Package net.sf.saxon.ma.map
Class StringMapBuilder
java.lang.Object
net.sf.saxon.ma.map.StringMapBuilder
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 Summary
ConstructorsConstructorDescriptionStringMapBuilder(int specVersion) StringMapBuilder(int size, int specVersion) -
Method Summary
Modifier and TypeMethodDescriptionGet the constructed map.Get the constructed map.voidput(UnicodeString key, GroundedValue value) Add a key-value pairvoidsetCombiner(MapFunctionSet.OnDuplicatesAction combiner) Supply a combiner function for combining entries with duplicate keys.voidsetContext(XPathContext context) Supply a dynamic evaluation context for evaluating the combiner function.
-
Constructor Details
-
StringMapBuilder
public StringMapBuilder(int specVersion) -
StringMapBuilder
public StringMapBuilder(int size, int specVersion)
-
-
Method Details
-
setCombiner
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
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
Add a key-value pair- Parameters:
key- the keyvalue- the corresponding value
-
getCompletedMap
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
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
-