com.tensegrity.generic.util
Class StableHashMap

java.lang.Object
  extended bycom.tensegrity.generic.util.StableHashMap
All Implemented Interfaces:
java.util.Map

public final class StableHashMap
extends java.lang.Object
implements java.util.Map

This version of a HashMap keeps the order of its elements. This is different from the original java1.3 HashMap that imposes no order on its elements. Java 1.4 has a class that resembles this class.

The order of the values in the StableHashMap is stable and does not change throughout the lifetime of the map.

The class also allows to remove a value from the order and bring it to front or to the back of the order in linear time. Methods that do this are moveToBegin(Object) and moveToEnd(Object).

Version:
$Id: StableHashMap.java,v 1.25 2006/01/26 16:41:49 MichaelKegel Exp $
Author:
S.Rutz, MichaelKegel

Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Constructor Summary
StableHashMap()
          Constructs a new empty StableHashMap.
StableHashMap(int initialCapacity)
          Constructs a new empty StableHashMap with the specified initial capacity.
StableHashMap(StableHashMap stablehashmap)
          Constructs a new empty StableHashMap that is filled with the key/value pairs from the given StableHashMap.
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set entrySet()
           
 java.lang.Object get(java.lang.Object key)
           
 java.lang.Object getFirst()
          Return the object that comes as first in the internal order.
 java.lang.Object getLast()
          Return the object that comes as last in the internal order.
 java.lang.Object getPredecessor(java.lang.Object key)
          Returns the predecessor of the value represented by the given key.
 java.lang.Object getPredecessorKey(java.lang.Object key)
          Returns the key for the predecessor of the value represented by the given key.
 java.lang.Object getSuccessor(java.lang.Object key)
          Returns the successor of the value represented by the given key.
 java.lang.Object getSuccessorKey(java.lang.Object key)
          Returns the key for the successor of the value represented by the given key.
 java.util.List internalEntriesBetween(java.lang.Object key0, java.lang.Object key1)
          Undocumented Tensegrity Visualization Framework internal method.
 boolean isEmpty()
           
 java.util.Set keySet()
           
 boolean moveBackward(java.lang.Object key)
          Brings the object with the associated key one step backwards in the internal order.
 boolean moveBefore(java.lang.Object keyPivot, java.lang.Object key)
          Brings the object indetified by the given key right before the object identified by the given keyPivot in the internal order.
 boolean moveBehind(java.lang.Object keyPivot, java.lang.Object key)
          Brings the object indetified by the given key right behind the object identified by the given keyPivot in the internal order.
 boolean moveForward(java.lang.Object key)
          Brings the object with the associated key one step forward in the internal order.
 boolean moveToBegin(java.lang.Object key)
          Brings the object with the associated key to the beginning of the internal order.
 boolean moveToEnd(java.lang.Object key)
          Brings the object with the associated key to the end of the internal order.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 void putAll(java.util.Map t)
           
 boolean putBefore(java.lang.Object keyPivot, java.lang.Object key, java.lang.Object value)
          Inserts the specified key-value pair right before the mapping specified through the given keyPivot and returns a boolean that indicates whether a mapping for the given key-value pair has been created or not.
 boolean putBehind(java.lang.Object keyPivot, java.lang.Object key, java.lang.Object value)
          Inserts the specified key-value pair right after the mapping specified through the given keyPivot and returns a boolean that indicates whether a mapping for the given key-value pair has been created or not.
 java.lang.Object remove(java.lang.Object key)
           
 int size()
           
 java.util.Collection values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

StableHashMap

public StableHashMap()
Constructs a new empty StableHashMap.


StableHashMap

public StableHashMap(int initialCapacity)
Constructs a new empty StableHashMap with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of this instance.

StableHashMap

public StableHashMap(StableHashMap stablehashmap)
Constructs a new empty StableHashMap that is filled with the key/value pairs from the given StableHashMap.

Parameters:
stablehashmap - input HashMap that contains initial key/value pairs that are inserted into this instance upon creation.
Throws:
InvalidArgumentException, - if a null map is given.
Method Detail

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map

size

public int size()
Specified by:
size in interface java.util.Map

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map

putAll

public void putAll(java.util.Map t)
Specified by:
putAll in interface java.util.Map

remove

public java.lang.Object remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map

clear

public void clear()
Specified by:
clear in interface java.util.Map

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map

keySet

public java.util.Set keySet()
Specified by:
keySet in interface java.util.Map

entrySet

public java.util.Set entrySet()
Specified by:
entrySet in interface java.util.Map

values

public java.util.Collection values()
Specified by:
values in interface java.util.Map

internalEntriesBetween

public java.util.List internalEntriesBetween(java.lang.Object key0,
                                             java.lang.Object key1)
Undocumented Tensegrity Visualization Framework internal method.

