org.apache.commons.collections
public class SequencedHashMap extends Object implements Map, Cloneable, Externalizable
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 {@link java.util.List} because of incompatible interface definitions. The remove methods in List and Map have different return values (see: {@link java.util.List#remove(Object)} and {@link java.util.Map#remove(Object)}).
This class is not thread safe. When a thread safe implementation is required, use {@link java.util.Collections#synchronizedMap(Map)} as it is documented, or use explicit synchronization controls.
Since: Commons Collections 2.0
Version: $Revision: 1.28 $ $Date: 2004/02/18 01:15:42 $
See Also: LinkedMap ListOrderedMap
Constructor Summary | |
---|---|
SequencedHashMap()
Construct a new sequenced hash map with default initial size and load
factor. | |
SequencedHashMap(int initialSize)
Construct a new sequenced hash map with the specified initial size and
default load factor.
| |
SequencedHashMap(int initialSize, float loadFactor)
Construct a new sequenced hash map with the specified initial size and
load factor.
| |
SequencedHashMap(Map m)
Construct a new sequenced hash map and add all the elements in the
specified map. |
Method Summary | |
---|---|
void | clear()
Implements {@link Map#clear()}. |
Object | clone()
Creates a shallow copy of this object, preserving the internal structure
by copying only references. |
boolean | containsKey(Object key)
Implements {@link Map#containsKey(Object)}. |
boolean | containsValue(Object value)
Implements {@link Map#containsValue(Object)}. |
Set | entrySet()
Implements {@link Map#entrySet()}. |
boolean | equals(Object obj)
Implements {@link Map#equals(Object)}. |
Object | get(Object o)
Implements {@link Map#get(Object)}. |
Object | get(int index)
Gets the key at the specified index.
|
Entry | getFirst()
Return the entry for the "oldest" mapping. |
Object | getFirstKey()
Return the key for the "oldest" mapping. |
Object | getFirstValue()
Return the value for the "oldest" mapping. |
Entry | getLast()
Return the entry for the "newest" mapping. |
Object | getLastKey()
Return the key for the "newest" mapping. |
Object | getLastValue()
Return the value for the "newest" mapping. |
Object | getValue(int index)
Gets the value at the specified index.
|
int | hashCode()
Implements {@link Map#hashCode()}. |
int | indexOf(Object key)
Gets the index of the specified key.
|
boolean | isEmpty()
Implements {@link Map#isEmpty()}. |
Iterator | iterator()
Gets an iterator over the keys.
|
Set | keySet()
Implements {@link Map#keySet()}. |
int | lastIndexOf(Object key)
Gets the last index of the specified key.
|
Object | put(Object key, Object value)
Implements {@link Map#put(Object, Object)}. |
void | putAll(Map t)
Adds all the mappings in the specified map to this map, replacing any
mappings that already exist (as per {@link Map#putAll(Map)}). |
void | readExternal(ObjectInput in)
Deserializes this map from the given stream.
|
Object | remove(Object key)
Implements {@link Map#remove(Object)}. |
Object | remove(int index)
Removes the element at the specified index.
|
List | sequence()
Returns a List view of the keys rather than a set view. |
int | size()
Implements {@link Map#size()}. |
String | toString()
Provides a string representation of the entries within the map. |
Collection | values()
Implements {@link Map#values()}. |
void | writeExternal(ObjectOutput out)
Serializes this map to the given stream.
|
Parameters: initialSize the initial size for the hash table
See Also: HashMap#HashMap(int)
Parameters: initialSize the initial size for the hash table loadFactor the load factor for the hash table.
See Also: HashMap#HashMap(int,float)
clone()
'd. The cloned object maintains the same sequence.
Returns: A clone of this instance.
Throws: CloneNotSupportedException if clone is not supported by a subclass.
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.
entrySet().iterator().next()
, but this method provides an
optimized implementation.
Returns: The first entry in the sequence, or null
if the
map is empty.
getFirst().getKey()
, but this method provides a slightly
optimized implementation.
Returns: The first key in the sequence, or null
if the
map is empty.
getFirst().getValue()
, but this method provides a slightly
optimized implementation.
Returns: The first value in the sequence, or null
if the
map is empty.
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.
getLast().getKey()
, but this method provides a slightly
optimized implementation.
Returns: The last key in the sequence, or null
if the map is
empty.
getLast().getValue()
, but this method provides a slightly
optimized implementation.
Returns: The last value in the sequence, or null
if the map
is empty.
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.
Parameters: key the key to find the index of
Returns: the index, or -1 if not found
Returns: an iterator over the keys
Parameters: key the key to find the index of
Returns: the index, or -1 if not found
Parameters: t the mappings that should be added to this map.
Throws: NullPointerException if t
is null
Parameters: in the stream to deserialize from
Throws: IOException if the stream raises it ClassNotFoundException if the stream raises it
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.
An alternative to this method is to use {@link #keySet()}
Returns: The ordered list of keys.
See Also: keySet
Parameters: out the stream to serialize to
Throws: IOException if the stream raises it