com.vaadin.signals.
Class NumberSignal
A signal containing a numeric value. The value is updated as a single atomic
change. In addition to the regular ValueSignal
operation, this class
also supports atomically incrementing the value.
-
Field Summary
Fields inherited from class com.vaadin.signals.Signal
ANYTHING_GOES
-
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates a new number signal with a zero value.
NumberSignal
(double initialValue) Creates a new number signal with the given value.
protected
NumberSignal
(SignalTree tree, Id id, Predicate<SignalCommand> validator) Creates a new number signal instance with the given id and validator for the given signal tree.
-
Method Summary
Modifier and TypeMethodDescriptionWraps this signal to not accept changes.
boolean
int
hashCode()
incrementBy
(double delta) Atomically increments the value of this signal by the given delta amount.
<C> Signal<C>
mapIntValue
(IntFunction<C> mapper) Creates a computed signal based on an integer mapper function that is passed the value of this signal.
toString()
value()
Gets the current value of this signal.
value
(int value) Sets the value of this signal as an integer.
int
Gets the value of this signal as an integer.
withValidator
(Predicate<SignalCommand> validator) Wraps this signal with a validator.
Methods inherited from class com.vaadin.signals.ValueSignal
asNode, extractValue, replace, update, usageChangeValue, value, verifyValue
Methods inherited from class com.vaadin.signals.Signal
clear, computed, createUsage, data, data, effect, fromJson, id, map, mergeValidators, nodeValue, peek, peekConfirmed, remove, runInTransaction, runInTransaction, runWithoutTransaction, runWithoutTransaction, submit, submit, submit, submitInsert, submitVoidOperation, toJson, tree, untracked, validator
-
Constructor Details
-
NumberSignal
public NumberSignal()Creates a new number signal with a zero value. The signal does not support clustering.
-
NumberSignal
public NumberSignal(double initialValue) Creates a new number signal with the given value. The signal does not support clustering.
Parameters:
initialValue
- the initial value -
NumberSignal
Creates a new number signal instance with the given id and validator for the given signal tree.
Parameters:
tree
- the signal tree that contains the value for this signal, notnull
id
- the id of the signal node within the signal tree, notnull
validator
- the validator to check operations submitted to this singal, notnull
-
-
Method Details
-
incrementBy
Atomically increments the value of this signal by the given delta amount. The value is decremented if the delta is negative. The result of the returned operation will be resolved with the update value at the time when this operation was confirmed.
Parameters:
delta
- the increment amountReturns:
an operation containing the eventual result
-
value
Description copied from class:
Signal
Gets the current value of this signal. The value is read in a way that takes the current transaction into account and in the case of clustering also changes that have been submitted to the cluster but not yet confirmed.
Reading the value in a regular (i.e.
Transaction.Type.STAGED
) transaction makes the transaction depend on the value so that the transaction fails in case the signal value is changed concurrently.Reading the value inside an
Signal.effect(Runnable)
orSignal.computed(Supplier)
callback sets up that effect or computed signal to depend on the signal. -
valueAsInt
public int valueAsInt()Gets the value of this signal as an integer. This method works in the same way was
value()
with regards to transactions and dependency tracking.Returns:
the signal value as an integer
-
value
Sets the value of this signal as an integer. This method works in the same way was the regular value setter with regards to transactions.
Parameters:
value
- the integer value to setReturns:
an operation containing the eventual result
-
withValidator
Wraps this signal with a validator. The validator is used to check all value changing commands issued through the new signal instance. If this signal has a validator, then the new signal will use both validators. Note that due to the way validators are retained by
ValueSignal.asNode()
, there's a possibility that the validator also receives commands that cannot be directly issued for a number signal.This signal will keep its current configuration and changes applied through this instance will be visible through the wrapped instance.
Overrides:
withValidator
in classValueSignal<Double>
Parameters:
validator
- the validator to use, notnull
Returns:
a new number signal that uses the validator, not
null
-
asReadonly
Wraps this signal to not accept changes.
This signal will keep its current configuration and changes applied through this instance will be visible through the wrapped instance.
Overrides:
asReadonly
in classValueSignal<Double>
Returns:
the new readonly number signal, not
null
-
mapIntValue
Creates a computed signal based on an integer mapper function that is passed the value of this signal. If the mapper function accesses other signal values, then the computed signal will also depend on those signals.
Type Parameters:
C
- the computed signal typeParameters:
mapper
- the integer mapper function to use, notnull
Returns:
the computed signal, not
null
-
equals
Overrides:
equals
in classValueSignal<Double>
-
hashCode
public int hashCode()Overrides:
hashCode
in classValueSignal<Double>
-
toString
Overrides:
toString
in classValueSignal<Double>
-