Package org.apache.commons.collections
Class SequencedHashMap
- java.lang.Object
 - 
- org.apache.commons.collections.SequencedHashMap
 
 
- 
- All Implemented Interfaces:
 java.io.Externalizable,java.io.Serializable,java.lang.Cloneable,java.util.Map
- Direct Known Subclasses:
 LRUMap
@Deprecated(since="2021-04-30") public class SequencedHashMap extends java.lang.Object implements java.util.Map, java.lang.Cloneable, java.io.ExternalizableDeprecated.Replaced by LinkedMap and ListOrderedMap in map subpackage. Due to be removed in v4.0.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
Listbecause of incompatible interface definitions. The remove methods in List and Map have different return values (see:List.remove(Object)andMap.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
 - See Also:
 LinkedMap,ListOrderedMap, Serialized Form
 
- 
- 
Constructor Summary
Constructors Constructor 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(java.util.Map m)Deprecated.Construct a new sequenced hash map and add all the elements in the specified map. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclear()Deprecated.ImplementsMap.clear().java.lang.Objectclone()Deprecated.Creates a shallow copy of this object, preserving the internal structure by copying only references.booleancontainsKey(java.lang.Object key)Deprecated.ImplementsMap.containsKey(Object).booleancontainsValue(java.lang.Object value)Deprecated.ImplementsMap.containsValue(Object).java.util.SetentrySet()Deprecated.ImplementsMap.entrySet().booleanequals(java.lang.Object obj)Deprecated.ImplementsMap.equals(Object).java.lang.Objectget(int index)Deprecated.Gets the key at the specified index.java.lang.Objectget(java.lang.Object o)Deprecated.ImplementsMap.get(Object).java.util.Map.EntrygetFirst()Deprecated.Return the entry for the "oldest" mapping.java.lang.ObjectgetFirstKey()Deprecated.Return the key for the "oldest" mapping.java.lang.ObjectgetFirstValue()Deprecated.Return the value for the "oldest" mapping.java.util.Map.EntrygetLast()Deprecated.Return the entry for the "newest" mapping.java.lang.ObjectgetLastKey()Deprecated.Return the key for the "newest" mapping.java.lang.ObjectgetLastValue()Deprecated.Return the value for the "newest" mapping.java.lang.ObjectgetValue(int index)Deprecated.Gets the value at the specified index.inthashCode()Deprecated.ImplementsMap.hashCode().intindexOf(java.lang.Object key)Deprecated.Gets the index of the specified key.booleanisEmpty()Deprecated.ImplementsMap.isEmpty().java.util.Iteratoriterator()Deprecated.Gets an iterator over the keys.java.util.SetkeySet()Deprecated.ImplementsMap.keySet().intlastIndexOf(java.lang.Object key)Deprecated.Gets the last index of the specified key.java.lang.Objectput(java.lang.Object key, java.lang.Object value)Deprecated.ImplementsMap.put(Object, Object).voidputAll(java.util.Map t)Deprecated.Adds all the mappings in the specified map to this map, replacing any mappings that already exist (as perMap.putAll(Map)).voidreadExternal(java.io.ObjectInput in)Deprecated.Deserializes this map from the given stream.java.lang.Objectremove(int index)Deprecated.Removes the element at the specified index.java.lang.Objectremove(java.lang.Object key)Deprecated.ImplementsMap.remove(Object).java.util.Listsequence()Deprecated.Returns a List view of the keys rather than a set view.intsize()Deprecated.ImplementsMap.size().java.lang.StringtoString()Deprecated.Provides a string representation of the entries within the map.java.util.Collectionvalues()Deprecated.ImplementsMap.values().voidwriteExternal(java.io.ObjectOutput out)Deprecated.Serializes this map to the given stream. 
 - 
 
- 
- 
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(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 tableloadFactor- the load factor for the hash table.- See Also:
 HashMap(int,float)
 
- 
SequencedHashMap
public SequencedHashMap(java.util.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 byputAll(Map). 
 - 
 
- 
Method Detail
- 
size
public int size()
Deprecated.ImplementsMap.size().- Specified by:
 sizein interfacejava.util.Map
 
- 
isEmpty
public boolean isEmpty()
Deprecated.ImplementsMap.isEmpty().- Specified by:
 isEmptyin interfacejava.util.Map
 
- 
containsKey
public boolean containsKey(java.lang.Object key)
Deprecated.ImplementsMap.containsKey(Object).- Specified by:
 containsKeyin interfacejava.util.Map
 
- 
containsValue
public boolean containsValue(java.lang.Object value)
Deprecated.ImplementsMap.containsValue(Object).- Specified by:
 containsValuein interfacejava.util.Map
 
- 
get
public java.lang.Object get(java.lang.Object o)
Deprecated.ImplementsMap.get(Object).- Specified by:
 getin interfacejava.util.Map
 
- 
getFirst
public java.util.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 usingentrySet().iterator().next(), but this method provides an optimized implementation.- Returns:
 - The first entry in the sequence, or 
nullif the map is empty. 
 
- 
getFirstKey
public java.lang.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 usinggetFirst().getKey(), but this method provides a slightly optimized implementation.- Returns:
 - The first key in the sequence, or 
nullif the map is empty. 
 
- 
getFirstValue
public java.lang.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 usinggetFirst().getValue(), but this method provides a slightly optimized implementation.- Returns:
 - The first value in the sequence, or 
nullif the map is empty. 
 
- 
getLast
public java.util.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 
nullif the map is empty. 
 
- 
getLastKey
public java.lang.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 usinggetLast().getKey(), but this method provides a slightly optimized implementation.- Returns:
 - The last key in the sequence, or 
nullif the map is empty. 
 
- 
getLastValue
public java.lang.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 usinggetLast().getValue(), but this method provides a slightly optimized implementation.- Returns:
 - The last value in the sequence, or 
nullif the map is empty. 
 
- 
put
public java.lang.Object put(java.lang.Object key, java.lang.Object value)Deprecated.ImplementsMap.put(Object, Object).- Specified by:
 putin interfacejava.util.Map
 
- 
remove
public java.lang.Object remove(java.lang.Object key)
Deprecated.ImplementsMap.remove(Object).- Specified by:
 removein interfacejava.util.Map
 
- 
putAll
public void putAll(java.util.Map t)
Deprecated.Adds all the mappings in the specified map to this map, replacing any mappings that already exist (as perMap.putAll(Map)). The order in which the entries are added is determined by the iterator returned fromMap.entrySet()for the specified map.- Specified by:
 putAllin interfacejava.util.Map- Parameters:
 t- the mappings that should be added to this map.- Throws:
 java.lang.NullPointerException- iftisnull
 
- 
clear
public void clear()
Deprecated.ImplementsMap.clear().- Specified by:
 clearin interfacejava.util.Map
 
- 
equals
public boolean equals(java.lang.Object obj)
Deprecated.ImplementsMap.equals(Object).- Specified by:
 equalsin interfacejava.util.Map- Overrides:
 equalsin classjava.lang.Object
 
- 
hashCode
public int hashCode()
Deprecated.ImplementsMap.hashCode().- Specified by:
 hashCodein interfacejava.util.Map- Overrides:
 hashCodein classjava.lang.Object
 
- 
toString
public java.lang.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, useentrySet().iterator()and iterate over the entries in the map formatting them as appropriate.- Overrides:
 toStringin classjava.lang.Object
 
- 
keySet
public java.util.Set keySet()
Deprecated.ImplementsMap.keySet().- Specified by:
 keySetin interfacejava.util.Map
 
- 
values
public java.util.Collection values()
Deprecated.ImplementsMap.values().- Specified by:
 valuesin interfacejava.util.Map
 
- 
entrySet
public java.util.Set entrySet()
Deprecated.ImplementsMap.entrySet().- Specified by:
 entrySetin interfacejava.util.Map
 
- 
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedExceptionDeprecated.Creates a shallow copy of this object, preserving the internal structure by copying only references. The keys and values themselves are notclone()'d. The cloned object maintains the same sequence.- Returns:
 - A clone of this instance.
 - Throws:
 java.lang.CloneNotSupportedException- if clone is not supported by a subclass.
 
- 
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, or null
 - Throws:
 java.lang.ArrayIndexOutOfBoundsException- if theindexis< 0or>the size of the map.
 
- 
getValue
public java.lang.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:
 java.lang.ArrayIndexOutOfBoundsException- if theindexis< 0or>the size of the map.
 
- 
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
 
 
- 
iterator
public java.util.Iterator iterator()
Deprecated.Gets an iterator over the keys.- Returns:
 - an iterator over the keys
 
 
- 
lastIndexOf
public int lastIndexOf(java.lang.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 java.util.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 (usingListIterator.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 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, ornullif none existed. - Throws:
 java.lang.ArrayIndexOutOfBoundsException- if theindexis< 0or>the size of the map.
 
- 
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionDeprecated.Deserializes this map from the given stream.- Specified by:
 readExternalin interfacejava.io.Externalizable- Parameters:
 in- the stream to deserialize from- Throws:
 java.io.IOException- if the stream raises itjava.lang.ClassNotFoundException- if the stream raises it
 
- 
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOExceptionDeprecated.Serializes this map to the given stream.- Specified by:
 writeExternalin interfacejava.io.Externalizable- Parameters:
 out- the stream to serialize to- Throws:
 java.io.IOException- if the stream raises it
 
 - 
 
 -