Package org.metricshub.jawk.jrt
Class AssocArray
java.lang.Object
org.metricshub.jawk.jrt.AssocArray
- All Implemented Interfaces:
Comparator<Object>,Map<Object,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
-
Nested Class Summary
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe parameter to useMapType to convert this associative array to a HashMap.static final intThe parameter to useMapType to convert this associative array to a LinkedHashMap.static final intThe parameter to useMapType to convert this associative array to a TreeMap. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear the arrayintComparator implementation used by the TreeMap when keys are to be maintained in sorted order.booleancontainsKey(Object key) booleancontainsValue(Object value) entrySet()get.getMapVersion.booleanisEmpty()booleanisIn.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.voidDelete the specified entryintsize()toString()Do nothing.voiduseMapType(int mapType) Convert the map which backs this associative array into one of HashMap, LinkedHashMap, or TreeMap.values()Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
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.- 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.
- Specified by:
getin interfaceMap<Object,Object> - 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. -
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.
-
clear
public void clear()Clear the array -
remove
Delete the specified entry -
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:
comparein interfaceComparator<Object>
-
getMapVersion
getMapVersion.
- Returns:
- the specification version of this class
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKeyin interfaceMap<Object,Object>
-
containsValue
- Specified by:
containsValuein interfaceMap<Object,Object>
-
putAll
-
values
-
entrySet
-