Package net.sf.saxon.ma.map
Class MapItem
java.lang.Object
net.sf.saxon.ma.map.MapItem
- All Implemented Interfaces:
Callable
,FunctionItem
,GroundedValue
,Item
,Sequence
- Direct Known Subclasses:
DelegatingMapItem
,DictionaryMap
,HashTrieMap
,RangeKey
,SingleEntryMap
Interface supported by different implementations of an XDM map item
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract MapItem
addEntry
(AtomicValue key, GroundedValue value) Create a new map containing the existing entries in the map plus an additional entry, without modifying the original.atomize()
Atomize the item.call
(XPathContext context, Sequence[] args) Invoke the functionabstract boolean
conforms
(PlainType keyType, SequenceType valueType, TypeHierarchy th) Ask whether the map conforms to a given map typeboolean
deepEqual40
(FunctionItem other, XPathContext context, DeepEqual.DeepEqualOptions options) boolean
deepEquals
(FunctionItem other, XPathContext context, AtomicComparer comparer, int flags) Test whether this FunctionItem is deep-equal to another function item, under the rules of the deep-equal functionboolean
Get the effective boolean value of this sequenceentries()
Get an iterator over the entries in the map, each represented as a singleton map (representing one key-value pair)void
Export information about this function item to the export() or explain() outputabstract GroundedValue
get
(AtomicValue key) Get an entry from the MapGet the function annotations (as defined in XQuery).int
getArity()
Get the arity of the functionGet a description of this function for use in error messages.Get the item type of this item as a function item.Get the name of the function, or null if it is anonymousgetGenre()
Get the genre of this itemabstract ItemType
Get the type of the map.static ItemType
Get an item type to which all the values in a sequence are known to conformabstract UType
Get the lowest common item type of the keys in the mapGet the roles of the arguments, for the purposes of streamingGet the typed value of the item.Get the value of the item as a string.boolean
isArray()
Ask whether this function item is an arrayboolean
isEmpty()
Ask whether the map is emptystatic boolean
isKnownToConform
(Sequence value, ItemType itemType) Ask whether all the items in a sequence are known to conform to a given item typeboolean
isMap()
Ask whether this function item is a mapboolean
Ask if the function can be trusted to return a result of the correct typeitemAt
(int n) Get the n'th item in the value, counting from 0abstract AtomicIterator
keys()
Get the set of all key values in the map.abstract Iterable
<KeyValuePair> Get the set of all key-value pairs in the mapmakeNewContext
(XPathContext callingContext, ContextOriginator originator) Prepare an XPathContext object for evaluating the functionstatic String
mapToString
(MapItem map) Returns a string representation of the map.abstract MapItem
remove
(AtomicValue key) Remove an entry from the mapabstract int
size()
Get the size of the mapProvide a short string showing the contents of the item, suitable for use in error messagesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.sf.saxon.om.FunctionItem
isSequenceVariadic
Methods inherited from interface net.sf.saxon.om.GroundedValue
asIterable, concatenate, containsNode, materialize
Methods inherited from interface net.sf.saxon.om.Item
getLength, getStringValue, head, isStreamed, iterate, reduce, subsequence
Methods inherited from interface net.sf.saxon.om.Sequence
makeRepeatable
-
Constructor Details
-
MapItem
public MapItem()
-
-
Method Details
-
get
Get an entry from the Map- Parameters:
key
- the value of the key- Returns:
- the value associated with the given key, or null if the key is not present in the map.
-
size
public abstract int size()Get the size of the map- Returns:
- the number of keys/entries present in this map
-
isEmpty
public boolean isEmpty()Ask whether the map is empty- Returns:
- true if and only if the size of the map is zero
-
keys
Get the set of all key values in the map.- Returns:
- a set containing all the key values present in the map, in unpredictable order
-
keyValuePairs
Get the set of all key-value pairs in the map- Returns:
- an iterable containing all the key-value pairs
-
entries
Get an iterator over the entries in the map, each represented as a singleton map (representing one key-value pair)- Returns:
- a
SequenceIterator
over the entries in the map, represented as single-entry maps
-
addEntry
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.- Parameters:
key
- the key of the new entryvalue
- the value associated with the new entry- Returns:
- the new map containing the additional entry
-
remove
Remove an entry from the map- 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
-
conforms
Ask whether the map conforms to a given map type- Parameters:
keyType
- the required keyTypevalueType
- the required valueTypeth
- the type hierarchy cache for the configuration- Returns:
- true if the map conforms to the required type
-
getItemType
Get the type of the map. This method is used largely for diagnostics, to report the type of a map when it differs from the required type.- Parameters:
th
- the type hierarchy cache- Returns:
- the type of this map
-
getKeyUType
Get the lowest common item type of the keys in the map- Returns:
- the most specific type to which all the keys belong. If the map is empty, return UType.VOID
-
toShortString
Provide a short string showing the contents of the item, suitable for use in error messages- Specified by:
toShortString
in interfaceFunctionItem
- Specified by:
toShortString
in interfaceGroundedValue
- Specified by:
toShortString
in interfaceItem
- Returns:
- a depiction of the item suitable for use in error messages
-
getGenre
Get the genre of this item- Specified by:
getGenre
in interfaceFunctionItem
- Specified by:
getGenre
in interfaceItem
- Returns:
- the genre: specifically, Map.
-
isArray
public boolean isArray()Ask whether this function item is an array- Specified by:
isArray
in interfaceFunctionItem
- Returns:
- false (it is not an array)
-
isMap
public boolean isMap()Ask whether this function item is a map- Specified by:
isMap
in interfaceFunctionItem
- Returns:
- true (it is a map)
-
getAnnotations
Get the function annotations (as defined in XQuery). Returns an empty list if there are no function annotations.- Specified by:
getAnnotations
in interfaceFunctionItem
- Returns:
- the function annotations
-
atomize
Atomize the item.- Specified by:
atomize
in interfaceItem
- Returns:
- the result of atomization
- Throws:
XPathException
- if atomization is not allowed for this kind of item
-
isKnownToConform
Ask whether all the items in a sequence are known to conform to a given item type- Parameters:
value
- the sequenceitemType
- the given item type- Returns:
- true if all the items conform; false if not, or if the information cannot be efficiently determined
-
getItemTypeOfSequence
Get an item type to which all the values in a sequence are known to conform- Parameters:
val
- the sequence- Returns:
- the type of the first item in the sequence, provided that all subsequent values in the sequence are known to conform to this type; otherwise item().
-
getOperandRoles
Get the roles of the arguments, for the purposes of streaming- Specified by:
getOperandRoles
in interfaceFunctionItem
- Returns:
- an array of OperandRole objects, one for each argument
-
getFunctionItemType
Get the item type of this item as a function item. Note that this returns the generic function type for maps, not a type related to this specific map.- Specified by:
getFunctionItemType
in interfaceFunctionItem
- Returns:
- the function item's type
-
getFunctionName
Get the name of the function, or null if it is anonymous- Specified by:
getFunctionName
in interfaceFunctionItem
- Returns:
- the function name, or null for an anonymous inline function
-
getDescription
Get a description of this function for use in error messages. For named functions, the description is the function name (as a lexical QName). For others, it might be, for example, "inline function", or "partially-applied ends-with function".- Specified by:
getDescription
in interfaceFunctionItem
- Returns:
- a description of the function for use in error messages
-
getArity
public int getArity()Get the arity of the function- Specified by:
getArity
in interfaceFunctionItem
- Returns:
- the number of arguments in the function signature
-
makeNewContext
Prepare an XPathContext object for evaluating the function- Specified by:
makeNewContext
in interfaceFunctionItem
- Parameters:
callingContext
- the XPathContext of the function calling expressionoriginator
- not used- Returns:
- a suitable context for evaluating the function (which may or may not be the same as the caller's context)
-
call
Invoke the function- Specified by:
call
in interfaceCallable
- Parameters:
context
- the XPath dynamic evaluation contextargs
- the actual arguments to be supplied- Returns:
- the result of invoking the function
- Throws:
XPathException
- if an error occurs evaluating the supplied argument
-
getUnicodeStringValue
Get the value of the item as a string. For nodes, this is the string value of the node as defined in the XPath 2.0 data model, except that all nodes are treated as being untyped: it is not an error to get the string value of a node with a complex type. For atomic values, the method returns the result of casting the atomic value to a string.- Specified by:
getUnicodeStringValue
in interfaceGroundedValue
- Specified by:
getUnicodeStringValue
in interfaceItem
- Returns:
- the string value of the item
- Throws:
UncheckedXPathException
- if the item is a function item (an unchecked exception is used here to avoid introducing exception handling to a large number of paths where it is not needed)- Since:
- 8.4
-
getTypedValue
Get the typed value of the item.For a node, this is the typed value as defined in the XPath 2.0 data model. Since a node may have a list-valued data type, the typed value is in general a sequence, and it is returned in the form of a SequenceIterator.
If the node has not been validated against a schema, the typed value will be the same as the string value, either as an instance of xs:string or as an instance of xs:untypedAtomic, depending on the node kind.
For an atomic value, this method returns an iterator over a singleton sequence containing the atomic value itself.
- Returns:
- an iterator over the items in the typed value of the node or atomic value. The items returned by this iterator will always be atomic values.
- Throws:
XPathException
- where no typed value is available, for example in the case of an element with complex content- Since:
- 8.4
-
deepEquals
public boolean deepEquals(FunctionItem other, XPathContext context, AtomicComparer comparer, int flags) throws XPathException Test whether this FunctionItem is deep-equal to another function item, under the rules of the deep-equal function- Specified by:
deepEquals
in interfaceFunctionItem
- Parameters:
other
- the other function itemcontext
- the dynamic evaluation contextcomparer
- the object to perform the comparisonflags
- options for how the comparison is performed- Returns:
- true if the two function items are deep-equal
- Throws:
XPathException
- if the comparison cannot be performed
-
deepEqual40
public boolean deepEqual40(FunctionItem other, XPathContext context, DeepEqual.DeepEqualOptions options) throws XPathException - Specified by:
deepEqual40
in interfaceFunctionItem
- Throws:
XPathException
-
itemAt
Description copied from interface:Item
Get the n'th item in the value, counting from 0- Specified by:
itemAt
in interfaceGroundedValue
- Specified by:
itemAt
in interfaceItem
- Parameters:
n
- the index of the required item, with 0 representing the first item in the sequence- Returns:
- the n'th item if it exists, or null otherwise
-
effectiveBooleanValue
Description copied from interface:GroundedValue
Get the effective boolean value of this sequence- Specified by:
effectiveBooleanValue
in interfaceGroundedValue
- Returns:
- the effective boolean value
- Throws:
XPathException
- if the sequence has no effective boolean value (for example a sequence of two integers)
-
mapToString
Returns a string representation of the map.- Parameters:
map
- the input map- Returns:
- a string representation of the input map (using syntax resembling that of an XPath 3.1 map constructor).
-
export
Export information about this function item to the export() or explain() output- Specified by:
export
in interfaceFunctionItem
- Parameters:
out
- the destination for the information- Throws:
XPathException
- if things go wrong
-
isTrustedResultType
public boolean isTrustedResultType()Description copied from interface:FunctionItem
Ask if the function can be trusted to return a result of the correct type- Specified by:
isTrustedResultType
in interfaceFunctionItem
- Returns:
- true if the implementation can be trusted
-