com.xml_project.morganaxdm
Class XdmSequence

java.lang.Object
  extended by com.xml_project.morganaxdm.XdmSequence
All Implemented Interfaces:
java.lang.Iterable<XdmItem>
Direct Known Subclasses:
EmptySequence, XdmItem

public class XdmSequence
extends java.lang.Object
implements java.lang.Iterable<XdmItem>

A sequence of items from XDM.


Constructor Summary
protected XdmSequence()
           
 
Method Summary
 AtomizingIterator atomize()
          Returns an AtomizingIterator which gives access to the atomized value of the elements in this sequence.
 XdmSequence concat(XdmSequence second)
          Creates a new sequence by concatenating this sequence with another.
 XdmItem first()
          Returns the first item of this XdmSequence or throws a RuntimeException if sequence is empty.
 XdmItem get(long nr)
          Returns the n-th element of the sequence, counting by 1.
 java.lang.String getStringValue()
          Return the string value of this sequence.
 boolean hasCommonType()
          Checks whether all elements have a common type such as xs:integer or node().
 boolean hasValues()
          Checks whether the sequences contains XdmValues as opposed to nodes.
 boolean isEmpty()
          Checks whether the sequence is empty.
 XdmItemIterator iterator()
          Returns an iterator over this XdmSequence.
 XdmSequence normalize(java.lang.String itemSeparator)
          Returns a normalized sequence as defined in https://www.w3.org/TR/xslt-xquery-serialization-30/#serdm
 java.lang.String serialize()
           
 java.lang.String serialize(Map options)
           
 java.lang.String serialize(com.xml_project.morganaxpath.nodes.serializer.SerializerOptions options)
           
 long size()
          Returns the number of elements in this sequence.
 XdmSequence subSequence(long first, java.lang.Double length)
          Creates a new sequence which contains the element (first..length) of this sequence.
static XdmSequence wrap(Sequence items)
          Wraps the given Sequence into a new (simplified version) XdmSequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XdmSequence

protected XdmSequence()
Method Detail

wrap

public static final XdmSequence wrap(Sequence items)
Wraps the given Sequence into a new (simplified version) XdmSequence.

Parameters:
items - the sequence to wrap.
Returns:
an XdmSequence with the items, an XdmItem or EmptySequence.

iterator

public XdmItemIterator iterator()
Returns an iterator over this XdmSequence.

Specified by:
iterator in interface java.lang.Iterable<XdmItem>

first

public XdmItem first()
              throws java.lang.RuntimeException
Returns the first item of this XdmSequence or throws a RuntimeException if sequence is empty.

Returns:
the first item of this sequence.
Throws:
java.lang.RuntimeException - if the sequence is empty.

get

public XdmItem get(long nr)
            throws XPathException,
                   java.lang.RuntimeException
Returns the n-th element of the sequence, counting by 1. Invoking this method will convert the underlying sequence to a materialized sequence which will take time and cost memory. See also size().

Parameters:
nr - the number of the element, based by 1!
Returns:
the element on the given position.
Throws:
java.lang.RuntimeException - thrown, if nr < 1 or nr > size().
XPathException - thrown, if the underlying sequence is not convertible.

size

public long size()
          throws XPathException
Returns the number of elements in this sequence. Invoking this method will convert the underlying sequence to a materialized sequence which will take time and cost memory. See also get(n).

Returns:
the number of elements in this sequence.
Throws:
XPathException - thrown, if the underlying sequence is not convertible.

hasCommonType

public boolean hasCommonType()
Checks whether all elements have a common type such as xs:integer or node().

Returns:
true, if all elements in the sequence have a common type.

isEmpty

public boolean isEmpty()
Checks whether the sequence is empty.

Returns:
true, if the sequence is empty.

concat

public XdmSequence concat(XdmSequence second)
                   throws XPathException
Creates a new sequence by concatenating this sequence with another.

Parameters:
second - the sequence to concatenate.
Returns:
a new XdmSequence containing the elements of the two original sequences in the found order.
Throws:
XPathException - if the two XdmSequences cannot be concatenated, (i.e. not enough memory).

hasValues

public boolean hasValues()
Checks whether the sequences contains XdmValues as opposed to nodes.

Returns:
true, if there is at least one value.

atomize

public AtomizingIterator atomize()
                          throws XPathException
Returns an AtomizingIterator which gives access to the atomized value of the elements in this sequence.

Returns:
an AtomizingIterator.
Throws:
XPathException - thrown, if the sequence contains elements which cannot be atomized.

getStringValue

public java.lang.String getStringValue()
Return the string value of this sequence.

Returns:
the string value of this sequence.

subSequence

public XdmSequence subSequence(long first,
                               java.lang.Double length)
                        throws XPathException
Creates a new sequence which contains the element (first..length) of this sequence.

Parameters:
first - the first element (counting by 1) to include.
length - the number of elements to include.
Returns:
a new sequence as a subsequence of this sequence.
Throws:
XPathException - thrown the sequence cannot be created.

serialize

public java.lang.String serialize(Map options)
                           throws XPathException
Throws:
XPathException

serialize

public java.lang.String serialize()
                           throws XPathException
Throws:
XPathException

serialize

public java.lang.String serialize(com.xml_project.morganaxpath.nodes.serializer.SerializerOptions options)
                           throws XPathException
Throws:
XPathException

normalize

public XdmSequence normalize(java.lang.String itemSeparator)
                      throws XPathException
Returns a normalized sequence as defined in https://www.w3.org/TR/xslt-xquery-serialization-30/#serdm

Parameters:
itemSeparator -
Returns:
the normalized sequence
Throws:
XPathException