Package io.jawk.jrt

Class SortedAssocArray

All Implemented Interfaces:
AssocArray, Serializable, Cloneable, Map<Object,Object>, NavigableMap<Object,Object>, SortedMap<Object,Object>

public class SortedAssocArray extends TreeMap<Object,Object> implements AssocArray
An AWK associative array backed by a TreeMap.

Keys are maintained in sorted order using AWK comparison semantics: numeric keys are compared numerically, string keys lexicographically, and mixed key types fall back to string comparison.

Author:
MetricsHub
See Also:
  • Constructor Details

    • SortedAssocArray

      public SortedAssocArray()
      Creates a new sorted associative array using AWK key ordering.
  • Method Details

    • get

      public Object get(Object key)
      Returns the value to which the specified key is mapped, normalizing the key first. If the key does not exist, a blank (UninitializedObject) is inserted and returned, as required by AWK semantics.
      Specified by:
      get in interface Map<Object,Object>
      Overrides:
      get in class TreeMap<Object,Object>
      Parameters:
      key - the key whose associated value is to be returned
      Returns:
      the value associated with the key, or a blank value if not found
    • put

      public Object put(Object key, Object value)
      Associates the specified value with the specified key, normalizing the key to a Long when the key is a valid integer string.
      Specified by:
      put in interface Map<Object,Object>
      Overrides:
      put in class TreeMap<Object,Object>
      Parameters:
      key - the key
      value - the value
      Returns:
      the previous value associated with the key, or null
    • remove

      public Object remove(Object key)
      Removes the mapping for the specified key, trying both the original and its Long equivalent.
      Specified by:
      remove in interface Map<Object,Object>
      Overrides:
      remove in class TreeMap<Object,Object>
      Parameters:
      key - the key whose mapping is to be removed
      Returns:
      the previous value associated with the key, or null
    • getMapVersion

      public String getMapVersion()
      Returns the specification version of the underlying TreeMap class.
      Specified by:
      getMapVersion in interface AssocArray
      Returns:
      the specification version string, or null if unavailable
    • toString

      public String toString()
      Overrides:
      toString in class AbstractMap<Object,Object>
      Throws:
      AwkRuntimeException - always, to prevent accidental use of AbstractMap.toString() in an AWK evaluation context