org.apache.commons.collections

## Class SequencedHashMap

- java.lang.Object
- - org.apache.commons.collections.SequencedHashMap

- All Implemented Interfaces:
    Externalizable, Serializable, Cloneable, Map
  Direct Known Subclasses:
    LRUMap

  Deprecated.
  Replaced by LinkedMap and ListOrderedMap in map subpackage. Due to be removed in v4.0.

      public class SequencedHashMap
      extends Object
      implements Map, Cloneable, Externalizable

  A map of objects whose mapping entries are sequenced based on the order in which they were added. This data structure has fast O(1) search time, deletion time, and insertion time.

  Although this map is sequenced, it cannot implement `List` because of incompatible interface definitions. The remove methods in List and Map have different return values (see: `List.remove(Object)` and `Map.remove(Object)`).

  This class is not thread safe. When a thread safe implementation is required, use `Collections.synchronizedMap(Map)` as it is documented, or use explicit synchronization controls.

  Since:
    Commons Collections 2.0
  Version:
    $Revision: 646777 $ $Date: 2008-04-10 14:33:15 +0200 (Thu, 10 Apr 2008) $
  Author:
    Michael A. Smith, Daniel Rall, Henning P. Schmiedehausen, Stephen Colebourne
  See Also:
    `LinkedMap`, `ListOrderedMap`, Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SequencedHashMap()` Deprecated. Construct a new sequenced hash map with default initial size and load factor.
    `SequencedHashMap(int initialSize)` Deprecated. Construct a new sequenced hash map with the specified initial size and default load factor.
    `SequencedHashMap(int initialSize, float loadFactor)` Deprecated. Construct a new sequenced hash map with the specified initial size and load factor.
    `SequencedHashMap(Map m)` Deprecated. Construct a new sequenced hash map and add all the elements in the specified map.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()` Deprecated. Implements `Map.clear()`.
    `Object` | `clone()` Deprecated. Creates a shallow copy of this object, preserving the internal structure by copying only references.
    `boolean` | `containsKey(Object key)` Deprecated. Implements `Map.containsKey(Object)`.
    `boolean` | `containsValue(Object value)` Deprecated. Implements `Map.containsValue(Object)`.
    `Set` | `entrySet()` Deprecated. Implements `Map.entrySet()`.
    `boolean` | `equals(Object obj)` Deprecated. Implements `Map.equals(Object)`.
    `Object` | `get(int index)` Deprecated. Gets the key at the specified index.
    `Object` | `get(Object o)` Deprecated. Implements `Map.get(Object)`.
    `Map.Entry` | `getFirst()` Deprecated. Return the entry for the "oldest" mapping.
    `Object` | `getFirstKey()` Deprecated. Return the key for the "oldest" mapping.
    `Object` | `getFirstValue()` Deprecated. Return the value for the "oldest" mapping.
    `Map.Entry` | `getLast()` Deprecated. Return the entry for the "newest" mapping.
    `Object` | `getLastKey()` Deprecated. Return the key for the "newest" mapping.
    `Object` | `getLastValue()` Deprecated. Return the value for the "newest" mapping.
    `Object` | `getValue(int index)` Deprecated. Gets the value at the specified index.
    `int` | `hashCode()` Deprecated. Implements `Map.hashCode()`.
    `int` | `indexOf(Object key)` Deprecated. Gets the index of the specified key.
    `boolean` | `isEmpty()` Deprecated. Implements `Map.isEmpty()`.
    `Iterator` | `iterator()` Deprecated. Gets an iterator over the keys.
    `Set` | `keySet()` Deprecated. Implements `Map.keySet()`.
    `int` | `lastIndexOf(Object key)` Deprecated. Gets the last index of the specified key.
    `Object` | `put(Object key, Object value)` Deprecated. Implements `Map.put(Object, Object)`.
    `void` | `putAll(Map t)` Deprecated. Adds all the mappings in the specified map to this map, replacing any mappings that already exist (as per `Map.putAll(Map)`).
    `void` | `readExternal(ObjectInput in)` Deprecated. Deserializes this map from the given stream.
    `Object` | `remove(int index)` Deprecated. Removes the element at the specified index.
    `Object` | `remove(Object key)` Deprecated. Implements `Map.remove(Object)`.
    `List` | `sequence()` Deprecated. Returns a List view of the keys rather than a set view.
    `int` | `size()` Deprecated. Implements `Map.size()`.
    `String` | `toString()` Deprecated. Provides a string representation of the entries within the map.
    `Collection` | `values()` Deprecated. Implements `Map.values()`.
    `void` | `writeExternal(ObjectOutput out)` Deprecated. Serializes this map to the given stream.

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### SequencedHashMap

          public SequencedHashMap()

      Deprecated.
      Construct a new sequenced hash map with default initial size and load factor.

    - #### SequencedHashMap

          public SequencedHashMap(int initialSize)

      Deprecated.
      Construct a new sequenced hash map with the specified initial size and default load factor.
      Parameters:
        `initialSize` - the initial size for the hash table
      See Also:
        `HashMap.HashMap(int)`

    - #### SequencedHashMap

          public SequencedHashMap(int initialSize,
                          float loadFactor)

      Deprecated.
      Construct a new sequenced hash map with the specified initial size and load factor.
      Parameters:
        `initialSize` - the initial size for the hash table
        `loadFactor` - the load factor for the hash table.
      See Also:
        `HashMap.HashMap(int,float)`

    - #### SequencedHashMap

          public SequencedHashMap(Map m)

      Deprecated.
      Construct a new sequenced hash map and add all the elements in the specified map. The order in which the mappings in the specified map are added is defined by `putAll(Map)`.

  - ### Method Detail

    - #### size

          public int size()

      Deprecated.
      Implements `Map.size()`.
      Specified by:
        `size` in interface `Map`

    - #### isEmpty

          public boolean isEmpty()

      Deprecated.
      Implements `Map.isEmpty()`.
      Specified by:
        `isEmpty` in interface `Map`

    - #### containsKey

          public boolean containsKey(Object key)

      Deprecated.
      Implements `Map.containsKey(Object)`.
      Specified by:
        `containsKey` in interface `Map`

    - #### containsValue

          public boolean containsValue(Object value)

      Deprecated.
      Implements `Map.containsValue(Object)`.
      Specified by:
        `containsValue` in interface `Map`

    - #### get

          public Object get(Object o)

      Deprecated.
      Implements `Map.get(Object)`.
      Specified by:
        `get` in interface `Map`

    - #### getFirst

          public Map.Entry getFirst()

      Deprecated.
      Return the entry for the "oldest" mapping. That is, return the Map.Entry for the key-value pair that was first put into the map when compared to all the other pairings in the map. This behavior is equivalent to using `entrySet().iterator().next()`, but this method provides an optimized implementation.
      Returns:
        The first entry in the sequence, or `null` if the map is empty.

    - #### getFirstKey

          public Object getFirstKey()

      Deprecated.
      Return the key for the "oldest" mapping. That is, return the key for the mapping that was first put into the map when compared to all the other objects in the map. This behavior is equivalent to using `getFirst().getKey()`, but this method provides a slightly optimized implementation.
      Returns:
        The first key in the sequence, or `null` if the map is empty.

    - #### getFirstValue

          public Object getFirstValue()

      Deprecated.
      Return the value for the "oldest" mapping. That is, return the value for the mapping that was first put into the map when compared to all the other objects in the map. This behavior is equivalent to using `getFirst().getValue()`, but this method provides a slightly optimized implementation.
      Returns:
        The first value in the sequence, or `null` if the map is empty.

    - #### getLast

          public Map.Entry getLast()

      Deprecated.
      Return the entry for the "newest" mapping. That is, return the Map.Entry for the key-value pair that was first put into the map when compared to all the other pairings in the map. The behavior is equivalent to:

              Object obj = null;
              Iterator iter = entrySet().iterator();
              while(iter.hasNext()) {
                obj = iter.next();
              }
              return (Map.Entry)obj;

      However, the implementation of this method ensures an O(1) lookup of the last key rather than O(n).
      Returns:
        The last entry in the sequence, or `null` if the map is empty.

    - #### getLastKey

          public Object getLastKey()

      Deprecated.
      Return the key for the "newest" mapping. That is, return the key for the mapping that was last put into the map when compared to all the other objects in the map. This behavior is equivalent to using `getLast().getKey()`, but this method provides a slightly optimized implementation.
      Returns:
        The last key in the sequence, or `null` if the map is empty.

    - #### getLastValue

          public Object getLastValue()

      Deprecated.
      Return the value for the "newest" mapping. That is, return the value for the mapping that was last put into the map when compared to all the other objects in the map. This behavior is equivalent to using `getLast().getValue()`, but this method provides a slightly optimized implementation.
      Returns:
        The last value in the sequence, or `null` if the map is empty.

    - #### put

          public Object put(Object key,
                   Object value)

      Deprecated.
      Implements `Map.put(Object, Object)`.
      Specified by:
        `put` in interface `Map`

    - #### remove

          public Object remove(Object key)

      Deprecated.
      Implements `Map.remove(Object)`.
      Specified by:
        `remove` in interface `Map`

    - #### putAll

          public void putAll(Map t)

      Deprecated.
      Adds all the mappings in the specified map to this map, replacing any mappings that already exist (as per `Map.putAll(Map)`). The order in which the entries are added is determined by the iterator returned from `Map.entrySet()` for the specified map.
      Specified by:
        `putAll` in interface `Map`
      Parameters:
        `t` - the mappings that should be added to this map.
      Throws:
        `NullPointerException` - if `t` is `null`

    - #### clear

          public void clear()

      Deprecated.
      Implements `Map.clear()`.
      Specified by:
        `clear` in interface `Map`

    - #### equals

          public boolean equals(Object obj)

      Deprecated.
      Implements `Map.equals(Object)`.
      Specified by:
        `equals` in interface `Map`
      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Deprecated.
      Implements `Map.hashCode()`.
      Specified by:
        `hashCode` in interface `Map`
      Overrides:
        `hashCode` in class `Object`

    - #### toString

          public String toString()

      Deprecated.
      Provides a string representation of the entries within the map. The format of the returned string may change with different releases, so this method is suitable for debugging purposes only. If a specific format is required, use `entrySet()`.`iterator()` and iterate over the entries in the map formatting them as appropriate.
      Overrides:
        `toString` in class `Object`

    - #### keySet

          public Set keySet()

      Deprecated.
      Implements `Map.keySet()`.
      Specified by:
        `keySet` in interface `Map`

    - #### values

          public Collection values()

      Deprecated.
      Implements `Map.values()`.
      Specified by:
        `values` in interface `Map`

    - #### entrySet

          public Set entrySet()

      Deprecated.
      Implements `Map.entrySet()`.
      Specified by:
        `entrySet` in interface `Map`

    - #### clone

          public Object clone()
                       throws CloneNotSupportedException

      Deprecated.
      Creates a shallow copy of this object, preserving the internal structure by copying only references. The keys and values themselves are not `clone()`'d. The cloned object maintains the same sequence.
      Overrides:
        `clone` in class `Object`
      Returns:
        A clone of this instance.
      Throws:
        `CloneNotSupportedException` - if clone is not supported by a subclass.

    - #### get

          public 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, or null
      Throws:
        `ArrayIndexOutOfBoundsException` - if the `index` is `< 0` or `>` the size of the map.

    - #### getValue

          public Object getValue(int index)

      Deprecated.
      Gets the value at the specified index.
      Parameters:
        `index` - the index to retrieve
      Returns:
        the value at the specified index, or null
      Throws:
        `ArrayIndexOutOfBoundsException` - if the `index` is `< 0` or `>` the size of the map.

    - #### indexOf

          public int indexOf(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

    - #### iterator

          public Iterator iterator()

      Deprecated.
      Gets an iterator over the keys.
      Returns:
        an iterator over the keys

    - #### lastIndexOf

          public int lastIndexOf(Object key)

      Deprecated.
      Gets the last index of the specified key.
      Parameters:
        `key` - the key to find the index of
      Returns:
        the index, or -1 if not found

    - #### sequence

          public List sequence()

      Deprecated.
      Returns a List view of the keys rather than a set view. The returned list is unmodifiable. This is required 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 `keySet()`

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

    - #### remove

          public 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:
        `ArrayIndexOutOfBoundsException` - if the `index` is `< 0` or `>` the size of the map.

    - #### readExternal

          public void readExternal(ObjectInput in)
                            throws IOException,
                                   ClassNotFoundException

      Deprecated.
      Deserializes this map from the given stream.
      Specified by:
        `readExternal` in interface `Externalizable`
      Parameters:
        `in` - the stream to deserialize from
      Throws:
        `IOException` - if the stream raises it
        `ClassNotFoundException` - if the stream raises it

    - #### writeExternal

          public void writeExternal(ObjectOutput out)
                             throws IOException

      Deprecated.
      Serializes this map to the given stream.
      Specified by:
        `writeExternal` in interface `Externalizable`
      Parameters:
        `out` - the stream to serialize to
      Throws:
        `IOException` - if the stream raises it

Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.