Class XPathPatterns.NodeSet

All Implemented Interfaces:
Iterable<Node>, Collection<Node>, List<Node>, SequencedCollection<Node>
Enclosing class:
XPathPatterns

public static class XPathPatterns.NodeSet extends AbstractSequentialList<Node>
Lazy list of selected XML nodes.

Objects of this represent what is called node-sets in XPath 1.0. This is an unfortunate and misleading name, since the elements are always ordered, but in various context-dependent ways. It is thus technically and logically more correct to conceive of this class as a kind of list.

Null elements are not supported; a NullPointerException is thrown as early as possible.

  • Method Details

    • of

      public static XPathPatterns.NodeSet of(Iterable<? extends Node> elems)
      Returns a new node-set that contains the lazily given elements in order.

      The given elements are computed on demand, by means of an iterator on elems. No data are copied before this method returns. The exact time when each element is demanded is unpredictable. Hence the iteration should be invariant over time; otherwise behavior is unspecified.

      If lazy iteration produces a null element later during access to the constructed node-set, NullPointerException is thrown. In that case, the node-set should be considered invalidated and not accessed again.

      Parameters:
      elems - an object capable of producing elements by iteration
      Returns:
      a new node-set that contains elems in order
      Throws:
      NullPointerException - if elems is null
    • of

      public static XPathPatterns.NodeSet of(Node... elems)
      Returns a new node-set that contains the given elements in order.

      The given array is copied before this method returns. Subsequent changes to the array have no effect on the returned node-set.

      Parameters:
      elems - an array of elements
      Returns:
      a new node-set that contains elems in order
      Throws:
      NullPointerException - if elems is or contains null
    • of

      public static XPathPatterns.NodeSet of(List<? extends Node> elems)
      Returns a new node-set that contains the given elements in order.

      The given list is copied before this method returns. Subsequent changes to the list have no effect on the returned node-set.

      Parameters:
      elems - a list of elements
      Returns:
      a new node-set that contains elems in order
      Throws:
      NullPointerException - if elems is or contains null
    • size

      public int size()
      Returns the number of elements in this node-set.

      If this list is being populated lazily, a call to this method enforces completion.

      Specified by:
      size in interface Collection<Node>
      Specified by:
      size in interface List<Node>
      Specified by:
      size in class AbstractCollection<Node>
    • listIterator

      public ListIterator<Node> listIterator(int index)
      Returns a list iterator for this node-set.

      Node-sets are immutable; the returned iterator does not support the operations add, set and remove.

      The access operations next and previous do not tolerate null elements. If a null element is produced lazily on demand from such an access operation, a NullPointerException is thrown.

      Specified by:
      listIterator in interface List<Node>
      Specified by:
      listIterator in class AbstractSequentialList<Node>
      Parameters:
      index - the first element to be returned from the list iterator (by a call to next)
      Returns:
      an unmodifiable list iterator over the elements of this node-set, in order
    • filter

      Returns a node-set that contains only those element of this node-set that are selected by the given predicate, in order.

      The resulting node-set is computed lazily on demand.

      Parameters:
      pred - the predicate to filter this node-set with
      Returns:
      a node-set that contains only those element of this node-set that are selected by pred
      Throws:
      NullPointerException - if pred is null