Class XdmArray

  • All Implemented Interfaces:
    java.lang.Iterable<XdmItem>

    public class XdmArray
    extends XdmFunctionItem
    An array in the XDM data model. An array is a list of zero or more members, each of which is an arbitrary XDM value. The array itself is an XDM item.

    An XdmArray is immutable.

    Since:
    9.8
    • Constructor Detail

      • XdmArray

        public XdmArray()
        Create an empty XdmArray
      • XdmArray

        public XdmArray​(ArrayItem array)
        Create an XdmArray that wraps a supplied ArrayItem
        Parameters:
        array - the ArrayItem to be encapsulated
      • XdmArray

        public XdmArray​(XdmValue[] members)
        Create an XdmArray supplying the members as an array of XdmValue objects
        Parameters:
        members - an array of XdmValue objects. Note that subsequent changes to the array will have no effect on the XdmValue.
      • XdmArray

        public XdmArray​(java.lang.Iterable<? extends XdmValue> members)
        Create an XdmArray supplying the members as a collection of XdmValue objects
        Parameters:
        members - a sequence of XdmValue objects. Note that if this is supplied as a list or similar collection, subsequent changes to the list/collection will have no effect on the XdmValue. Note that the argument can be a single XdmValue representing a sequence, in which case the constructed array will have one member for each item in the supplied sequence.
    • Method Detail

      • arrayLength

        public int arrayLength()
        Get the number of members in the array
        Returns:
        the number of members in the array. (Note that the XdmItem.size() method returns 1 (one), because an XDM array is an item.)
      • get

        public XdmValue get​(int n)
                     throws java.lang.IndexOutOfBoundsException
        Get the n'th member in the array, counting from zero.
        Parameters:
        n - the member that is required, counting the first member in the array as member zero
        Returns:
        the n'th member in the sequence making up the array, counting from zero
        Throws:
        java.lang.IndexOutOfBoundsException - if n is less than zero or greater than or equal to the number of members in the array
      • put

        public XdmArray put​(int n,
                            XdmValue value)
                     throws java.lang.IndexOutOfBoundsException
        Create a new array in which one member is replaced with a new value.
        Parameters:
        n - the position of the member that is to be replaced, counting the first member in the array as member zero
        value - the new value for this member
        Returns:
        a new array, the same length as the original, with one member replaced by a new value
        Throws:
        java.lang.IndexOutOfBoundsException - if n is less than zero or greater than or equal to the number of members in the array
      • addMember

        public XdmArray addMember​(XdmValue value)
        Append a new member to an array
        Parameters:
        value - the new member
        Returns:
        a new array, one item longer than the original
        Since:
        9.9. (See bug 3968: on first release of 9.9, the method was mistakenly named append).
      • concat

        public XdmArray concat​(XdmArray value)
        Concatenate another array
        Parameters:
        value - the other array
        Returns:
        a new array, containing the members of this array followed by the members of the other array
        Since:
        9.9
      • asList

        public java.util.List<XdmValue> asList()
        Get the members of the array in the form of a list.
        Returns:
        a list of the members of this array.
      • getUnderlyingValue

        public ArrayItem getUnderlyingValue()
        Get the underlying implementation object representing the value. This method allows access to lower-level Saxon functionality, including classes and methods that offer no guarantee of stability across releases.
        Overrides:
        getUnderlyingValue in class XdmItem
        Returns:
        the underlying implementation object representing the value
      • makeArray

        public static XdmArray makeArray​(java.lang.Object[] input)
                                  throws java.lang.IllegalArgumentException
        Make an XDM array from a Java array. Each member of the supplied array is converted to a single member in the result array using the method XdmValue.makeValue(Object)
        Parameters:
        input - the Java array
        Returns:
        the result of the conversion if successful
        Throws:
        java.lang.IllegalArgumentException - if conversion is not possible
      • makeArray

        public static XdmArray makeArray​(boolean[] input)
        Make an XdmArray whose members are xs:boolean values
        Parameters:
        input - the input array of booleans
        Returns:
        an XdmArray whose members are xs:boolean values corresponding one-to-one with the input
      • makeArray

        public static XdmArray makeArray​(long[] input)
        Make an XdmArray whose members are xs:long values
        Parameters:
        input - the input array of integers
        Returns:
        an XdmArray whose members are xs:integer values corresponding one-to-one with the input
      • makeArray

        public static XdmArray makeArray​(int[] input)
        Make an XdmArray whose members are xs:integer values
        Parameters:
        input - the input array of integers
        Returns:
        an XdmArray whose members are xs:integer values corresponding one-to-one with the input
      • makeArray

        public static XdmArray makeArray​(short[] input)
        Make an XdmArray whose members are xs:integer values
        Parameters:
        input - the input array of integers
        Returns:
        an XdmArray whose members are xs:integer values corresponding one-to-one with the input
      • makeArray

        public static XdmArray makeArray​(byte[] input)
        Make an XdmArray whose members are xs:integer values
        Parameters:
        input - the input array of integers
        Returns:
        an XdmArray whose members are xs:integer values corresponding one-to-one with the input