Advertisement
Guest User

Untitled

a guest
Apr 17th, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.96 KB | None | 0 0
  1. /*
  2.  * JBoss, Home of Professional Open Source
  3.  * Copyright 2012, Red Hat, Inc., and individual contributors
  4.  * by the @authors tag. See the copyright.txt in the distribution for a
  5.  * full listing of individual contributors.
  6.  *
  7.  * This is free software; you can redistribute it and/or modify it
  8.  * under the terms of the GNU Lesser General Public License as
  9.  * published by the Free Software Foundation; either version 2.1 of
  10.  * the License, or (at your option) any later version.
  11.  *
  12.  * This software is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15.  * Lesser General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this software; if not, write to the Free
  19.  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20.  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21.  */
  22. package org.jboss.forge.resources;
  23.  
  24. import java.util.Collections;
  25. import java.util.List;
  26. import java.util.Map;
  27. import java.util.Map.Entry;
  28.  
  29. /**
  30.  * Represents a Key-value entry
  31.  *
  32.  * @author <a href="mailto:gegastaldi@gmail.com">George Gastaldi</a>
  33.  *
  34.  */
  35. public class EntryResource<K, V> extends VirtualResource<Entry<K, V>>
  36. {
  37.  
  38.    private Entry<K, V> entry;
  39.  
  40.    public EntryResource(final Resource<?> parent, K key, V value)
  41.    {
  42.       super(parent);
  43.       entry = new ConcreteEntry(key, value);
  44.    }
  45.  
  46.    public K getKey()
  47.    {
  48.       return entry.getKey();
  49.    }
  50.  
  51.    public V getValue()
  52.    {
  53.       return entry.getValue();
  54.    }
  55.  
  56.    @Override
  57.    public boolean delete() throws UnsupportedOperationException
  58.    {
  59.       throw new UnsupportedOperationException();
  60.    }
  61.  
  62.    @Override
  63.    public boolean delete(boolean recursive) throws UnsupportedOperationException
  64.    {
  65.       throw new UnsupportedOperationException();
  66.    }
  67.  
  68.    @Override
  69.    public String getName()
  70.    {
  71.       return getKey() + " = " + getValue();
  72.    }
  73.  
  74.    @Override
  75.    public Entry<K, V> getUnderlyingResourceObject()
  76.    {
  77.       return entry;
  78.    }
  79.  
  80.    @Override
  81.    protected List<Resource<?>> doListResources()
  82.    {
  83.       return Collections.emptyList();
  84.    }
  85.  
  86.    /**
  87.     * Implementation of {@link Entry} used in {@link EntryResource#getUnderlyingResourceObject()}
  88.     *
  89.     * @author george
  90.     *
  91.     */
  92.    private class ConcreteEntry implements Map.Entry<K, V>
  93.    {
  94.       private K key;
  95.       private V value;
  96.  
  97.       private ConcreteEntry(K key, V value)
  98.       {
  99.          super();
  100.          this.key = key;
  101.          this.value = value;
  102.       }
  103.  
  104.       @Override
  105.       public K getKey()
  106.       {
  107.          return key;
  108.       }
  109.  
  110.       @Override
  111.       public V getValue()
  112.       {
  113.          return value;
  114.       }
  115.  
  116.       @Override
  117.       public V setValue(V value)
  118.       {
  119.          this.value = value;
  120.          return getValue();
  121.       }
  122.  
  123.    }
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement