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) $
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classDeprecated.Map.Entrythat doubles as a node in the linked list of sequenced mappings.private classDeprecated. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate HashMapDeprecated.Map of keys to entriesprivate static final intDeprecated.private static final intDeprecated.private longDeprecated.Holds the number of modifications that have occurred to the map, excluding modifications made through a collection view's iterator (e.g.private static final intDeprecated.private SequencedHashMap.EntryDeprecated.Sentinel used to hold the head and tail of the list of entries.private static final longDeprecated.private static final intDeprecated. -
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 TypeMethodDescriptionvoidclear()Deprecated.ImplementsMap.clear().clone()Deprecated.Creates a shallow copy of this object, preserving the internal structure by copying only references.booleancontainsKey(Object key) Deprecated.ImplementsMap.containsKey(Object).booleancontainsValue(Object value) Deprecated.ImplementsMap.containsValue(Object).private static final SequencedHashMap.EntryDeprecated.Construct an empty sentinel used to hold the head (sentinel.next) and the tail (sentinel.prev) of the list.entrySet()Deprecated.ImplementsMap.entrySet().booleanDeprecated.ImplementsMap.equals(Object).get(int index) Deprecated.Gets the key at the specified index.Deprecated.ImplementsMap.get(Object).private Map.EntrygetEntry(int index) Deprecated.Returns the Map.Entry at the specified indexgetFirst()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.inthashCode()Deprecated.ImplementsMap.hashCode().intDeprecated.Gets the index of the specified key.private voidDeprecated.Inserts a new internal entry to the tail of the linked list.booleanisEmpty()Deprecated.ImplementsMap.isEmpty().iterator()Deprecated.Gets an iterator over the keys.keySet()Deprecated.ImplementsMap.keySet().intlastIndexOf(Object key) Deprecated.Gets the last index of the specified key.Deprecated.ImplementsMap.put(Object, Object).voidDeprecated.Adds all the mappings in the specified map to this map, replacing any mappings that already exist (as perMap.putAll(Map)).voidDeprecated.Deserializes this map from the given stream.remove(int index) Deprecated.Removes the element at the specified index.Deprecated.ImplementsMap.remove(Object).private voidDeprecated.Removes an internal entry from the linked list.private SequencedHashMap.EntryremoveImpl(Object key) Deprecated.Fully remove an entry from the map, returning the old entry or null if there was no such entry with the specified key.sequence()Deprecated.Returns a List view of the keys rather than a set view.intsize()Deprecated.ImplementsMap.size().toString()Deprecated.Provides a string representation of the entries within the map.values()Deprecated.ImplementsMap.values().voidDeprecated.Serializes this map to the given stream.Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
sentinel
Deprecated.Sentinel used to hold the head and tail of the list of entries. -
entries
Deprecated.Map of keys to entries -
modCount
private transient long modCountDeprecated.Holds the number of modifications that have occurred to the map, excluding modifications made through a collection view's iterator (e.g. entrySet().iterator().remove()). This is used to create a fail-fast behavior with the iterators. -
KEY
private static final int KEYDeprecated.- See Also:
-
VALUE
private static final int VALUEDeprecated.- See Also:
-
ENTRY
private static final int ENTRYDeprecated.- See Also:
-
REMOVED_MASK
private static final int REMOVED_MASKDeprecated.- See Also:
-
serialVersionUID
private static final long serialVersionUIDDeprecated.- See Also:
-
-
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
-
createSentinel
Deprecated.Construct an empty sentinel used to hold the head (sentinel.next) and the tail (sentinel.prev) of the list. The sentinel has anullkey and value. -
removeEntry
Deprecated.Removes an internal entry from the linked list. This does not remove it from the underlying map. -
insertEntry
Deprecated.Inserts a new internal entry to the tail of the linked list. This does not add the entry to the underlying map. -
size
public int size()Deprecated.ImplementsMap.size(). -
isEmpty
public boolean isEmpty()Deprecated.ImplementsMap.isEmpty(). -
containsKey
Deprecated.ImplementsMap.containsKey(Object).- Specified by:
containsKeyin interfaceMap
-
containsValue
Deprecated.ImplementsMap.containsValue(Object).- Specified by:
containsValuein 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
nullif 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
nullif 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
nullif 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
nullif 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
nullif 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
nullif the map is empty.
-
put
Deprecated.ImplementsMap.put(Object, Object). -
remove
Deprecated.ImplementsMap.remove(Object). -
removeImpl
Deprecated.Fully remove an entry from the map, returning the old entry or null if there was no such entry with the specified key. -
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:
putAllin interfaceMap- Parameters:
t- the mappings that should be added to this map.- Throws:
NullPointerException- iftisnull
-
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:
clonein classObject- Returns:
- A clone of this instance.
- Throws:
CloneNotSupportedException- if clone is not supported by a subclass.
-
getEntry
Deprecated.Returns the Map.Entry at the specified index- Throws:
ArrayIndexOutOfBoundsException- if the specified index is< 0or>the size of the map.
-
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 theindexis< 0or>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 theindexis< 0or>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, ornullif none existed. - Throws:
ArrayIndexOutOfBoundsException- if theindexis< 0or>the size of the map.
-
readExternal
Deprecated.Deserializes this map from the given stream.- Specified by:
readExternalin 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:
writeExternalin interfaceExternalizable- Parameters:
out- the stream to serialize to- Throws:
IOException- if the stream raises it
-