Class IdentityMap<E>

  • Type Parameters:
    E - The element type
    All Implemented Interfaces:
    java.util.Map<E,​E>

    public final class IdentityMap<E>
    extends java.lang.Object
    implements java.util.Map<E,​E>
    This is a dumb implementation of a Map. It acts as if every object in the VM is mapped onto itself.
    Author:
    Matthew Wakeling
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Map

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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      boolean containsKey​(java.lang.Object key)
      boolean containsValue​(java.lang.Object value)
      java.util.Set<java.util.Map.Entry<E,​E>> entrySet()
      boolean equals​(java.lang.Object o)
      E get​(java.lang.Object key)
      static <T> IdentityMap<T> getInstance()
      Obtain an instance of this class
      int hashCode()
      boolean isEmpty()
      java.util.Set<E> keySet()
      E put​(E key, E value)
      void putAll​(java.util.Map<? extends E,​? extends E> map)
      E remove​(java.lang.Object key)
      int size()
      java.util.Collection<E> values()
      • Methods inherited from class java.lang.Object

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

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Method Detail

      • getInstance

        public static <T> IdentityMap<T> getInstance()
        Obtain an instance of this class
        Type Parameters:
        T - The type of the map
        Returns:
        a singleton
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<E,​E>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<E,​E>
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<E,​E>
      • entrySet

        public java.util.Set<java.util.Map.Entry<E,​E>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<E,​E>
      • equals

        public boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface java.util.Map<E,​E>
        Overrides:
        equals in class java.lang.Object
      • get

        public E get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<E,​E>
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map<E,​E>
        Overrides:
        hashCode in class java.lang.Object
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<E,​E>
      • keySet

        public java.util.Set<E> keySet()
        Specified by:
        keySet in interface java.util.Map<E,​E>
      • put

        public E put​(E key,
                     E value)
        Specified by:
        put in interface java.util.Map<E,​E>
      • putAll

        public void putAll​(java.util.Map<? extends E,​? extends E> map)
        Specified by:
        putAll in interface java.util.Map<E,​E>
      • remove

        public E remove​(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<E,​E>
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<E,​E>
      • values

        public java.util.Collection<E> values()
        Specified by:
        values in interface java.util.Map<E,​E>