org.clapper.util.misc
Class OrderedHashMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by org.clapper.util.misc.OrderedHashMap<K,V>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<K,V>

Deprecated. Please use java.util.LinkedHashMap, instead

public class OrderedHashMap<K,V>
extends java.util.HashMap<K,V>
implements java.lang.Cloneable, java.io.Serializable

An OrderedHashMap is a java.util.HashMap with one additional property: It maintains a list of the map's keys in the order they were added to the map. This additional capability imposes a small amount of extra overhead on insertion and a larger amount of overhead on key removal, but absolutely no additional key lookup overhead. This class is conceptually similar to (though less feature-rich than) the java.util.LinkedHashMap class added in JDK 1.4.

Version:
$Revision: 6735 $
Author:
Copyright © 2004-2007 Brian M. Clapper
See Also:
keysInInsertionOrder(), getKeysInInsertionOrder(java.util.List), Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
OrderedHashMap()
          Deprecated. Construct a new empty map with a default capacity and load factor.
OrderedHashMap(int initialCapacity)
          Deprecated. Construct a new empty map with the specified initial capacity and a default load factor.
OrderedHashMap(int initialCapacity, float loadFactor)
          Deprecated. Constructs a new, empty map with the specified initial capacity and the specified load factor.
OrderedHashMap(java.util.Map<? extends K,? extends V> map)
          Deprecated. Constructs a new map with the same mappings as the given map.
OrderedHashMap(OrderedHashMap<? extends K,? extends V> map)
          Deprecated. Constructs a new map with the same mappings as the given OrderedHashMap.
 
Method Summary
 void clear()
          Deprecated. Remove all mappings from this map.
 java.lang.Object clone()
          Deprecated. Returns a shallow copy of this instance.
 int getKeysInInsertionOrder(java.util.List<? super K> list)
          Deprecated. Get the keys in the order they were added to this map.
 java.util.List<K> keysInInsertionOrder()
          Deprecated. Get the keys in the order they were added to this map.
 V put(K key, V value)
          Deprecated. Associates the specified value with the specified key in this map.
 void putAll(java.util.Map<? extends K,? extends V> map)
          Deprecated. Copies all of the mappings from a specified map to this one.
 void putAll(OrderedHashMap<? extends K,? extends V> map)
          Deprecated. Copies all of the mappings from a specified map to this one.
 V remove(java.lang.Object key)
          Deprecated. Removes the mapping for a key, if there is one.
 
Methods inherited from class java.util.HashMap
containsKey, containsValue, entrySet, get, isEmpty, keySet, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

OrderedHashMap

public OrderedHashMap()
Deprecated. 
Construct a new empty map with a default capacity and load factor.


OrderedHashMap

public OrderedHashMap(int initialCapacity)
Deprecated. 
Construct a new empty map with the specified initial capacity and a default load factor.

Parameters:
initialCapacity - the initial capacity

OrderedHashMap

public OrderedHashMap(int initialCapacity,
                      float loadFactor)
Deprecated. 
Constructs a new, empty map with the specified initial capacity and the specified load factor.

Parameters:
initialCapacity - the initial capacity
loadFactor - the load factor

OrderedHashMap

public OrderedHashMap(java.util.Map<? extends K,? extends V> map)
Deprecated. 
Constructs a new map with the same mappings as the given map. The initial capacity and load factor is the same as for the parent HashMap class. Since there's no way of knowing in what order entries were made in the original map, the order imposed on them in this map is the order in which they are returned by the keySet() method.

Parameters:
map - the map whose mappings are to be copied
See Also:
OrderedHashMap(OrderedHashMap)

OrderedHashMap

public OrderedHashMap(OrderedHashMap<? extends K,? extends V> map)
Deprecated. 
Constructs a new map with the same mappings as the given OrderedHashMap. The initial capacity and load factor is the same as for the parent HashMap class. The insertion order of the keys is preserved.

Parameters:
map - the map whose mappings are to be copied
Method Detail

getKeysInInsertionOrder

public int getKeysInInsertionOrder(java.util.List<? super K> list)
Deprecated. 
Get the keys in the order they were added to this map.

Parameters:
list - the List to receive the keys
Returns:
the number of keys added to the list
See Also:
keysInInsertionOrder()

keysInInsertionOrder

public java.util.List<K> keysInInsertionOrder()
Deprecated. 
Get the keys in the order they were added to this map.

Returns:
a new List containing the keys in insertion order
See Also:
getKeysInInsertionOrder(java.util.List)

clone

public java.lang.Object clone()
Deprecated. 
Returns a shallow copy of this instance. The keys and values themselves are not cloned.

Overrides:
clone in class java.util.HashMap<K,V>
Returns:
a shallow copy of this map

clear

public void clear()
Deprecated. 
Remove all mappings from this map.

Specified by:
clear in interface java.util.Map<K,V>
Overrides:
clear in class java.util.HashMap<K,V>

put

public V put(K key,
             V value)
Deprecated. 
Associates the specified value with the specified key in this map. If the key already has a value in this map, the existing value is replaced by the new value, and the old value is replaced. If the key already exists in the map, it is moved to the end of the key insertion order list.

Specified by:
put in interface java.util.Map<K,V>
Overrides:
put in class java.util.HashMap<K,V>
Parameters:
key - the key with which the specified value is to be associated
value - the value to associate with the specified key
Returns:
the previous value associated with the key, or null if (a) there was no previous value, or (b) the previous value was a null

putAll

public void putAll(java.util.Map<? extends K,? extends V> map)
Deprecated. 
Copies all of the mappings from a specified map to this one. These mappings replace any mappings that this map had for any of the keys in this map. Since there's no way of knowing in what order entries were made in the original map, they are appended to the key insertion order list in the order they are returned by the map's keySet() method.

Specified by:
putAll in interface java.util.Map<K,V>
Overrides:
putAll in class java.util.HashMap<K,V>
Parameters:
map - the map whose mappings are to be copied
See Also:
putAll(OrderedHashMap)

putAll

public void putAll(OrderedHashMap<? extends K,? extends V> map)
Deprecated. 
Copies all of the mappings from a specified map to this one. These mappings replace any mappings that this map had for any of the keys in this map. The keys are appended to this map's key insertion order list in the order they were originally added to map.

Parameters:
map - the map whose mappings are to be copied
See Also:
putAll(OrderedHashMap), keysInInsertionOrder()

remove

public V remove(java.lang.Object key)
Deprecated. 
Removes the mapping for a key, if there is one. The key is also removed from the key insertion order list.

Specified by:
remove in interface java.util.Map<K,V>
Overrides:
remove in class java.util.HashMap<K,V>
Parameters:
key - the key to remove
Returns:
the previous value associated with the key, or null if (a) there was no previous value, or (b) the previous value was a null


Copyright © 2004-2007 Brian M. Clapper. All Rights Reserved.