Class LinkedMap

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.util.Map, IterableMap, OrderedMap

    @Deprecated(since="2021-04-30")
    public class LinkedMap
    extends AbstractLinkedMap
    implements java.io.Serializable, java.lang.Cloneable
    Deprecated.
    Commons Collections 3 is in maintenance mode. Commons Collections 4 should be used instead.
    A Map implementation that maintains the order of the entries. In this implementation order is maintained by original insertion.

    This implementation improves on the JDK1.4 LinkedHashMap by adding the MapIterator functionality, additional convenience methods and allowing bidirectional iteration. It also implements OrderedMap. In addition, non-interface methods are provided to access the map by index.

    The orderedMapIterator() method provides direct access to a bidirectional iterator. The iterators from the other views can also be cast to OrderedIterator if required.

    All the available iterators can be reset back to the start by casting to ResettableIterator and calling reset().

    The implementation is also designed to be subclassed, with lots of useful methods exposed.

    Note that LinkedMap is not synchronized and is not thread-safe. If you wish to use this map from multiple threads concurrently, you must use appropriate synchronization. The simplest approach is to wrap this map using Collections.synchronizedMap(Map). This class may throw exceptions when accessed by concurrent threads without synchronization.

    Since:
    Commons Collections 3.0
    See Also:
    Serialized Form
    • Nested Class Summary

      • 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>
    • Constructor Summary

      Constructors 
      Constructor Description
      LinkedMap()
      Deprecated.
      Constructs a new empty map with default size and load factor.
      LinkedMap​(int initialCapacity)
      Deprecated.
      Constructs a new, empty map with the specified initial capacity.
      LinkedMap​(int initialCapacity, float loadFactor)
      Deprecated.
      Constructs a new, empty map with the specified initial capacity and load factor.
      LinkedMap​(java.util.Map map)
      Deprecated.
      Constructor copying elements from another map.
    • Constructor Detail

      • LinkedMap

        public LinkedMap()
        Deprecated.
        Constructs a new empty map with default size and load factor.
      • LinkedMap

        public LinkedMap​(int initialCapacity)
        Deprecated.
        Constructs a new, empty map with the specified initial capacity.
        Parameters:
        initialCapacity - the initial capacity
        Throws:
        java.lang.IllegalArgumentException - if the initial capacity is less than one
      • LinkedMap

        public LinkedMap​(int initialCapacity,
                         float loadFactor)
        Deprecated.
        Constructs a new, empty map with the specified initial capacity and load factor.
        Parameters:
        initialCapacity - the initial capacity
        loadFactor - the load factor
        Throws:
        java.lang.IllegalArgumentException - if the initial capacity is less than one
        java.lang.IllegalArgumentException - if the load factor is less than zero
      • LinkedMap

        public LinkedMap​(java.util.Map map)
        Deprecated.
        Constructor copying elements from another map.
        Parameters:
        map - the map to copy
        Throws:
        java.lang.NullPointerException - if the map is null
    • Method Detail

      • clone

        public java.lang.Object clone()
        Deprecated.
        Clones the map without cloning the keys or values.
        Returns:
        a shallow clone
      • get

        public java.lang.Object get​(int index)
        Deprecated.
        Gets the key at the specified index.
        Parameters:
        index - the index to retrieve
        Returns:
        the key at the specified index
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is invalid
      • getValue

        public java.lang.Object getValue​(int index)
        Deprecated.
        Gets the value at the specified index.
        Parameters:
        index - the index to retrieve
        Returns:
        the key at the specified index
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is invalid
      • indexOf

        public int indexOf​(java.lang.Object key)
        Deprecated.
        Gets the index of the specified key.
        Parameters:
        key - the key to find the index of
        Returns:
        the index, or -1 if not found
      • remove

        public java.lang.Object remove​(int index)
        Deprecated.
        Removes the element at the specified index.
        Parameters:
        index - the index of the object to remove
        Returns:
        the previous value corresponding the key, or null if none existed
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is invalid
      • asList

        public java.util.List asList()
        Deprecated.
        Gets an unmodifiable List view of the keys.

        The returned list is unmodifiable because changes to the values of the list (using ListIterator.set(Object)) will effectively remove the value from the list and reinsert that value at the end of the list, which is an unexpected side effect of changing the value of a list. This occurs because changing the key, changes when the mapping is added to the map and thus where it appears in the list.

        An alternative to this method is to use AbstractHashedMap.keySet().

        Returns:
        The ordered list of keys.
        See Also:
        AbstractHashedMap.keySet()