Class LazySequence

java.lang.Object
net.sf.saxon.om.LazySequence
All Implemented Interfaces:
Sequence

public class LazySequence extends Object implements Sequence
A sequence that wraps an iterator, without being materialized. It can only be used once.
  • Constructor Details

    • LazySequence

      public LazySequence(SequenceIterator iterator)
      Create a virtual sequence backed by an iterator
      Parameters:
      iterator - the iterator that delivers the items in the sequence
  • Method Details

    • head

      public Item head() throws XPathException
      Get the first item in the sequence. This calls iterate() internally, which means it can only be called once; the method should only be used if the client requires only the first item in the sequence (or knows that the sequence has length one).
      Specified by:
      head in interface Sequence
      Returns:
      the first item, or null if the sequence is empty
      Throws:
      XPathException - if an error occurs evaluating the underlying expression
    • iterate

      public SequenceIterator iterate()
      Iterate over all the items in the sequence. The first time this is called it returns the original iterator backing the sequence. On subsequent calls it clones the original iterator.
      Specified by:
      iterate in interface Sequence
      Returns:
      an iterator over the items in the sequence
      Throws:
      UncheckedXPathException - if evaluation of the iterator fails.
      IllegalStateException - if iterate() has already been called
    • makeRepeatable

      public Sequence makeRepeatable() throws XPathException
      Description copied from interface: Sequence
      Ensure that the sequence is in a form where it can be evaluated more than once. Some sequences (for example LazySequence and Closure can only be evaluated once, and this operation causes these to be grounded. However, making it repeatable is not the same as making it grounded; it does not flush out all errors. Indeed, lazy evaluation relies on this property, because an expression that has been lifted out of a loop must not be evaluated unless the loop is executed at least once, to prevent spurious errors.
      Specified by:
      makeRepeatable in interface Sequence
      Returns:
      An equivalent sequence that can be repeatedly evaluated
      Throws:
      XPathException - if evaluation fails