Class GeneralMapBuilder

java.lang.Object
net.sf.saxon.ma.map.GeneralMapBuilder

public class GeneralMapBuilder extends Object
Builder class for constructing ordered maps. The builder simply accumulates keys and values until it is asked to construct and return a map with those keys and values. At that point it checks for duplicate keys, and carries out various optimizations to work out what map implementation class to use.
  • Field Details

    • keys

      protected final List<AtomicValue> keys
    • values

      protected final List<GroundedValue> values
    • specVersion

      protected final int specVersion
    • combiner

      Callback function to combine two values (for duplicate keys) into one. If null, duplicates are rejected as an error.
  • Constructor Details

    • GeneralMapBuilder

      public GeneralMapBuilder(int specVersion)
  • Method Details

    • setDuplicatesAction

      public void setDuplicatesAction(MapFunctionSet.OnDuplicatesAction combiner)
      Set a combiner function for combining entries with duplicate keys. If no combiner is set, duplicate keys result in a dynamic error.
      Parameters:
      combiner - a function that will be called with two grounded values (representing two values for the same key) and returns a single grounded value to be used in the result map.
    • put

      public void put(AtomicValue key, GroundedValue value)
      Add a key-value pair
      Parameters:
      key - the key
      value - the corresponding value
    • copy

      public void copy(MapItem map)
      Copy all the keys and values from an existing map
      Parameters:
      map - the map to be copied
    • getCompletedMap

      public MapItem getCompletedMap() throws XPathException
      Get the constructed map. This method must only be called once, because the lists of keys and values are used within the constructed map and are mutable. This method cannot be called if there is a combiner function, because calling the function potentially requires a run-time context.
      Returns:
      the constructed map
      Throws:
      XPathException - if duplicate keys were found, and not detected earlier
    • getCompletedMap

      public MapItem getCompletedMap(XPathContext context) throws XPathException
      Get the constructed map. This method must only be called once, because the lists of keys and values are used within the constructed map and are mutable.
      Parameters:
      context - The dynamic context: needed only when calling a combiner function to combine duplicate entries
      Returns:
      the constructed map
      Throws:
      XPathException - if duplicate keys were found, and not detected earlier
    • getCompletedMapConfidently

      public MapItem getCompletedMapConfidently()
      Get the constructed map, knowing that there are no duplicate keys. This method must only be called once, because the lists of keys and values are used within the constructed map and are mutable.
      Returns:
      the constructed map
    • hasPossibleDuplicates

      protected static boolean hasPossibleDuplicates(List<AtomicValue> keys, int specVersion)
      Quick check for possible duplicates in a set of keys, using a Bloom filter
      Parameters:
      keys - the set of keys to be checked
      specVersion - the XPath language version (determines how binary keys are compared)
      Returns:
      true if the set might or might not contain duplicates; false if it definitely contains no duplicates