@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
.
Modifier and Type | Field and Description |
---|---|
static StructureQueryConstraint.Sequence |
EMPTY
A sequence that has no values.
|
Modifier and Type | Method and Description |
---|---|
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).
|
static final StructureQueryConstraint.Sequence EMPTY
boolean advance(StructureQueryConstraint.Acceptor acceptor)
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.acceptor
- accepts members of this sequenceCopyright © 2024 Tempo Software. All Rights Reserved.