@FunctionalInterface public interface BooleanSignalSource extends AbstractSignalSource, BooleanSupplier
boolean
.
This basic interface is neutral with respect to whether values may change at arbitrary times or synchronously with respect to a clock, and to whether values are computed on the fly when demanded, or stored when available and then just retrieved.
BooleanClockedSignalSource
Modifier and Type | Method and Description |
---|---|
default BooleanSignalSource |
and(BooleanSignalSource other)
Returns a new signal source whose value is the conjunction of
the simultaneous values of this and another signal source.
|
default BooleanClockedSignalSource |
becoming(boolean initial)
Returns a new clocked signal source whose value, at any clock
index, is
true iff the value of this signal source is
becoming true at that clock index. |
default BooleanClockedSignalSource |
ceasing(boolean initial)
Returns a new clocked signal source whose value, at any clock
index, is
true iff the value of this signal source is
ceasing to be true at that clock index. |
default BooleanSignalSource |
choose(BooleanSignalSource inTrue,
BooleanSignalSource inFalse)
Returns a new signal source whose value is that of either of two
given type-compatible signal sources, depending on the current
value of this signal source.
|
static BooleanSignalSource |
choose(BooleanSignalSource condition,
BooleanSignalSource inTrue,
BooleanSignalSource inFalse)
Returns a new signal source whose value is that of either of two
given type-compatible signal sources, depending on the current
value of a condition signal source.
|
default DoubleSignalSource |
choose(DoubleSignalSource inTrue,
DoubleSignalSource inFalse)
Returns a new signal source whose value is that of either of two
given type-compatible signal sources, depending on the current
value of this signal source.
|
static <E extends Enum<E>> |
choose(EnumSignalSource<E> selector,
BooleanSignalSource... cases)
Returns a new signal source whose value is selected dynamically from a
range of cases indexed by
enum values. |
static <E extends Enum<E>> |
choose(EnumSignalSource<E> selector,
EnumMap<E,? extends BooleanSignalSource> cases)
Returns a new signal source whose value is selected dynamically from a
range of cases indexed by
enum values. |
default <E extends Enum<E>> |
choose(EnumSignalSource<E> inTrue,
EnumSignalSource<E> inFalse)
Returns a new signal source whose value is that of either of two
given type-compatible signal sources, depending on the current
value of this signal source.
|
default FloatSignalSource |
choose(FloatSignalSource inTrue,
FloatSignalSource inFalse)
Returns a new signal source whose value is that of either of two
given type-compatible signal sources, depending on the current
value of this signal source.
|
default IntSignalSource |
choose(IntSignalSource inTrue,
IntSignalSource inFalse)
Returns a new signal source whose value is that of either of two
given type-compatible signal sources, depending on the current
value of this signal source.
|
default LongSignalSource |
choose(LongSignalSource inTrue,
LongSignalSource inFalse)
Returns a new signal source whose value is that of either of two
given type-compatible signal sources, depending on the current
value of this signal source.
|
default <A> SignalSource<A> |
choose(SignalSource<A> inTrue,
SignalSource<A> inFalse)
Returns a new signal source whose value is that of either of two
given type-compatible signal sources, depending on the current
value of this signal source.
|
static <E extends Enum<E>> |
choose(SignalSource<E> selector,
EnumMap<E,? extends BooleanSignalSource> cases)
Returns a new signal source whose value is selected dynamically from a
range of cases indexed by
enum values. |
static BooleanClockedSignalSource |
clock(BooleanSignalSource output,
Process... processes) |
default Consumer<CompilationContext> |
compileDataFlow()
Returns a code generator for outputting the value of this entity.
|
default void |
compileMainSignalSource(CompilationContext context) |
static BooleanSignalSource |
constant(boolean value)
Returns a signal source whose value is constant (never changes).
|
default BooleanClockedSignalSource |
delayed(boolean... initialValues)
Returns a new signal source that mirror the values of this signal source
delayed by a given number of clock ticks.
|
default BooleanClockedSignalSource |
delayed(boolean initialValue)
Returns a new signal source that mirrors the values of this
signal source delayed by one clock tick.
|
static BooleanClockedSignalSource |
delayedFeedback(Function<? super BooleanClockedSignalSource,? extends BooleanSignalSource> loop,
boolean... initialValues) |
static BooleanClockedSignalSource |
delayedFeedback(Function<? super BooleanClockedSignalSource,? extends BooleanSignalSource> loop,
boolean initialValue)
Returns a new signal source that receives its own delayed output as input.
|
boolean |
getAsBoolean()
Returns the current value of this signal source.
|
default Optional<Boolean> |
getConstantAsBoolean()
Returns the constant value of this signal source, if applicable.
|
default Class<?> |
getValueClass()
Returns the type of values produced by this entity.
|
default BooleanSignalSource |
guard(BooleanPredicate pred)
Returns a boolean signal source whose values are derived from the values
of this signal source by applying a unary predicate.
|
default boolean |
hasConstantAsBoolean()
Checks whether this signal source has a constant value.
|
default BooleanClockedSignalSource |
invariant() |
default BooleanSignalSource |
map(BooleanUnaryOperator op)
Returns a signal source whose values are derived from the values of this
signal source by applying a unary function.
|
default BooleanSignalSource |
not()
Returns a new signal source whose value is the negation of the value of
this signal source.
|
default BooleanSignalSource |
or(BooleanSignalSource other)
Returns a new signal source whose value is the disjunction of
the simultaneous values of this and another signal source.
|
default BooleanClockedSignalSource |
power(BinaryOperator<BooleanSignalSource> op,
long n) |
default Process |
probe(Object key)
Returns a realtime event that, when fired, notifies the concerned observer
of the current value of this signal source.
|
default void |
publishStoredValueVariable(CompilationContext context) |
default BooleanSignalSource |
relateWith(BooleanBiPredicate pred,
BooleanSignalSource other)
Returns a boolean signal source whose values are derived from the
simultaneous values of this and another signal source by applying a binary
predicate.
|
default BooleanClockedSignalSource |
sampleAndHold(BooleanSignalSource hold,
boolean initialValue)
Returns a new clocked signal source whose value at each clock tick is
either the current value of this signal source (sample mode), or
its own value at the previous clock tick (hold mode), depending on
the current value of a given boolean signal source.
|
default BooleanClockedSignalSource |
stored()
Returns a new signal source that stores snapshot values of this signal
source driven by a clock.
|
default BooleanSignalSource |
xor(BooleanSignalSource other)
Returns a new signal source whose value is the difference of
the simultaneous values of this and another signal source.
|
default BooleanSignalSource |
zipWith(BooleanBinaryOperator op,
BooleanSignalSource other)
Returns a signal source whose values are derived from the simultaneous
values of this and another signal source by applying a binary function.
|
compileDataFlowTo, hasDataFlowIO
boolean getAsBoolean()
The value may be either computed on demand, or retrieved from storage.
Implementations of this method should have no side effect.
getAsBoolean
in interface BooleanSupplier
default Class<?> getValueClass()
For signals of primitive value type, the result will be the corresponding pseudoclass.
This implementation returns the primitive pseudoclass boolean.class
.
getValueClass
in interface CompilableDataFlow
Class.isPrimitive()
default Optional<Boolean> getConstantAsBoolean()
Optional
containing the value of this signal
source if it is constant, or Optional.empty()
otherwise.default boolean hasConstantAsBoolean()
true
iff the value of this signal source does not change
over timedefault Consumer<CompilationContext> compileDataFlow()
This implementation generates code to invoke this.getAsBoolean()
.
compileDataFlow
in interface CompilableDataFlow
static BooleanSignalSource constant(boolean value)
value
- the value of the new signal sourcedefault BooleanSignalSource map(BooleanUnaryOperator op)
The implementation yields a signal source that computes the derived
value by applying the given function every time its getAsBoolean()
method is invoked. If the computation is costly and the
value reused often, it may be convenient to compute and store the value
proactively driven by a clock.
op
- the function to apply to each valuestored()
default BooleanSignalSource zipWith(BooleanBinaryOperator op, BooleanSignalSource other)
The implementation yields a signal source that computes the derived
value by applying the given function every time its getAsBoolean()
method is invoked. If the computation is costly and the
value reused often, it may be convenient to compute the value proactively
driven by a clock.
op
- the function to apply to each pair of valuesother
- the other signal source to considerstored()
default BooleanSignalSource guard(BooleanPredicate pred)
The implementation yields a signal source that computes the derived
value by applying the given predicate every time its getAsBoolean()
method is invoked. If the computation is costly and the
value reused often, it may be convenient to compute the value proactively
driven by a clock.
pred
- the predicate to apply to each valuestored()
default BooleanSignalSource relateWith(BooleanBiPredicate pred, BooleanSignalSource other)
The implementation yields a signal source that computes the derived
value by applying the given predicate every time its getAsBoolean()
method is invoked. If the computation is costly and the
value reused often, it may be convenient to compute the value proactively
driven by a clock.
pred
- the predicate to apply to each valueother
- the other signal source to considerstored()
@Undocumented static BooleanClockedSignalSource clock(BooleanSignalSource output, Process... processes)
@Undocumented default BooleanClockedSignalSource invariant()
default BooleanClockedSignalSource stored()
The getAsBoolean()
method of the returned signal
source is guaranteed to be extremely fast, both in interpreted
and compiled mode. The computational effort of the underlying
signal source is instead spent on the Process.step(RealtimeContext)
method of the
returned signal source, to be invoked at each clock tick.
If the underlying signal source is constant, the value is
forwarded when the Process.init()
method of the returned signal source is invoked, where as its
implementation of Process.step(RealtimeContext)
does nothing.
default BooleanClockedSignalSource delayed(boolean initialValue)
initialValue
- the initial value to output for the first clock tickdefault BooleanClockedSignalSource delayed(boolean... initialValues)
The length of the delay in clock ticks is specified implicitly by the number of initial values.
initialValues
- the initial values to output for the first clock ticksstatic BooleanClockedSignalSource delayedFeedback(Function<? super BooleanClockedSignalSource,? extends BooleanSignalSource> loop, boolean initialValue)
The circular data flow is constructed by specifying a function that receives as its argument a delayed signal source that will be fed back from the source that it returns. The passed function is applied exactly once.
The output signal source is used both internally for the delayed feedback, and possibly externally by a consumer. Hence its value is stored implicitly in an intermediate variable in order to avoid duplicate computations.
loop
- the function that creates the output signal source, given its delayed feedbackinitialValue
- the initial value of the delayed feedback@SafeVarargs static BooleanClockedSignalSource delayedFeedback(Function<? super BooleanClockedSignalSource,? extends BooleanSignalSource> loop, boolean... initialValues)
default Process probe(Object key)
key
- the key to associate the value of this signal source withRealtimeContext.getSignalProbe()
default BooleanSignalSource not()
At any point in time, this.negate().getAsBoolean() ==
!this.getAsBoolean()
holds.
default BooleanSignalSource or(BooleanSignalSource other)
At any point in time, this.add(other).getAsBoolean() ==
this.getAsBoolean() | other.getAsBoolean()
holds.
other
- the other signal source to considerdefault BooleanSignalSource and(BooleanSignalSource other)
At any point in time, this.add(other).getAsBoolean() ==
this.getAsBoolean() & other.getAsBoolean()
holds.
other
- the other signal source to considerdefault BooleanSignalSource xor(BooleanSignalSource other)
At any point in time, this.add(other).getAsBoolean() ==
this.getAsBoolean() ^ other.getAsBoolean()
holds.
other
- the other signal source to considerdefault BooleanClockedSignalSource becoming(boolean initial)
true
iff the value of this signal source is
becoming true
at that clock index. That is, if the pair
of values of this signal source at the previous and the current
clock index are false, true
, respectively. The virtual
initial value before the first clock index is specified
separately.initial
- the virtual initial value; if false
then
the output can become true
at the first clock tickdefault BooleanClockedSignalSource ceasing(boolean initial)
true
iff the value of this signal source is
ceasing to be true
at that clock index. That is, if the
pair of values of this signal source at the previous and the
current clock index are true, false
, respectively. The virtual
initial value before the first clock index is specified
separately.initial
- the virtual initial value; if true
then
the output can become true
at the first clock tickdefault <A> SignalSource<A> choose(SignalSource<A> inTrue, SignalSource<A> inFalse)
At any point in time, this.choose(x, y).get() ==
(this.getAsBoolean() ? x : y).get()
holds.
inTrue
- the signal source to consider when the value of
this signal source is true
inFalse
- the signal source to consider when the value of
this signal source is false
default FloatSignalSource choose(FloatSignalSource inTrue, FloatSignalSource inFalse)
At any point in time, this.choose(x, y).getAsFloat() ==
(this.getAsBoolean() ? x : y).getAsFloat()
holds.
inTrue
- the signal source to consider when the value of
this signal source is true
inFalse
- the signal source to consider when the value of
this signal source is false
default DoubleSignalSource choose(DoubleSignalSource inTrue, DoubleSignalSource inFalse)
At any point in time, this.choose(x, y).getAsDouble() ==
(this.getAsBoolean() ? x : y).getAsDouble()
holds.
inTrue
- the signal source to consider when the value of
this signal source is true
inFalse
- the signal source to consider when the value of
this signal source is false
default IntSignalSource choose(IntSignalSource inTrue, IntSignalSource inFalse)
At any point in time, this.choose(x, y).getAsInt() ==
(this.getAsBoolean() ? x : y).getAsInt()
holds.
inTrue
- the signal source to consider when the value of
this signal source is true
inFalse
- the signal source to consider when the value of
this signal source is false
default BooleanSignalSource choose(BooleanSignalSource inTrue, BooleanSignalSource inFalse)
At any point in time, this.choose(x, y).getAsBoolean() ==
(this.getAsBoolean() ? x : y).getAsBoolean()
holds.
inTrue
- the signal source to consider when the value of
this signal source is true
inFalse
- the signal source to consider when the value of
this signal source is false
default LongSignalSource choose(LongSignalSource inTrue, LongSignalSource inFalse)
At any point in time, this.choose(x, y).getAsLong() ==
(this.getAsBoolean() ? x : y).getAsLong()
holds.
inTrue
- the signal source to consider when the value of
this signal source is true
inFalse
- the signal source to consider when the value of
this signal source is false
default <E extends Enum<E>> EnumSignalSource<E> choose(EnumSignalSource<E> inTrue, EnumSignalSource<E> inFalse)
At any point in time, this.choose(x, y).getAsInt() ==
(this.getAsBoolean() ? x : y).getAsInt()
holds.
inTrue
- the signal source to consider when the value of
this signal source is true
inFalse
- the signal source to consider when the value of
this signal source is false
static BooleanSignalSource choose(BooleanSignalSource condition, BooleanSignalSource inTrue, BooleanSignalSource inFalse)
At any point in time, choose(condition, x, y).getAsInt() ==
(this.getAsBoolean() ? x : y).getAsInt()
holds.
condition
- the condition signal sourceinTrue
- the signal source to consider when the value of
the condition signal source is true
inFalse
- the signal source to consider when the value of
the condition signal source is false
static <E extends Enum<E>> BooleanSignalSource choose(SignalSource<E> selector, EnumMap<E,? extends BooleanSignalSource> cases)
enum
values.
At any point in time, choose(s, m).getAsBoolean() ==
m.get(s.get()).getAsBoolean()
holds.
The given map cases
is assumed to be immutable and to contain an
entry for every possible value of the enum
type E
.
E
- the type of enum
valuesselector
- the signal source that provides the enum
valuecases
- a map of enum
values to signal sources to select fromstatic <E extends Enum<E>> BooleanSignalSource choose(EnumSignalSource<E> selector, EnumMap<E,? extends BooleanSignalSource> cases)
enum
values.
At any point in time, choose(s, m).getAsBoolean() ==
m.get(E.values()[s.getAsInt()]).getAsBoolean()
holds.
The given map cases
is assumed to be immutable and to contain an
entry for every possible value of the enum
type E
.
E
- the type of enum
valuesselector
- the signal source that provides the ordinal number of the
enum
valuecases
- a map of enum
values to signal sources to select from@SafeVarargs static <E extends Enum<E>> BooleanSignalSource choose(EnumSignalSource<E> selector, BooleanSignalSource... cases)
enum
values.
At any point in time, choose(s, a).getAsBoolean() ==
m[s.getAsInt()].getAsBoolean()
holds.
The given array cases
is assumed to be immutable and to contain
an element for every possible value of the enum
type E
.
E
- the type of enum
valuesselector
- the signal source that provides the enum
valuecases
- an array signal sources to select from, in the definition
order of enum
elementsdefault BooleanClockedSignalSource sampleAndHold(BooleanSignalSource hold, boolean initialValue)
hold
- a boolean signal source that, at each clock tick, selects hold
mode if its value ist true
, or sample mode if its value is false
initialValue
- the initial value to use if in hold mode at the first
clock tick@Undocumented default BooleanClockedSignalSource power(BinaryOperator<BooleanSignalSource> op, long n)
@Undocumented default void compileMainSignalSource(CompilationContext context)
@Undocumented default void publishStoredValueVariable(CompilationContext context)