Class DeltaMap

All Implemented Interfaces:
Iterable<KeyValuePair>, Callable, FunctionItem, GroundedValue, Item, Sequence

public class DeltaMap extends MapWithTypeCache implements Iterable<KeyValuePair>
A DeltaMap consists of a fixed part and a variable part. The fixed part represents the result of building a map "in bulk", for example with a map:merge or map:build call, or as the output of JSON parsing. The variable part represents the result of subsequent map:put and map:remove operations.

The thinking here is that map:put and map:remove operations are fairly rare, so most maps will be implemented as instances of AbstractFixedMap. If a map:put or map:remove then occurs, the result will be a DeltaMap that contains the original AbstractFixedMap, plus details of subsequent changes.

The variable part, representing the differences, actually includes three data structures:

  • A list of removals: entries that have been removed from the fixed map
  • A list of replacements: entries where a new value is now associated with a key that was present in the fixed map
  • A list of additions: new key-value pairs, themselves represented as a map
  • Constructor Details

    • DeltaMap

      public DeltaMap(AbstractFixedMap fixedMap)
      Construct a DeltaMap with a supplied fixed part, and an empty variable part
      Parameters:
      fixedMap - the supplied fixed part
  • Method Details

    • get

      public GroundedValue get(AtomicValue key)
      Get the value with a given key. This searches first, the additional entries, then the fixed entries, but taking into account any removals and replacements
      Specified by:
      get in class MapItem
      Parameters:
      key - the value of the key
      Returns:
      the associated value, or null.
    • size

      public int size()
      Description copied from class: MapItem
      Get the size of the map
      Specified by:
      size in class MapItem
      Returns:
      the number of keys/entries present in this map
    • keyValuePairs

      public Iterable<KeyValuePair> keyValuePairs()
      Description copied from class: MapItem
      Get the set of all key-value pairs in the map
      Specified by:
      keyValuePairs in class MapItem
      Returns:
      an iterable containing all the key-value pairs
    • iterator

      public Iterator<KeyValuePair> iterator()
      Implement Iterable<KeyValuePair>
      Specified by:
      iterator in interface Iterable<KeyValuePair>
      Returns:
      an iterator over the key-value pairs
    • put

      public MapItem put(AtomicValue key, GroundedValue value)
      Description copied from class: MapItem
      Create a new map containing the existing entries in the map plus an additional entry, without modifying the original. If there is already an entry with the specified key, this entry is replaced by the new entry.
      Specified by:
      put in class MapItem
      Parameters:
      key - the key of the new entry
      value - the value associated with the new entry
      Returns:
      the new map containing the additional entry
    • remove

      public MapItem remove(AtomicValue key)
      Description copied from class: MapItem
      Remove an entry from the map
      Specified by:
      remove in class MapItem
      Parameters:
      key - the key of the entry to be removed
      Returns:
      a new map in which the requested entry has been removed; or this map unchanged if the specified key was not present