org.openbp.common.util
Class OrderedMap

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap
          extended by org.openbp.common.util.OrderedMap
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map

public class OrderedMap
extends java.util.HashMap

Ordered map is a map which keeps the order of the incoming elements. It is based on a list and a map.

Author:
Andreas Putz
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>
 
Constructor Summary
OrderedMap()
          Constructor.
OrderedMap(int initialCapacity)
          Constructor.
 
Method Summary
 void clear()
          Clears the map.
 java.lang.Object getKey(int index)
          Gets a key by the index.
 java.lang.Object getLastKey()
          Gets the last key.
 java.lang.Object getLastValue()
          Gets the last value.
 java.lang.Object getValue(int index)
          Gets a value by the index.
 int indexOf(java.lang.Object key)
          Gets the index of an object.
 java.util.Set keySet()
          Returns a set of all element keys in the correct order.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Adds an element to the map.
 java.lang.Object remove(java.lang.Object key)
          Removes an element from the map.
 void removeLast()
          Removes the last entry.
 java.util.Collection values()
          Returns a collection of all element values in the correct order.
 
Methods inherited from class java.util.HashMap
clone, containsKey, containsValue, entrySet, get, isEmpty, putAll, 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
equals, hashCode
 

Constructor Detail

OrderedMap

public OrderedMap()
Constructor.


OrderedMap

public OrderedMap(int initialCapacity)
Constructor.

Parameters:
initialCapacity - The initial capacity
Method Detail

getValue

public java.lang.Object getValue(int index)
Gets a value by the index.

Parameters:
index - The index
Returns:
The value

getKey

public java.lang.Object getKey(int index)
Gets a key by the index.

Parameters:
index - The index
Returns:
The vkey

indexOf

public int indexOf(java.lang.Object key)
Gets the index of an object.

Parameters:
key - The key object
Returns:
The index or -1

removeLast

public void removeLast()
Removes the last entry.


getLastValue

public java.lang.Object getLastValue()
Gets the last value.

Returns:
The value

getLastKey

public java.lang.Object getLastKey()
Gets the last key.

Returns:
The key

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Adds an element to the map.

Specified by:
put in interface java.util.Map
Overrides:
put in class java.util.HashMap
Parameters:
key - Key of the element to add
value - Element value
Returns:
The old value of the element or null

remove

public java.lang.Object remove(java.lang.Object key)
Removes an element from the map.

Specified by:
remove in interface java.util.Map
Overrides:
remove in class java.util.HashMap
Parameters:
key - Key of the element to remove
Returns:
The old value of the element or null

clear

public void clear()
Clears the map.

Specified by:
clear in interface java.util.Map
Overrides:
clear in class java.util.HashMap

keySet

public java.util.Set keySet()
Returns a set of all element keys in the correct order.

Specified by:
keySet in interface java.util.Map
Overrides:
keySet in class java.util.HashMap
Returns:
The key set

values

public java.util.Collection values()
Returns a collection of all element values in the correct order.

Specified by:
values in interface java.util.Map
Overrides:
values in class java.util.HashMap
Returns:
The values


Copyright © 2011. All Rights Reserved.