com.marringtons.number
Class IntegerMap

java.lang.Object
  extended bycom.marringtons.number.IntegerMap

public class IntegerMap
extends Object

IntegerMap is a convenience class where the key and value is an integer rather than an object. The key can be either integer or object.

 map.put(1, 1);
 assertTrue(map.get(1).intValue() == 1);
 
 map.put("two", 2);
 assertTrue(map.get("two").intValue() == 2);
 

Author:
Paul Marrington

Constructor Summary
IntegerMap()
          Creates a local map for integer values (that may be overridden if needed).
 
Method Summary
 Integer get(int key)
          Retrieve an integer value for an integer key.
 Integer get(Object key)
          Retrieve an integer value for an Object key (normally a string).
 void put(int key, int value)
          Associates the specified integer value with the specified integer key in this map.
 void put(Object key, int value)
          Associates the specified integer value with the specified key in this map.
 void setMap(Map map)
          When the default HashMap is not the correct map for the job, call setMap().
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IntegerMap

public IntegerMap()
Creates a local map for integer values (that may be overridden if needed).

Method Detail

setMap

public void setMap(Map map)
When the default HashMap is not the correct map for the job, call setMap().

Parameters:
map - to use as integer map - allowing any form of map to be used.

get

public Integer get(Object key)
Retrieve an integer value for an Object key (normally a string).

Parameters:
key - to retrieve integer value for.
Returns:
Integer value or null if it does not exist

get

public Integer get(int key)
Retrieve an integer value for an integer key. It is more efficient to use getKey() if the key often does not exist.

Parameters:
key - to retrieve integer value for.
Returns:
Integer value or null if it does not exist.

put

public void put(int key,
                int value)
Associates the specified integer value with the specified integer key in this map. If the map previously contained a mapping for this key, the old value is replaced by the specified value.

Parameters:
key - integer key to which the specified integer value is associated.
value - integer value to be associated with the provided integer key.

put

public void put(Object key,
                int value)
Associates the specified integer value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced by the specified value.

Parameters:
key - key to which the specified integer value is associated.
value - integer value to be associated with the provided key.


Copyright © 2005 Paul Marrington http://library.marringtons.com