Package net.sf.saxon.ma.map
Class MapItem
- java.lang.Object
-
- net.sf.saxon.ma.map.MapItem
-
- All Implemented Interfaces:
Callable
,Function
,GroundedValue
,Item
,Sequence
- Direct Known Subclasses:
DelegatingMapItem
,DictionaryMap
,HashTrieMap
,RangeKey
,SingleEntryMap
public abstract class MapItem extends java.lang.Object implements Function
Interface supported by different implementations of an XDM map item
-
-
Constructor Summary
Constructors Constructor Description MapItem()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract 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.AtomicSequence
atomize()
Atomize the item.Sequence
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
deepEquals(Function 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
effectiveBooleanValue()
Get the effective boolean value of this sequencevoid
export(ExpressionPresenter out)
Export information about this function item to the export() or explain() outputabstract GroundedValue
get(AtomicValue key)
Get an entry from the MapAnnotationList
getAnnotations()
Get the function annotations (as defined in XQuery).int
getArity()
Get the arity of the functionjava.lang.String
getDescription()
Get a description of this function for use in error messages.FunctionItemType
getFunctionItemType()
Get the item type of this item as a function item.StructuredQName
getFunctionName()
Get the name of the function, or null if it is anonymousGenre
getGenre()
Get the genre of this itemabstract ItemType
getItemType(TypeHierarchy th)
Get the type of the map.static ItemType
getItemTypeOfSequence(Sequence val)
Get an item type to which all the values in a sequence are known to conformabstract UType
getKeyUType()
Get the lowest common item type of the keys in the mapOperandRole[]
getOperandRoles()
Get the roles of the arguments, for the purposes of streaminglong
getSerialNumber()
Allocate a unique serial number.SequenceIterator
getTypedValue()
Get the typed value of the item.UnicodeString
getUnicodeStringValue()
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
isTrustedResultType()
Ask if the function can be trusted to return a result of the correct typeMapItem
itemAt(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 java.lang.Iterable<KeyValuePair>
keyValuePairs()
Get the set of all key-value pairs in the mapXPathContext
makeNewContext(XPathContext callingContext, ContextOriginator originator)
Prepare an XPathContext object for evaluating the functionstatic java.lang.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 mapjava.lang.String
toShortString()
Provide a short string showing the contents of the item, suitable for use in error messages-
Methods 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.Function
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
-
-
-
-
Method Detail
-
getSerialNumber
public long getSerialNumber()
Description copied from interface:Function
Allocate a unique serial number.Introduced on the 11.x branch for bug #5887, so that function items, arrays, and maps can be used as keys for memo functions. This is not needed for 12.x, which uses a different design.
- Specified by:
getSerialNumber
in interfaceFunction
-
get
public abstract GroundedValue get(AtomicValue key)
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
public abstract AtomicIterator 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
public abstract java.lang.Iterable<KeyValuePair> keyValuePairs()
Get the set of all key-value pairs in the map- Returns:
- an iterable containing all the key-value pairs
-
addEntry
public abstract 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. 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
public abstract MapItem remove(AtomicValue key)
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
public abstract boolean conforms(PlainType keyType, SequenceType valueType, TypeHierarchy th)
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
public abstract ItemType getItemType(TypeHierarchy th)
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
public abstract UType 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
public java.lang.String toShortString()
Provide a short string showing the contents of the item, suitable for use in error messages- Specified by:
toShortString
in interfaceFunction
- Specified by:
toShortString
in interfaceGroundedValue
- Specified by:
toShortString
in interfaceItem
- Returns:
- a depiction of the item suitable for use in error messages
-
getGenre
public Genre getGenre()
Get the genre of this item
-
isArray
public boolean isArray()
Ask whether this function item is an array
-
isMap
public boolean isMap()
Ask whether this function item is a map
-
getAnnotations
public AnnotationList getAnnotations()
Get the function annotations (as defined in XQuery). Returns an empty list if there are no function annotations.- Specified by:
getAnnotations
in interfaceFunction
- Returns:
- the function annotations
-
atomize
public AtomicSequence atomize() throws XPathException
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
public static boolean isKnownToConform(Sequence value, ItemType itemType)
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
public static ItemType getItemTypeOfSequence(Sequence val)
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
public OperandRole[] getOperandRoles()
Get the roles of the arguments, for the purposes of streaming- Specified by:
getOperandRoles
in interfaceFunction
- Returns:
- an array of OperandRole objects, one for each argument
-
getFunctionItemType
public FunctionItemType 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 interfaceFunction
- Returns:
- the function item's type
-
getFunctionName
public StructuredQName getFunctionName()
Get the name of the function, or null if it is anonymous- Specified by:
getFunctionName
in interfaceFunction
- Returns:
- the function name, or null for an anonymous inline function
-
getDescription
public java.lang.String 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 interfaceFunction
- Returns:
- a description of the function for use in error messages
-
getArity
public int getArity()
Get the arity of the function
-
makeNewContext
public XPathContext makeNewContext(XPathContext callingContext, ContextOriginator originator)
Prepare an XPathContext object for evaluating the function- Specified by:
makeNewContext
in interfaceFunction
- 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
public Sequence call(XPathContext context, Sequence[] args) throws XPathException
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
public UnicodeString 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:
java.lang.UnsupportedOperationException
- 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
public SequenceIterator getTypedValue() throws XPathException
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(Function 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 interfaceFunction
- 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
-
itemAt
public MapItem itemAt(int n)
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
public boolean effectiveBooleanValue() throws XPathException
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
public static java.lang.String mapToString(MapItem map)
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
public void export(ExpressionPresenter out) throws XPathException
Export information about this function item to the export() or explain() output- Specified by:
export
in interfaceFunction
- Parameters:
out
- the destination for the information- Throws:
XPathException
- if things go wrong
-
isTrustedResultType
public boolean isTrustedResultType()
Description copied from interface:Function
Ask if the function can be trusted to return a result of the correct type- Specified by:
isTrustedResultType
in interfaceFunction
- Returns:
- true if the implementation can be trusted
-
-