org.opengts.util
Class OrderedMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by org.opengts.util.OrderedMap<K,V>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<K,V>
Direct Known Subclasses:
ComboMap

public class OrderedMap<K,V>
extends java.util.HashMap<K,V>
implements java.util.Map<K,V>

OrderedMap provides a HashMap where values can also be retrieved in the order they were added

See Also:
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>
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
OrderedMap()
          Constructor
OrderedMap(boolean retainOriginalValue)
          Constructor
OrderedMap(java.util.Map<K,V> map)
          Constructor
 
Method Summary
 void clear()
          Clears the contents of this map
 boolean containsKey(java.lang.Object key)
          Returns true if this map contains the specified key
 boolean containsKeyIgnoreCase(java.lang.String key)
          Returns true if this map contains the specified case-insensitive key
 java.util.Set<java.util.Map.Entry<K,V>> entrySet()
          Return a set of Map.Entry elements
 V get(java.lang.Object key)
          Gets the value for the specified key
 K getFirstKey()
          Gets the first key.
 V getFirstValue()
          Gets the first value.
 K getKey(int ndx)
          Gets the key at the specified index.
 java.lang.String getProperty(java.lang.String key)
          Gets the value for the specified key
 java.lang.String getProperty(java.lang.String key, java.lang.String dft)
          Gets the value for the specified key
 V getValue(int ndx)
          Gets the value at the specified index.
 int indexOfKey(java.lang.Object key)
          Returns the index of the specified key in this map
 boolean isIgnoreCase()
          Returns true if all lookups should be performed with case-insensitive keys
 K[] keyArray(java.lang.Class<K> arrayType)
          Returns an array of key elements from this map
 java.lang.Object keyCaseFilter(java.lang.Object key)
          Maps the specified String key to its map lookup key.
 java.util.Iterator<K> keyIterator()
          Returns an Iterator over the keys in this map
 java.util.Set<K> keySet()
          Returns a shallow copy of an ordered set of keys from this map (Warning: The returned 'keySet' is not backed by the map, thus any Iterator 'remove()' calls performed on the returned set will not remove the item from this map)
 OrderedSet<K> orderedKeySet()
          Returns the ordered set of keys from this map
Warning: The returned 'keySet' is not backed by the map, thus any Iterator 'remove()' calls performed on the returned set will not remove the item from this map
Warning: The returned value is the actual internal Ordered Set used to maintain ordering of this ordered map.
 V put(int ndx, K key, V value)
          Puts the specified key/value into the map at the specified index.
 V put(K key, V value)
          Puts the specified key/value into the map.
 void putAll(java.util.Map<? extends K,? extends V> map)
          Copies the contents of the specified map into this map.
Note that if the specified is not ordered, then the order in which the elements are placed into this map is unpredictable.
 void remove(int ndx)
          Removes the key/value at the specified index
 V remove(java.lang.Object key)
          Removes the specified key from this map.
 void setIgnoreCase(boolean ignoreCase)
          Sets the case-insensitive key-lookup mode
 V setProperty(K key, V value)
          Puts the specified key/value Strings into the map.
 void sortKeys(java.util.Comparator<K> comp)
          Sorts the key set based on the specified Comparator
 V[] valueArray(java.lang.Class<V> arrayType)
          Returns an array of value elements from this map
 java.util.Iterator<V> valueIterator()
          Returns an Iterator over the values in this map
 java.util.Collection<V> values()
          Returns a Collection of values in this map
 java.util.Set<V> valueSet()
          Returns an ordered set of values from this map
 
Methods inherited from class java.util.HashMap
clone, containsValue, isEmpty, size
 
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
containsValue, equals, hashCode, isEmpty, size
 

Constructor Detail

OrderedMap

public OrderedMap()
Constructor


OrderedMap

public OrderedMap(boolean retainOriginalValue)
Constructor


OrderedMap

public OrderedMap(java.util.Map<K,V> map)
Constructor

Parameters:
map - A map from which all contents will be copied
Method Detail

isIgnoreCase

public boolean isIgnoreCase()
Returns true if all lookups should be performed with case-insensitive keys

Returns:
True if all lookups should be performed with case-insensitive keys

setIgnoreCase

public void setIgnoreCase(boolean ignoreCase)
Sets the case-insensitive key-lookup mode

Parameters:
ignoreCase - True to perform case-insensitive key lookups

keyCaseFilter

public java.lang.Object keyCaseFilter(java.lang.Object key)
Maps the specified String key to its map lookup key. If the specified key is not a String, then the key argument is simple returned.

Parameters:
key - The key
Returns:
The mapped lookup key

clear

public void clear()
Clears the contents of this map

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

entrySet

public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
Return a set of Map.Entry elements

Specified by:
entrySet in interface java.util.Map<K,V>
Overrides:
entrySet in class java.util.HashMap<K,V>
Returns:
A set of Map.Entry elements

keySet

