Interface Value<T>

Type Parameters:
T - the type of the wrapped value
All Superinterfaces:
Consumer<T>, EventObserver<T>, Supplier<T>, ValueObserver<T>
All Known Subinterfaces:
ComponentValue<T,C>, PropertyValue<T>, State, ValueSet<T>
All Known Implementing Classes:
AbstractComponentValue, AbstractTextComponentValue, AbstractValue

public interface Value<T> extends ValueObserver<T>, Consumer<T>
An observable wrapper for a value. A factory class for Value instances.
See Also:
  • Method Details

    • accept

      void accept(T value)
      Sets the value
      Specified by:
      accept in interface Consumer<T>
      Parameters:
      value - the value
      Throws:
      IllegalArgumentException - in case the given value is invalid
      See Also:
    • set

      boolean set(T value)
      Sets the value. Note that if the value is equal to the current value according to Objects.equals(java.lang.Object, java.lang.Object) the underlying value is still set, but no change event is triggered.
      Parameters:
      value - the value
      Returns:
      true if the underlying value changed
      Throws:
      IllegalArgumentException - in case the given value is invalid
      See Also:
    • observer

      ValueObserver<T> observer()
      Returns a ValueObserver notified each time this value changes.
      Returns:
      a ValueObserver for this value
    • link

      void link(Value<T> originalValue)
      Creates a bidirectional link between this and the given original value, so that changes in one are reflected in the other. Note that after a call to this method this value is the same as originalValue.
      Parameters:
      originalValue - the original value to link this value to
      Throws:
      IllegalStateException - in case the values are already linked
      IllegalArgumentException - in case the original value is not valid according to this values validators
    • unlink

      void unlink(Value<T> originalValue)
      Unlinks this value from the given original value
      Parameters:
      originalValue - the original value to unlink from this one
      Throws:
      IllegalStateException - in case the values are not linked
    • link

      void link(ValueObserver<T> originalValue)
      Creates a unidirectional link between this value and the given original value observer, so that changes in the original value are reflected in this one. Note that after a call to this method the value of this value is the same as the original value.
      Parameters:
      originalValue - the original value to link this value to
      Throws:
      IllegalArgumentException - in case the original value is not valid according to this values validators
    • unlink

      void unlink(ValueObserver<T> originalValue)
      Unlinks this value from the given original value observer
      Parameters:
      originalValue - the original value to unlink
    • addValidator

      boolean addValidator(Value.Validator<T> validator)
      Adds a validator to this Value. Adding the same validator again has no effect.
      Parameters:
      validator - the validator
      Returns:
      true if this value did not already contain the specified validator
      Throws:
      IllegalArgumentException - in case the current value is invalid according to the validator
    • removeValidator

      boolean removeValidator(Value.Validator<T> validator)
      Removes the given validator from this value
      Parameters:
      validator - the validator
      Returns:
      true if this value contained the specified validator
    • validate

      void validate(T value)
      Validate the given value using all validators
      Parameters:
      value - the value to validate
      Throws:
      IllegalArgumentException - in case the given value is invalid according to a validator
    • value

      static <T> Value<T> value()
      Creates a new Value instance, wrapping a null initial value, using Value.Notify.WHEN_CHANGED.
      Type Parameters:
      T - the value type
      Returns:
      a Value for the given type
    • value

      static <T> Value<T> value(Value.Notify notify)
      Creates a new Value instance, wrapping a null initial value
      Type Parameters:
      T - the value type
      Parameters:
      notify - specifies when this value notifies its listeners
      Returns:
      a Value for the given type
    • value

      static <T> Value<T> value(T initialValue)
      Creates a new Value instance, using Value.Notify.WHEN_CHANGED.
      Type Parameters:
      T - the value type
      Parameters:
      initialValue - the initial value
      Returns:
      a Value with given initial value
    • value

      static <T> Value<T> value(T initialValue, Value.Notify notify)
      Creates a new Value instance
      Type Parameters:
      T - the value type
      Parameters:
      initialValue - the initial value
      notify - specifies when this value notifies its listeners
      Returns:
      a Value with given initial value
    • value

      static <T> Value<T> value(T initialValue, T nullValue)
      Creates a new Value instance, using Value.Notify.WHEN_CHANGED.
      Type Parameters:
      T - the value type
      Parameters:
      initialValue - the initial value
      nullValue - the actual value to use when the value is set to null
      Returns:
      a Value with given initial value
      Throws:
      NullPointerException - in case nullValue is null
    • value

      static <T> Value<T> value(T initialValue, T nullValue, Value.Notify notify)
      Creates a new Value instance
      Type Parameters:
      T - the value type
      Parameters:
      initialValue - the initial value
      nullValue - the actual value to use when the value is set to null
      notify - specifies when this value notifies its listeners
      Returns:
      a Value with given initial value
      Throws:
      NullPointerException - in case nullValue is null