Interface Value<T>

    • Method Detail

      • set

        void set​(T value)
        Sets the value
        Parameters:
        value - the 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:
        IllegalArgumentException - in case the values are already linked
      • 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:
        IllegalArgumentException - in case the values are not linked
      • link

        void link​(ValueObserver<T> originalValueObserver)
        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:
        originalValueObserver - the original value to link this value to
      • unlink

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

        Set<Value<T>> linkedValues()
        Returns:
        an unmodifiable set containing the values that have been linked to this value
      • addValidator

        void addValidator​(Value.Validator<T> validator)
        Adds a validator to this Value. Adding the same validator again has no effect.
        Parameters:
        validator - the validator
        Throws:
        IllegalArgumentException - in case the current value is invalid according to the validator
      • removeValidator

        void removeValidator​(Value.Validator<T> validator)
        Removes the given validator from this value
        Parameters:
        validator - the validator
      • value

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

        static <T> Value<T> value​(T initialValue)
        Creates a new Value instance
        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,
                                  T nullValue)
        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
        Returns:
        a Value with given initial value
        Throws:
        NullPointerException - in case nullValue is null
      • value

        static <T> Value<T> value​(Supplier<T> getter,
                                  Consumer<T> setter)
        Creates a new Value instance based on the given getter and setter. The setter may throw an unchecked exception in case of an invalid value.
        Type Parameters:
        T - the value type
        Parameters:
        getter - the getter
        setter - the setter
        Returns:
        a new Value instance based on the given setter and getter
        Throws:
        NullPointerException - in case either getter or setter is null
      • value

        static <T> Value<T> value​(Supplier<T> getter,
                                  Consumer<T> setter,
                                  T nullValue)
        Creates a Value based on the given getter and setter. The setter may throw an unchecked exception in case of an invalid value.
        Type Parameters:
        T - the value type
        Parameters:
        getter - the getter
        setter - the setter
        nullValue - the value to use instead of null
        Returns:
        a new Value instance based on the given setter and getter
        Throws:
        NullPointerException - in case either getter or setter is null
      • propertyValue

        static <T> Value<T> propertyValue​(Object owner,
                                          String propertyName,
                                          Class<T> valueClass,
                                          EventObserver<T> valueChangeObserver)
        Creates a new Value based on a class property
        Type Parameters:
        T - the value type
        Parameters:
        owner - the property owner
        propertyName - the name of the property
        valueClass - the value class
        valueChangeObserver - an observer notified each time the value changes
        Returns:
        a Value for the given property