Interface StructureQueryConstraint.Sequence

All Known Implementing Classes:
StructureQueryConstraint.BulkFilter, StructureQueryConstraint.EmptySequence, StructureQueryConstraint.SimpleFilter
Enclosing interface:
StructureQueryConstraint

@PublicSpi public static interface StructureQueryConstraint.Sequence

Allows to implement a sequence of numbers in a generator-like fashion. Namely, object of this class represents a function that, when called, may produce 0, 1 or more results, or can indicate that it cannot produce any more results. Acceptor is the place where the results are placed. Callers of this function will construct an object of a class implementing Acceptor and then call this function. They might call it until it produces at least one value. Then they might use the produced values immediately and either stop the computation, or call the function again. It is recommended to produce values lazily. Ideally, the code would look like this:

   class MySequence implements Sequence {
     private IntIterator myInput;
     
     @Override public boolean advance(Acceptor acceptor) {
       if (!myInput.hasNext()) return false;
       if (matches(myInput.nextValue()) {
         acceptor.accept(myInput.value());
       }
       return true;
     }
   }
 

For convenience, we provide default implementations: StructureQueryConstraint.SimpleFilter does the same as the code sample above, so that you only have to define the matches() method. StructureQueryConstraint.BulkFilter accounts for cases where you need to process indices in bulk, such as compute attributes via StructureAttributeService.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    A sequence that has no values.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Attempts to advance in this sequence by 0, 1 or more positions (i.e., attempts to find the next 0, 1 or more matching indices).
  • Field Details

  • Method Details

    • advance

      boolean advance(StructureQueryConstraint.Acceptor acceptor)
      Attempts to advance in this sequence by 0, 1 or more positions (i.e., attempts to find the next 0, 1 or more matching indices). Each position should be passed to acceptor through calls to acceptor.accept(index) or acceptor.accept(indices). Return value indicates whether this sequence is capable of producing values: false indicates the end of this sequence.
      Parameters:
      acceptor - accepts members of this sequence
      Returns:
      false iff this sequence does not have any more values