org.jibx.binding.util
Class ArrayMap

java.lang.Object
  extended by org.jibx.binding.util.ArrayMap

public class ArrayMap
extends java.lang.Object

Array with reverse mapping from values to indices. This operates as the combination of an array with ordinary int indices and a hashmap from values back to the corresponding index position. Values are assured to be unique.

Author:
Dennis M. Sosnoski

Field Summary
private  java.util.ArrayList m_array
          Array of values.
private  java.util.HashMap m_map
          Map from values to indices.
 
Constructor Summary
ArrayMap()
          Default constructor.
ArrayMap(int size)
          Constructor with initial capacity supplied.
 
Method Summary
 int find(java.lang.Object obj)
          Find existing object.
 int findOrAdd(java.lang.Object obj)
          Add object.
 java.lang.Object get(int index)
          Get value for index.
 int size()
          Get count of values present.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_array

private java.util.ArrayList m_array
Array of values.


m_map

private java.util.HashMap m_map
Map from values to indices.

Constructor Detail

ArrayMap

public ArrayMap()
Default constructor.


ArrayMap

public ArrayMap(int size)
Constructor with initial capacity supplied.

Parameters:
size - initial capacity for array map
Method Detail

get

public java.lang.Object get(int index)
Get value for index. The index must be within the valid range (from 0 to one less than the number of values present).

Parameters:
index - number to be looked up
Returns:
value at that index position

find

public int find(java.lang.Object obj)
Find existing object. If the supplied value object is present in the array map its index position is returned.

Parameters:
obj - value to be found
Returns:
index number assigned to value, or -1 if not found

findOrAdd

public int findOrAdd(java.lang.Object obj)
Add object. If the supplied value object is already present in the array map the existing index position is returned.

Parameters:
obj - value to be added
Returns:
index number assigned to value

size

public int size()
Get count of values present.

Returns:
number of values in array map


Project Web Site