Utils
Class ArrayMap<K,V>

java.lang.Object
  extended by Utils.ArrayMap<K,V>
Type Parameters:
K - The key type
V - The value type

public class ArrayMap<K,V>
extends java.lang.Object

A crude map of a fixed size that is backed by an array. Created to be memory effecient and allow quick updating of values (when their index is known) but still allow more user friendly access by key. Error checks are deliberately not done on put() and getEntry() for effeciency reasons. Calling code should ensure the map is big enough and that the index is valid else an ArrayIndexOutOfBoundsException will be thrown

Version:
1.2

Constructor Summary
ArrayMap(java.lang.Class<K> k, java.lang.Class<V> v, int size)
          Default Constructor.
 
Method Summary
 boolean containsKey(K k)
          Tests whether the map contains a key
 boolean equals(java.lang.Object o)
           
 V get(K k)
          Gets the value for a given key
 java.util.AbstractMap.SimpleEntry<K,V> getEntry(int i)
          Gets the key/value entry at a given location Error checks are deliberately not done for effeciency reasons.
 java.util.ArrayList<K> keyList()
          Gets a list of keys in the map
 void put(int i, K k, V v)
          Puts a new key/value pair into the map at a given location Error checks are deliberately not done for effeciency reasons.
 void put(K k, V v)
          Puts a new key/value pair into the map Error checks are deliberately not done for effeciency reasons.
 int size()
          Returns the size of the map.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayMap

public ArrayMap(java.lang.Class<K> k,
                java.lang.Class<V> v,
                int size)
Default Constructor. Passing the classes like this is the easiest way to deal with the java problems that come with using generics and arrays in Java

Parameters:
k - The class of the keys
v - The class of the values
size - The size of the map
Method Detail

put

public void put(K k,
                V v)
Puts a new key/value pair into the map Error checks are deliberately not done for effeciency reasons. Calling code should ensure the map is big enough else an ArrayIndexOutOfBoundsException will be thrown

Parameters:
k - The key
v - The value

put

public void put(int i,
                K k,
                V v)
Puts a new key/value pair into the map at a given location Error checks are deliberately not done for effeciency reasons. Calling code should ensure that the index is valid else an ArrayIndexOutOfBoundsException will be thrown

Parameters:
i - The location to add the key / value pair
k - The key
v - The value

keyList

public java.util.ArrayList<K> keyList()
Gets a list of keys in the map

Returns:
A list of keys

getEntry

public java.util.AbstractMap.SimpleEntry<K,V> getEntry(int i)
Gets the key/value entry at a given location Error checks are deliberately not done for effeciency reasons. Calling code should ensure that the index is valid else an ArrayIndexOutOfBoundsException will be thrown

Parameters:
i - The location to return the entry for
Returns:
The entry at that location

size

public int size()
Returns the size of the map. This is how many key/value pairs the map can hold, not how many it is holding

Returns:
The size of the map

containsKey

public boolean containsKey(K k)
Tests whether the map contains a key

Parameters:
k - The key to test for
Returns:
Whether the map contains the key

get

public V get(K k)
Gets the value for a given key

Parameters:
k - The key
Returns:
The value associated with that key

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object