Class NodeSetExtent

All Implemented Interfaces:
Sortable, NodeList

public final class NodeSetExtent extends NodeSetValue implements Sortable, NodeList
A node-set value implemented extensionally. This class also implements the DOM NodeList interface - though this will only work if the nodes themselves implement the DOM Node interface (which is true of the two Saxon tree models, but not necessarily of all possible implementations).
  • Constructor Details

    • NodeSetExtent

      public NodeSetExtent(NodeOrderComparer comparer)
      Construct an empty node set
    • NodeSetExtent

      public NodeSetExtent(NodeInfo[] nodes, NodeOrderComparer comparer)
      Construct a node-set given the set of nodes as an array
      Parameters:
      nodes - An array whose elements must be NodeInfo objects
      comparer - Comparer used for sorting into document order
    • NodeSetExtent

      public NodeSetExtent(Vector nodes, NodeOrderComparer comparer)
      Construct a node-set given the set of nodes as a Vector
      Parameters:
      nodes - a Vector whose elements must be NodeInfo objects
      comparer - Comparer used for sorting into document order
    • NodeSetExtent

      public NodeSetExtent(NodeEnumeration enm, NodeOrderComparer comparer) throws XPathException
      Construct a node-set containing all the nodes in a NodeEnumeration.
      Parameters:
      enm - The supplied node enumeration. This must be positioned at the start, so that hasMoreElements() returns true if there are any nodes in the node-set, and nextElement() returns the first node.
      comparer - Comparer used for sorting into document order
      Throws:
      XPathException
  • Method Details

    • append

      public void append(NodeInfo node)
      Append a node to the node-set. This is used only when building indexes. The node-set must be sorted; the new node must follow the others in document order. The new node is not added if it is the same as the last node currently in the node-set.
    • simplify

      public Expression simplify()
      Simplify the expression
      Overrides:
      simplify in class Value
      Returns:
      the simplified expression
    • setSorted

      public void setSorted(boolean isSorted)
      Set a flag to indicate whether the nodes are sorted. Used when the creator of the node-set knows that they are already in document order.
      Specified by:
      setSorted in class NodeSetValue
      Parameters:
      isSorted - true if the caller wishes to assert that the nodes are in document order and do not need to be further sorted
    • isSorted

      public boolean isSorted()
      Test whether the value is known to be sorted
      Specified by:
      isSorted in class NodeSetValue
      Returns:
      true if the value is known to be sorted in document order, false if it is not known whether it is sorted.
    • asString

      public String asString()
      Convert to string value
      Specified by:
      asString in class NodeSetValue
      Returns:
      the value of the first node in the node-set if there is one, otherwise an empty string
    • asBoolean

      public boolean asBoolean() throws XPathException
      Evaluate as a boolean.
      Specified by:
      asBoolean in class NodeSetValue
      Returns:
      true if the node set is not empty
      Throws:
      XPathException
    • getCount

      public int getCount()
      Count the nodes in the node-set. Note this will sort the node set if necessary, to make sure there are no duplicates.
      Specified by:
      getCount in class NodeSetValue
    • sort

      public NodeSetValue sort()
      Sort the nodes into document order. This does nothing if the nodes are already known to be sorted; to force a sort, call setSorted(false)
      Specified by:
      sort in class NodeSetValue
      Returns:
      the same NodeSetValue, after sorting. (The reason for returning this is that it makes life easier for the XSL compiler).
    • getFirst

      public NodeInfo getFirst()
      Get the first node in the nodeset (in document order)
      Specified by:
      getFirst in class NodeSetValue
      Returns:
      the first node, or null if the nodeset is empty
    • selectFirst

      public NodeInfo selectFirst(Context context)
      Return the first node in the nodeset (in document order)
      Parameters:
      context - The context for the evaluation: not used
      Returns:
      the NodeInfo of the first node in document order, or null if the node-set is empty.
    • enumerate

      public NodeEnumeration enumerate()
      Return an enumeration of this nodeset value.
      Specified by:
      enumerate in class NodeSetValue
    • getLength

      public int getLength()
      return the number of nodes in the list (DOM method)
      Specified by:
      getLength in interface NodeList
    • item

      public Node item(int index)
      Return the n'th item in the list (DOM method)
      Specified by:
      item in interface NodeList
    • compare

      public int compare(int a, int b)
      Compare two nodes in document sequence (needed to implement the Sortable interface)
      Specified by:
      compare in interface Sortable
      Returns:
      invalid input: '<'0 if obj[a]invalid input: '<'obj[b], 0 if obj[a]=obj[b], >0 if obj[a]>obj[b]
    • swap

      public void swap(int a, int b)
      Swap two nodes (needed to implement the Sortable interface)
      Specified by:
      swap in interface Sortable