Class SharedNumberSignal
- All Implemented Interfaces:
Signal<Double>,Serializable
SharedValueSignal operation, this
class also supports atomically incrementing the value.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.signals.shared.AbstractSignal
AbstractSignal.ChildSignalFactory<I extends AbstractSignal<?>>, AbstractSignal.ResultConverter<T extends @Nullable Object> -
Field Summary
Fields inherited from class com.vaadin.flow.signals.shared.AbstractSignal
ANYTHING_GOES -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates a new number signal with a zero value.SharedNumberSignal(double initialValue) Creates a new number signal with the given value.protectedSharedNumberSignal(SignalTree tree, Id id, CommandValidator 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.booleanget()Gets the current value of this signal.intgetAsInt()Gets the value of this signal as an integer.inthashCode()incrementBy(double delta) Atomically increments the value of this signal by the given delta amount.<C> Signal<C> mapIntValue(SerializableIntFunction<C> mapper) Creates a computed signal based on an integer mapper function that is passed the value of this signal.peek()Reads the value without setting up any dependencies.Reads the confirmed value without setting up any dependencies.set(int value) Sets the value of this signal as an integer.toString()withValidator(CommandValidator validator) Wraps this signal with a validator.Methods inherited from class com.vaadin.flow.signals.shared.SharedValueSignal
asNode, extractValue, replace, set, update, updater, usageChangeValue, verifyValueMethods inherited from class com.vaadin.flow.signals.shared.AbstractSignal
clear, createUsage, data, data, fromJson, id, mergeValidators, nodeValue, remove, submit, submit, submit, submitInsert, submitVoidOperation, toJson, tree, validator
-
Constructor Details
-
SharedNumberSignal
public SharedNumberSignal()Creates a new number signal with a zero value. The signal does not support clustering. -
SharedNumberSignal
public SharedNumberSignal(double initialValue) Creates a new number signal with the given value. The signal does not support clustering.- Parameters:
initialValue- the initial value
-
-
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 amount- Returns:
- an operation containing the eventual result
-
get
Description copied from interface:SignalGets 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.If the signal implementation supports transactions, then 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.unboundEffect(EffectAction)orSignal.computed(SignalComputation)callback sets up that effect or computed signal to depend on the signal.This method must only be called within a reactive context such as an effect, a computed signal, an explicit
Signal.untracked(ValueSupplier)block, or atransaction. Calling it outside such a context throws anIllegalStateException. UseSignal.peek()for one-time reads that do not need dependency tracking. -
peek
Description copied from interface:SignalReads the value without setting up any dependencies. This method returns the same value asSignal.get()but without creating a dependency when used inside a transaction, effect or computed signal.Unlike
Signal.get(), this method can be called outside a reactive context and is the recommended way to read a signal value for one-time use, such as logging, assertions, or initializing non-reactive UI. -
peekConfirmed
Description copied from class:AbstractSignalReads the confirmed value without setting up any dependencies. The confirmed value doesn't consider changes in the current transaction or changes that have been submitted but not yet confirmed in a cluster.- Overrides:
peekConfirmedin classAbstractSignal<Double>- Returns:
- the confirmed signal value
-
getAsInt
public int getAsInt()Gets the value of this signal as an integer. This method works in the same way wasget()with regards to transactions and dependency tracking.- Returns:
- the signal value as an integer
-
set
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 set- Returns:
- 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 bySharedValueSignal.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:
withValidatorin classSharedValueSignal<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:
asReadonlyin classSharedValueSignal<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 type- Parameters:
mapper- the integer mapper function to use, notnull- Returns:
- the computed signal, not
null
-
equals
- Overrides:
equalsin classSharedValueSignal<Double>
-
hashCode
public int hashCode()- Overrides:
hashCodein classSharedValueSignal<Double>
-
toString
- Overrides:
toStringin classSharedValueSignal<Double>
-