Interface StructureQueryConstraint.Sequence
- All Known Implementing Classes:
StructureQueryConstraint.BulkFilter,StructureQueryConstraint.EmptySequence,StructureQueryConstraint.SimpleFilter
- Enclosing interface:
- StructureQueryConstraint
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
FieldsModifier and TypeFieldDescriptionstatic final StructureQueryConstraint.SequenceA sequence that has no values. -
Method Summary
Modifier and TypeMethodDescriptionbooleanadvance(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).
-
Field Details
-
EMPTY
A sequence that has no values.
-
-
Method Details
-
advance
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 toacceptorthrough calls toacceptor.accept(index)oracceptor.accept(indices). Return value indicates whether this sequence is capable of producing values:falseindicates the end of this sequence.- Parameters:
acceptor- accepts members of this sequence- Returns:
- false iff this sequence does not have any more values
-