Class AbstractDecoratedMap<K,V>

java.lang.Object
java.util.AbstractMap<K,V>
com.twelvemonkeys.util.AbstractDecoratedMap<K,V>
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>
Direct Known Subclasses:
IgnoreCaseMap, LinkedMap, TimeoutMap

abstract class AbstractDecoratedMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Serializable, Cloneable
AbstractDecoratedMap
Version:
$Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/util/AbstractDecoratedMap.java#2 $
  • Field Details

    • entries

      protected Map<K,Map.Entry<K,V>> entries
    • modCount

      protected transient volatile int modCount
    • entrySet

      private transient volatile Set<Map.Entry<K,V>> entrySet
    • keySet

      private transient volatile Set<K> keySet
    • values

      private transient volatile Collection<V> values
  • Constructor Details

    • AbstractDecoratedMap

      public AbstractDecoratedMap()
      Creates a Map backed by a HashMap.
    • AbstractDecoratedMap

      public AbstractDecoratedMap(Map<? extends K,? extends V> pContents)
      Creates a Map backed by a HashMap, containing all key/value mappings from the given Map.

      This is constructor is here to comply with the reccomendations for "standard" constructors in the Map interface.

      Parameters:
      pContents - the map whose mappings are to be placed in this map. May be null.
      See Also:
    • AbstractDecoratedMap

      public AbstractDecoratedMap(Map<K,Map.Entry<K,V>> pBacking, Map<? extends K,? extends V> pContents)
      Creates a Map backed by the given backing-Map, containing all key/value mappings from the given contents-Map.

      NOTE: The backing map is structuraly cahnged, and it should NOT be accessed directly, after the wrapped map is created.

      Parameters:
      pBacking - the backing map of this map. Must be either empty, or the same map as pContents.
      pContents - the map whose mappings are to be placed in this map. May be null.
      Throws:
      IllegalArgumentException - if pBacking is null or if pBacking differs from pContent and is not empty.
  • Method Details

    • init

      protected void init()
      Default implementation, does nothing.
    • size

      public int size()
      Specified by:
      size in interface Map<K,V>
      Overrides:
      size in class AbstractMap<K,V>
    • clear

      public void clear()
      Specified by:
      clear in interface Map<K,V>
      Overrides:
      clear in class AbstractMap<K,V>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Map<K,V>
      Overrides:
      isEmpty in class AbstractMap<K,V>
    • containsKey

      public boolean containsKey(Object pKey)
      Specified by:
      containsKey in interface Map<K,V>
      Overrides:
      containsKey in class AbstractMap<K,V>
    • containsValue

      public boolean containsValue(Object pValue)
      Returns true if this map maps one or more keys to the specified pValue. More formally, returns true if and only if this map contains at least one mapping to a pValue v such that (pValue==null ? v==null : pValue.equals(v)).

      This implementation requires time linear in the map size for this operation.

      Specified by:
      containsValue in interface Map<K,V>
      Overrides:
      containsValue in class AbstractMap<K,V>
      Parameters:
      pValue - pValue whose presence in this map is to be tested.
      Returns:
      true if this map maps one or more keys to the specified pValue.
    • values

      public Collection<V> values()
      Specified by:
      values in interface Map<K,V>
      Overrides:
      values in class AbstractMap<K,V>
    • entrySet

      public Set<Map.Entry<K,V>> entrySet()
      Specified by:
      entrySet in interface Map<K,V>
      Specified by:
      entrySet in class AbstractMap<K,V>
    • keySet

      public Set<K> keySet()
      Specified by:
      keySet in interface Map<K,V>
      Overrides:
      keySet in class AbstractMap<K,V>
    • clone

      protected Object clone() throws CloneNotSupportedException
      Returns a shallow copy of this AbstractMap instance: the keys and values themselves are not cloned.
      Overrides:
      clone in class AbstractMap<K,V>
      Returns:
      a shallow copy of this map.
      Throws:
      CloneNotSupportedException
    • newKeyIterator

      protected abstract Iterator<K> newKeyIterator()
    • newValueIterator

      protected abstract Iterator<V> newValueIterator()
    • newEntryIterator

      protected abstract Iterator<Map.Entry<K,V>> newEntryIterator()
    • get

      public abstract V get(Object pKey)
      Specified by:
      get in interface Map<K,V>
      Overrides:
      get in class AbstractMap<K,V>
    • remove

      public abstract V remove(Object pKey)
      Specified by:
      remove in interface Map<K,V>
      Overrides:
      remove in class AbstractMap<K,V>
    • put

      public abstract V put(K pKey, V pValue)
      Specified by:
      put in interface Map<K,V>
      Overrides:
      put in class AbstractMap<K,V>
    • createEntry

      Map.Entry<K,V> createEntry(K pKey, V pValue)
    • getEntry

      Map.Entry<K,V> getEntry(K pKey)
    • removeEntry

      protected Map.Entry<K,V> removeEntry(Map.Entry<K,V> pEntry)
      Removes the given entry from the Map.
      Parameters:
      pEntry - the entry to be removed
      Returns:
      the removed entry, or null if nothing was removed.