Class AbstractDecoratedMap<K,​V>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map<K,​V>
    Direct Known Subclasses:
    IgnoreCaseMap, LinkedMap, TimeoutMap

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

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  AbstractDecoratedMap.BasicEntry<K,​V>
      A simple Map.Entry implementation.
      protected class  AbstractDecoratedMap.EntrySet  
      protected class  AbstractDecoratedMap.KeySet  
      protected class  AbstractDecoratedMap.Values  
      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Map<K,​java.util.Map.Entry<K,​V>> entries  
      private java.util.Set<java.util.Map.Entry<K,​V>> entrySet  
      private java.util.Set<K> keySet  
      protected int modCount  
      private java.util.Collection<V> values  
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractDecoratedMap()
      Creates a Map backed by a HashMap.
      AbstractDecoratedMap​(java.util.Map<? extends K,​? extends V> pContents)
      Creates a Map backed by a HashMap, containing all key/value mappings from the given Map.
      AbstractDecoratedMap​(java.util.Map<K,​java.util.Map.Entry<K,​V>> pBacking, java.util.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.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()  
      protected java.lang.Object clone()
      Returns a shallow copy of this AbstractMap instance: the keys and values themselves are not cloned.
      boolean containsKey​(java.lang.Object pKey)  
      boolean containsValue​(java.lang.Object pValue)
      Returns true if this map maps one or more keys to the specified pValue.
      (package private) java.util.Map.Entry<K,​V> createEntry​(K pKey, V pValue)  
      java.util.Set<java.util.Map.Entry<K,​V>> entrySet()  
      abstract V get​(java.lang.Object pKey)  
      (package private) java.util.Map.Entry<K,​V> getEntry​(K pKey)  
      protected void init()
      Default implementation, does nothing.
      boolean isEmpty()  
      java.util.Set<K> keySet()  
      protected abstract java.util.Iterator<java.util.Map.Entry<K,​V>> newEntryIterator()  
      protected abstract java.util.Iterator<K> newKeyIterator()  
      protected abstract java.util.Iterator<V> newValueIterator()  
      abstract V put​(K pKey, V pValue)  
      abstract V remove​(java.lang.Object pKey)  
      protected java.util.Map.Entry<K,​V> removeEntry​(java.util.Map.Entry<K,​V> pEntry)
      Removes the given entry from the Map.
      int size()  
      java.util.Collection<V> values()  
      • Methods inherited from class java.util.AbstractMap

        equals, hashCode, putAll, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll
    • Field Detail

      • entries

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

        protected transient volatile int modCount
      • entrySet

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

        private transient volatile java.util.Set<K> keySet
      • values

        private transient volatile java.util.Collection<V> values
    • Constructor Detail

      • AbstractDecoratedMap

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

        public AbstractDecoratedMap​(java.util.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(java.util.Map, java.util.Map)
      • AbstractDecoratedMap

        public AbstractDecoratedMap​(java.util.Map<K,​java.util.Map.Entry<K,​V>> pBacking,
                                    java.util.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:
        java.lang.IllegalArgumentException - if pBacking is null or if pBacking differs from pContent and is not empty.
    • Method Detail

      • init

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

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

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

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

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

        public boolean containsValue​(java.lang.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 java.util.Map<K,​V>
        Overrides:
        containsValue in class java.util.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 java.util.Collection<V> values()
        Specified by:
        values in interface java.util.Map<K,​V>
        Overrides:
        values in class java.util.AbstractMap<K,​V>
      • entrySet

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

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

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

        protected abstract java.util.Iterator<K> newKeyIterator()
      • newValueIterator

        protected abstract java.util.Iterator<V> newValueIterator()
      • newEntryIterator

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

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

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

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

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

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

        protected java.util.Map.Entry<K,​V> removeEntry​(java.util.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.