Package net.sf.saxon.ma.map
Class GeneralMapBuilder
java.lang.Object
net.sf.saxon.ma.map.GeneralMapBuilder
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 Summary
FieldsModifier and TypeFieldDescriptionprotected MapFunctionSet.OnDuplicatesActionCallback function to combine two values (for duplicate keys) into one.protected final List<AtomicValue> protected final intprotected final List<GroundedValue> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCopy all the keys and values from an existing mapGet the constructed map.getCompletedMap(XPathContext context) Get the constructed map.Get the constructed map, knowing that there are no duplicate keys.protected static booleanhasPossibleDuplicates(List<AtomicValue> keys, int specVersion) Quick check for possible duplicates in a set of keys, using a Bloom filtervoidput(AtomicValue key, GroundedValue value) Add a key-value pairvoidSet a combiner function for combining entries with duplicate keys.
-
Field Details
-
keys
-
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
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
Add a key-value pair- Parameters:
key- the keyvalue- the corresponding value
-
copy
Copy all the keys and values from an existing map- Parameters:
map- the map to be copied
-
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. 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
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
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
Quick check for possible duplicates in a set of keys, using a Bloom filter- Parameters:
keys- the set of keys to be checkedspecVersion- 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
-