Package 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.
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:
-
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.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.Deprecated.Construct a new sequenced hash map and add all the elements in the specified map. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Deprecated.ImplementsMap.clear()
.clone()
Deprecated.Creates a shallow copy of this object, preserving the internal structure by copying only references.boolean
containsKey
(Object key) Deprecated.ImplementsMap.containsKey(Object)
.boolean
containsValue
(Object value) Deprecated.ImplementsMap.containsValue(Object)
.entrySet()
Deprecated.ImplementsMap.entrySet()
.boolean
Deprecated.ImplementsMap.equals(Object)
.get
(int index) Deprecated.Gets the key at the specified index.Deprecated.ImplementsMap.get(Object)
.getFirst()
Deprecated.Return the entry for the "oldest" mapping.Deprecated.Return the key for the "oldest" mapping.Deprecated.Return the value for the "oldest" mapping.getLast()
Deprecated.Return the entry for the "newest" mapping.Deprecated.Return the key for the "newest" mapping.Deprecated.Return the value for the "newest" mapping.getValue
(int index) Deprecated.Gets the value at the specified index.int
hashCode()
Deprecated.ImplementsMap.hashCode()
.int
Deprecated.Gets the index of the specified key.boolean
isEmpty()
Deprecated.ImplementsMap.isEmpty()
.iterator()
Deprecated.Gets an iterator over the keys.keySet()
Deprecated.ImplementsMap.keySet()
.int
lastIndexOf
(Object key) Deprecated.Gets the last index of the specified key.Deprecated.ImplementsMap.put(Object, Object)
.void
Deprecated.Adds all the mappings in the specified map to this map, replacing any mappings that already exist (as perMap.putAll(Map)
).void
Deprecated.Deserializes this map from the given stream.remove
(int index) Deprecated.Removes the element at the specified index.Deprecated.ImplementsMap.remove(Object)
.sequence()
Deprecated.Returns a List view of the keys rather than a set view.int
size()
Deprecated.ImplementsMap.size()
.toString()
Deprecated.Provides a string representation of the entries within the map.values()
Deprecated.ImplementsMap.values()
.void
Deprecated.Serializes this map to the given stream.Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
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:
-
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:
-
SequencedHashMap
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 Details
-
size
public int size()Deprecated.ImplementsMap.size()
. -
isEmpty
public boolean isEmpty()Deprecated.ImplementsMap.isEmpty()
. -
containsKey
Deprecated.ImplementsMap.containsKey(Object)
.- Specified by:
containsKey
in interfaceMap
-
containsValue
Deprecated.ImplementsMap.containsValue(Object)
.- Specified by:
containsValue
in interfaceMap
-
get
Deprecated.ImplementsMap.get(Object)
. -
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
null
if the map is empty.
-
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
null
if the map is empty.
-
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
null
if the map is empty.
-
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
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
null
if the map is empty.
-
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
null
if the map is empty.
-
put
Deprecated.ImplementsMap.put(Object, Object)
. -
remove
Deprecated.ImplementsMap.remove(Object)
. -
putAll
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:
putAll
in interfaceMap
- Parameters:
t
- the mappings that should be added to this map.- Throws:
NullPointerException
- ift
isnull
-
clear
public void clear()Deprecated.ImplementsMap.clear()
. -
equals
Deprecated.ImplementsMap.equals(Object)
. -
hashCode
public int hashCode()Deprecated.ImplementsMap.hashCode()
. -
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. -
keySet
Deprecated.ImplementsMap.keySet()
. -
values
Deprecated.ImplementsMap.values()
. -
entrySet
Deprecated.ImplementsMap.entrySet()
. -
clone
Deprecated.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.- Overrides:
clone
in classObject
- Returns:
- A clone of this instance.
- Throws:
CloneNotSupportedException
- if clone is not supported by a subclass.
-
get
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 theindex
is< 0
or>
the size of the map.
-
getValue
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 theindex
is< 0
or>
the size of the map.
-
indexOf
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
Deprecated.Gets an iterator over the keys.- Returns:
- an iterator over the keys
-
lastIndexOf
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
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:
-
remove
Deprecated.Removes the element at the specified index.- Parameters:
index
- The index of the object to remove.- Returns:
- The previous value corresponding the
key
, ornull
if none existed. - Throws:
ArrayIndexOutOfBoundsException
- if theindex
is< 0
or>
the size of the map.
-
readExternal
Deprecated.Deserializes this map from the given stream.- Specified by:
readExternal
in interfaceExternalizable
- Parameters:
in
- the stream to deserialize from- Throws:
IOException
- if the stream raises itClassNotFoundException
- if the stream raises it
-
writeExternal
Deprecated.Serializes this map to the given stream.- Specified by:
writeExternal
in interfaceExternalizable
- Parameters:
out
- the stream to serialize to- Throws:
IOException
- if the stream raises it
-