java.lang.Object | |
↳ | org.apache.commons.collections.SequencedHashMap |
Known Direct Subclasses |
This class is 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
java.util.List because of incompatible interface definitions.
The remove methods in List and Map have different return values
(see: remove(Object)
and remove(Object)
).
This class is not thread safe. When a thread safe implementation is
required, use synchronizedMap(Map)
as it is documented,
or use explicit synchronization controls.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Construct a new sequenced hash map with default initial size and load
factor.
| |||||||||||
Construct a new sequenced hash map with the specified initial size and
default load factor.
| |||||||||||
Construct a new sequenced hash map with the specified initial size and
load factor.
| |||||||||||
Construct a new sequenced hash map and add all the elements in the
specified map.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Implements
clear() . | |||||||||||
Creates a shallow copy of this object, preserving the internal structure
by copying only references.
| |||||||||||
Implements
containsKey(Object) . | |||||||||||
Implements
containsValue(Object) . | |||||||||||
Implements
entrySet() . | |||||||||||
Implements
equals(Object) . | |||||||||||
Gets the key at the specified index.
| |||||||||||
Implements
get(Object) . | |||||||||||
Return the entry for the "oldest" mapping.
| |||||||||||
Return the key for the "oldest" mapping.
| |||||||||||
Return the value for the "oldest" mapping.
| |||||||||||
Return the entry for the "newest" mapping.
| |||||||||||
Return the key for the "newest" mapping.
| |||||||||||
Return the value for the "newest" mapping.
| |||||||||||
Gets the value at the specified index.
| |||||||||||
Implements
hashCode() . | |||||||||||
Gets the index of the specified key.
| |||||||||||
Implements
isEmpty() . | |||||||||||
Gets an iterator over the keys.
| |||||||||||
Implements
keySet() . | |||||||||||
Gets the last index of the specified key.
| |||||||||||
Implements
put(Object, Object) . | |||||||||||
Adds all the mappings in the specified map to this map, replacing any
mappings that already exist (as per
putAll(Map) ). | |||||||||||
Deserializes this map from the given stream.
| |||||||||||
Removes the element at the specified index.
| |||||||||||
Implements
remove(Object) . | |||||||||||
Returns a List view of the keys rather than a set view.
| |||||||||||
Implements
size() . | |||||||||||
Provides a string representation of the entries within the map.
| |||||||||||
Implements
values() . | |||||||||||
Serializes this map to the given stream.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
java.io.Externalizable
| |||||||||||
From interface
java.util.Map
|
Construct a new sequenced hash map with default initial size and load factor.
Construct a new sequenced hash map with the specified initial size and default load factor.
initialSize | the initial size for the hash table |
---|
Construct a new sequenced hash map with the specified initial size and load factor.
initialSize | the initial size for the hash table |
---|---|
loadFactor | the load factor for the hash table. |
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)
.
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.
CloneNotSupportedException | if clone is not supported by a subclass. |
---|
Gets the key at the specified index.
index | the index to retrieve |
---|
ArrayIndexOutOfBoundsException | if the index is
< 0 or > the size of the map.
|
---|
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.
null
if the
map is empty.
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.
null
if the
map is empty.
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.
null
if the
map is empty.
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).
null
if the map
is empty.
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.
null
if the map is
empty.
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.
null
if the map
is empty.
Gets the value at the specified index.
index | the index to retrieve |
---|
ArrayIndexOutOfBoundsException | if the index is
< 0 or > the size of the map.
|
---|
Gets the index of the specified key.
key | the key to find the index of |
---|
Gets the last index of the specified key.
key | the key to find the index of |
---|
Adds all the mappings in the specified map to this map, replacing any
mappings that already exist (as per putAll(Map)
). The order
in which the entries are added is determined by the iterator returned
from entrySet()
for the specified map.
t | the mappings that should be added to this map. |
---|
NullPointerException | if t is null
|
---|
Deserializes this map from the given stream.
in | the stream to deserialize from |
---|
IOException | if the stream raises it |
---|---|
ClassNotFoundException | if the stream raises it |
Removes the element at the specified index.
index | The index of the object to remove. |
---|
key
, or
null
if none existed.ArrayIndexOutOfBoundsException | if the index is
< 0 or > the size of the map.
|
---|
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 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()
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.
Serializes this map to the given stream.
out | the stream to serialize to |
---|
IOException | if the stream raises it |
---|