Class MapItem

    • Constructor Detail

      • MapItem

        public MapItem()
    • Method Detail

      • 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
      • entries

        public SequenceIterator 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

        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 entry
        value - 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 keyType
        valueType - the required valueType
        th - 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 interface FunctionItem
        Specified by:
        toShortString in interface GroundedValue
        Specified by:
        toShortString in interface Item
        Returns:
        a depiction of the item suitable for use in error messages
      • getGenre

        public Genre getGenre()
        Get the genre of this item
        Specified by:
        getGenre in interface FunctionItem
        Specified by:
        getGenre in interface Item
        Returns:
        the genre: specifically, Map.
      • isArray

        public boolean isArray()
        Ask whether this function item is an array
        Specified by:
        isArray in interface FunctionItem
        Returns:
        false (it is not an array)
      • isMap

        public boolean isMap()
        Ask whether this function item is a map
        Specified by:
        isMap in interface FunctionItem
        Returns:
        true (it 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 interface FunctionItem
        Returns:
        the function annotations
      • 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 sequence
        itemType - 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 interface FunctionItem
        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 interface FunctionItem
        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 interface FunctionItem
        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 interface FunctionItem
        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 interface FunctionItem
        Returns:
        the number of arguments in the function signature
      • makeNewContext

        public XPathContext makeNewContext​(XPathContext callingContext,
                                           ContextOriginator originator)
        Prepare an XPathContext object for evaluating the function
        Specified by:
        makeNewContext in interface FunctionItem
        Parameters:
        callingContext - the XPathContext of the function calling expression
        originator - 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 interface Callable
        Parameters:
        context - the XPath dynamic evaluation context
        args - 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 interface GroundedValue
        Specified by:
        getUnicodeStringValue in interface Item
        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

        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​(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 interface FunctionItem
        Parameters:
        other - the other function item
        context - the dynamic evaluation context
        comparer - the object to perform the comparison
        flags - 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 interface GroundedValue
        Specified by:
        itemAt in interface Item
        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 interface GroundedValue
        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).
      • 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 interface FunctionItem
        Returns:
        true if the implementation can be trusted