public java.util.Set<K> keySet()
Returns a shallow copy of an ordered set of keys from this map (Warning: The returned 'keySet' is not backed by the map, thus any Iterator 'remove()' calls performed on the returned set will not remove the item from this map)

Specified by:
keySet in interface java.util.Map<K,V>
Overrides:
keySet in class java.util.HashMap<K,V>
Returns:
A shallow copy of an ordered set of keys from this map

orderedKeySet

public OrderedSet<K> orderedKeySet()
Returns the ordered set of keys from this map
Warning: The returned 'keySet' is not backed by the map, thus any Iterator 'remove()' calls performed on the returned set will not remove the item from this map
Warning: The returned value is the actual internal Ordered Set used to maintain ordering of this ordered map. Changes to the map will be reflected in this returned OrderedSet. The returned OrderedSet must not be modified! Use with caution!

Returns:
The ordered set of keys from this map

keyArray

public K[] keyArray(java.lang.Class<K> arrayType)
Returns an array of key elements from this map

Returns:
An array of key elements from this map

keyIterator

public java.util.Iterator<K> keyIterator()
Returns an Iterator over the keys in this map

Returns:
An Iterator over the keys in this map

sortKeys

public void sortKeys(java.util.Comparator<K> comp)
Sorts the key set based on the specified Comparator

Parameters:
comp - The Comparator used to sort the keySet of this map

valueSet

public java.util.Set<V> valueSet()
Returns an ordered set of values from this map

Returns:
An ordered set of values from this map

valueArray

public V[] valueArray(java.lang.Class<V> arrayType)
Returns an array of value elements from this map

Returns:
An array of value elements from this map

valueIterator

public java.util.Iterator<V> valueIterator()
Returns an Iterator over the values in this map

Returns:
An Iterator over the values in this map

values

public java.util.Collection<V> values()
Returns a Collection of values in this map

Specified by:
values in interface java.util.Map<K,V>
Overrides:
values in class java.util.HashMap<K,V>
Returns:
A Collection of values in this map

put

public V put(int ndx,
             K key,
             V value)
Puts the specified key/value into the map at the specified index.

Parameters:
ndx - The index where the key/value are to be placed
key - The map key
value - The map value
Returns:
The previous value associated with the specified key.

put

public V put(K key,
             V value)
Puts the specified key/value into the map.

Specified by:
put in interface java.util.Map<K,V>
Overrides:
put in class java.util.HashMap<K,V>
Parameters:
key - The map key
value - The map value
Returns:
The previous value associated with the specified key.

setProperty

public V setProperty(K key,
                     V value)
Puts the specified key/value Strings into the map.

Parameters:
key - The map key String
value - The map value String
Returns:
The previous value associated with the specified key.

putAll

public void putAll(java.util.Map<? extends K,? extends V> map)
Copies the contents of the specified map into this map.
Note that if the specified is not ordered, then the order in which the elements are placed into this map is unpredictable.

Specified by:
putAll in interface java.util.Map<K,V>
Overrides:
putAll in class java.util.HashMap<K,V>
Parameters:
map - The map to copy to this map

containsKeyIgnoreCase

public boolean containsKeyIgnoreCase(java.lang.String key)
Returns true if this map contains the specified case-insensitive key

Parameters:
key - The key
Returns:
True if this map contains the specified case-insensitive key

containsKey

public boolean containsKey(java.lang.Object key)
Returns true if this map contains the specified key

Specified by:
containsKey in interface java.util.Map<K,V>
Overrides:
containsKey in class java.util.HashMap<K,V>
Parameters:
key - The key
Returns:
True if this map contains the specified key

indexOfKey

public int indexOfKey(java.lang.Object key)
Returns the index of the specified key in this map

Parameters:
key - The key
Returns:
The index of the specified key

remove

public V remove(java.lang.Object key)
Removes the specified key from this map.

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 this key

get

public V get(java.lang.Object key)
Gets the value for the specified key

Specified by:
get in interface java.util.Map<K,V>
Overrides:
get in class java.util.HashMap<K,V>
Parameters:
key - The key
Returns:
The value for the specified key, or null if the key is not found in this map.

getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.String dft)
Gets the value for the specified key

Parameters:
key - The key
dft - The default value returned if the key does not exist in this map.
Returns:
The value for the specified key. The default value is returned if the specified key is not found in this map.

getProperty

public java.lang.String getProperty(java.lang.String key)
Gets the value for the specified key

Parameters:
key - The key
Returns:
The value for the specified key. Null is returned if the specified key is not found in this map.

getFirstKey

public K getFirstKey()
Gets the first key.

Returns:
The first key

getKey

public K getKey(int ndx)
Gets the key at the specified index.

Parameters:
ndx - The key index
Returns:
The key at the specified index

getFirstValue

public V getFirstValue()
Gets the first value.

Returns:
The first value

getValue

public V getValue(int ndx)
Gets the value at the specified index.

Parameters:
ndx - The value index
Returns:
The value at the specified index

remove

public void remove(int ndx)
Removes the key/value at the specified index

Parameters:
ndx - The index of the key/value to remove