Package org.sentrysoftware.jawk.jrt
Class AssocArray
java.lang.Object
org.sentrysoftware.jawk.jrt.AssocArray
- All Implemented Interfaces:
Comparator<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.
- Author:
- Danny Daglas
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The parameter to useMapType to convert this associative array to a HashMap.static final int
The parameter to useMapType to convert this associative array to a LinkedHashMap.static final int
The parameter to useMapType to convert this associative array to a TreeMap. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear the arrayint
Comparator implementation used by the TreeMap when keys are to be maintained in sorted order.get.getMapVersion.boolean
isIn.keySet()
keySet.Provide a string representation of the delegated map object.Added to support insertion of primitive key types.Added to support insertion of primitive key types.Delete the specified entrytoString()
Do nothing.void
useMapType
(int mapType) Convert the map which backs this associative array into one of HashMap, LinkedHashMap, or TreeMap.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
MT_HASH
public static final int MT_HASHThe parameter to useMapType to convert this associative array to a HashMap.- See Also:
-
MT_LINKED
public static final int MT_LINKEDThe parameter to useMapType to convert this associative array to a LinkedHashMap.- See Also:
-
MT_TREE
public static final int MT_TREEThe parameter to useMapType to convert this associative array to a TreeMap.- See Also:
-
-
Constructor Details
-
AssocArray
public AssocArray(boolean sortedArrayKeys) Constructor for AssocArray.
- Parameters:
sortedArrayKeys
- Whether keys must be kept sorted
-
-
Method Details
-
useMapType
public void useMapType(int mapType) Convert the map which backs this associative array into one of HashMap, LinkedHashMap, or TreeMap.- Parameters:
mapType
- Can be one of MT_HASH, MT_LINKED, or MT_TREE.
-
mapString
Provide a string representation of the delegated map object. It exists to support the _DUMP keyword.- Returns:
- string representing the map/array
-
isIn
isIn.
- Parameters:
key
- Key to be checked- Returns:
- 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
get.
- Parameters:
key
- Key to retrieve in the array- Returns:
- 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
Added to support insertion of primitive key types.- Parameters:
key
- Key of the entry to put in the arrayvalue
- Value of the key- Returns:
- the previous value of the specified key, or null if key didn't exist
-
put
Added to support insertion of primitive key types.- Parameters:
key
- Index of the entry to put in the arrayvalue
- Value of the key- Returns:
- the previous value of the specified key, or null if key didn't exist
-
keySet
keySet.
- Returns:
- the set of keys
-
clear
public void clear()Clear the array -
remove
Delete the specified entry- Parameters:
key
- Key of the entry to remove from the array- Returns:
- the value of the entry before it was removed
-
toString
Do nothing. Should not be called in this state. -
compare
Comparator implementation used by the TreeMap when keys are to be maintained in sorted order.- Specified by:
compare
in interfaceComparator<Object>
-
getMapVersion
getMapVersion.
- Returns:
- the specification version of this class
-