Class StringMapBuilder

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

public class StringMapBuilder extends Object
Builder class for constructing ordered maps, where the keys are all known in advance to have a type annotation of xs:string (so we don't need to retain the type annotation). 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.
  • Constructor Details

    • StringMapBuilder

      public StringMapBuilder(int specVersion)
    • StringMapBuilder

      public StringMapBuilder(int size, int specVersion)
  • Method Details

    • setCombiner

      public void setCombiner(MapFunctionSet.OnDuplicatesAction combiner)
      Supply 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.
    • setContext

      public void setContext(XPathContext context)
      Supply a dynamic evaluation context for evaluating the combiner function. Needed if and only if the combiner calls a user-defined XDM function
      Parameters:
      context - the XPath evaluation context
    • put

      public void put(UnicodeString key, GroundedValue value)
      Add a key-value pair
      Parameters:
      key - the key
      value - the corresponding value
    • 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.
      Returns:
      the constructed map
      Throws:
      XPathException - if duplicate keys were found, and not detected earlier
    • getCompletedMapConfidently

      public MapItem getCompletedMapConfidently()
      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 version of the method does not check for duplicated keys, and must be used only when the caller is 100% confident that there are no duplicates.
      Returns:
      the constructed map