Parameters:
key0 - undocumented Tensegrity Visualization Framework internal method
key1 - undocumented Tensegrity Visualization Framework internal method
Returns:
List undocumented Tensegrity Visualization Framework internal method

getFirst

public java.lang.Object getFirst()
Return the object that comes as first in the internal order. If no objects are stored in the map null is returned.

Returns:
Obhect the object that comes as first in the internal order or null

getLast

public java.lang.Object getLast()
Return the object that comes as last in the internal order. If no objects are stored in the map null is returned.

Returns:
Obhect the object that comes as last in the internal order or null

getPredecessor

public java.lang.Object getPredecessor(java.lang.Object key)
Returns the predecessor of the value represented by the given key. If the the map does not contain a mapping for the specified key null is returned.

Parameters:
key - the key of the value whose predecessor should be returned
Returns:
Object the predecessor or null if the value has no predecessor

getSuccessor

public java.lang.Object getSuccessor(java.lang.Object key)
Returns the successor of the value represented by the given key. If the the map does not contain a mapping for the specified key null is returned.

Parameters:
key - the key of the value whose successor should be returned
Returns:
Object the successor or null if the value has no successor

getPredecessorKey

public java.lang.Object getPredecessorKey(java.lang.Object key)
Returns the key for the predecessor of the value represented by the given key. If the the map does not contain a mapping for the specified key null is returned.

Parameters:
key - the key of the value whose predecessor key should be returned
Returns:
Object the key for the predecessor or null if the value has no predecessor

getSuccessorKey

public java.lang.Object getSuccessorKey(java.lang.Object key)
Returns the key for the successor of the value represented by the given key. If the the map does not contain a mapping for the specified key null is returned.

Parameters:
key - the key of the value whose successor key should be returned
Returns:
Object the key for the successor or null if the value has no successor

putBefore

public boolean putBefore(java.lang.Object keyPivot,
                         java.lang.Object key,
                         java.lang.Object value)
Inserts the specified key-value pair right before the mapping specified through the given keyPivot and returns a boolean that indicates whether a mapping for the given key-value pair has been created or not.
If the map does not contain a mapping for the given keyPivot the specified key-value pair is not inserted and false is returned.

Parameters:
keyPivot - the key of the value the specified key-value pair should be inserted right before
key - the key of the mapping to insert
value - the value of the mapping to insert
Returns:
boolean a flag indicating whether the mapping has been inserted

putBehind

public boolean putBehind(java.lang.Object keyPivot,
                         java.lang.Object key,
                         java.lang.Object value)
Inserts the specified key-value pair right after the mapping specified through the given keyPivot and returns a boolean that indicates whether a mapping for the given key-value pair has been created or not.
If the map does not contain a mapping for the given keyPivot the specified key-value pair is not inserted and false is returned.

Parameters:
keyPivot - the key of the value the specified key-value pair should be inserted right after
key - the key of the mapping to insert
value - the value of the mapping to insert
Returns:
boolean a flag indicating whether the mapping has been inserted

moveToBegin

public boolean moveToBegin(java.lang.Object key)
Brings the object with the associated key to the beginning of the internal order.

Parameters:
key - the key that identifies the element to reorder.
Returns:
true if the object was found and thus reordered. True is also returned if the object was at the beginning of the order.

moveToEnd

public boolean moveToEnd(java.lang.Object key)
Brings the object with the associated key to the end of the internal order.

Parameters:
key - the key that identifies the element to reorder.
Returns:
true if the object was found and thus reordered. True is also returned if the object was at the end of the order.

moveBefore

public boolean moveBefore(java.lang.Object keyPivot,
                          java.lang.Object key)
Brings the object indetified by the given key right before the object identified by the given keyPivot in the internal order.

Parameters:
keyPivot - the key that identifies the pivot object
key - the key that identifies the object to move
Returns:
boolean flag that indicates whether the given key and the given keyPivot were found in the map or not

moveBehind

public boolean moveBehind(java.lang.Object keyPivot,
                          java.lang.Object key)
Brings the object indetified by the given key right behind the object identified by the given keyPivot in the internal order.

Parameters:
keyPivot - the key that identifies the pivot object
key - the key that identifies the object to move
Returns:
boolean flag that indicates whether the given key and the given keyPivot were found in the map or not

moveForward

public boolean moveForward(java.lang.Object key)
Brings the object with the associated key one step forward in the internal order.

Parameters:
key - the key that identifies the element to reorder.
Returns:
boolean flag that indicates whether the given key was found in the map or not

moveBackward

public boolean moveBackward(java.lang.Object key)
Brings the object with the associated key one step backwards in the internal order.

Parameters:
key - the key that identifies the element to reorder.
Returns:
boolean flag that indicates whether the given key was found in the map or not


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.