org.jawk.jrt
Class AssocArray

java.lang.Object
  extended by org.jawk.jrt.AssocArray
All Implemented Interfaces:
java.util.Comparator<java.lang.Object>

public class AssocArray
extends java.lang.Object
implements java.util.Comparator<java.lang.Object>

An AWK associative array.

The implementation requires the ability to choose, at runtime, whether the keys are to be maintained in sorted order or not. Therefore, the implementation contains a reference to a Map (either TreeMap or HashMap, depending on whether to maintain keys in sorted order or not) and delegates calls to it accordingly.


Field Summary
protected  java.util.Map<java.lang.Object,java.lang.Object> map
           
static int MT_HASH
          The parameter to useMapType to convert this associative array to a HashMap.
static int MT_LINKED
          The parameter to useMapType to convert this associative array to a LinkedHashMap.
static int MT_TREE
          The parameter to useMapType to convert this associative array to a TreeMap.
 
Constructor Summary
AssocArray(boolean sorted_array_keys)
           
 
Method Summary
 void clear()
           
 int compare(java.lang.Object o1, java.lang.Object o2)
          Comparator implementation used by the TreeMap when keys are to be maintained in sorted order.
 java.lang.Object get(java.lang.Object key)
          Get the value of an associative array element given a particular key.
 java.lang.String getMapVersion()
           
 boolean isIn(java.lang.Object key)
          Test whether a particular key is contained within the associative array.
 java.util.Set<java.lang.Object> keySet()
           
 java.lang.String mapString()
          Provide a string representation of the delegated map object.
 java.lang.Object put(int key, java.lang.Object value)
          Added to support insertion of primitive key types.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
           
 java.lang.Object remove(java.lang.Object key)
           
 java.lang.String toString()
           
 void useMapType(int map_type)
          Convert the map which backs this associative array into one of HashMap, LinkedHashMap, or TreeMap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Field Detail

map

protected java.util.Map<java.lang.Object,java.lang.Object> map

MT_HASH

public static final int MT_HASH
The parameter to useMapType to convert this associative array to a HashMap.

See Also:
Constant Field Values

MT_LINKED

public static final int MT_LINKED
The parameter to useMapType to convert this associative array to a LinkedHashMap.

See Also:
Constant Field Values

MT_TREE

public static final int MT_TREE
The parameter to useMapType to convert this associative array to a TreeMap.

See Also:
Constant Field Values
Constructor Detail

AssocArray

public AssocArray(boolean sorted_array_keys)
Method Detail

useMapType

public void useMapType(int map_type)
Convert the map which backs this associative array into one of HashMap, LinkedHashMap, or TreeMap.

Parameters:
map_type - Can be one of MT_HASH, MT_LINKED, or MT_TREE.

mapString

public java.lang.String mapString()
Provide a string representation of the delegated map object. It exists to support the _DUMP keyword.


isIn

public boolean isIn(java.lang.Object key)
Test whether a particular key is contained within the associative array. Unlike get(), which adds a blank (null) reference to the associative array if the element is not found, isIn will not. It exists to support the IN keyword.


get

public java.lang.Object get(java.lang.Object key)
Get the value of an associative array element given a particular key. If the key does not exist, a null value (blank string) is inserted into the array with this key, and the null value is returned.


put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)

put

public java.lang.Object put(int key,
                            java.lang.Object value)
Added to support insertion of primitive key types.


keySet

public java.util.Set<java.lang.Object> keySet()

clear

public void clear()

remove

public java.lang.Object remove(java.lang.Object key)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

compare

public int compare(java.lang.Object o1,
                   java.lang.Object o2)
Comparator implementation used by the TreeMap when keys are to be maintained in sorted order.

Specified by:
compare in interface java.util.Comparator<java.lang.Object>

getMapVersion

public java.lang.String getMapVersion()