Class Value<T>


  • public class Value<T>
    extends java.util.Observable
    A property value.

    This is used for communicating between the Thing representation and the actual physical thing implementation.

    Notifies all observers when the underlying value changes through an external update (command to turn the light off) or if the underlying sensor reports a new value.

    • Constructor Summary

      Constructors 
      Constructor Description
      Value​(T initialValue)
      Create a read only value that can only be updated by a Thing's reading.
      Value​(T initialValue, java.util.function.Consumer<T> valueForwarder)
      Create a writable value that can be set to a new value.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T get()
      Returns the last known value from the underlying thing.
      void notifyOfExternalUpdate​(T value)
      Called if the underlying thing reported a new value.
      void set​(T value)
      Set a new Value for this thing.
      • Methods inherited from class java.util.Observable

        addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Value

        public Value​(T initialValue)
        Create a read only value that can only be updated by a Thing's reading.

        Example: A sensor is updating its reading, but the reading cannot be set externally.

        Parameters:
        initialValue - The initial value
      • Value

        public Value​(T initialValue,
                     java.util.function.Consumer<T> valueForwarder)
        Create a writable value that can be set to a new value.

        Example: A light that can be switched off by setting this to false.

        Parameters:
        initialValue - The initial value
        valueForwarder - The method that updates the actual value on the thing
    • Method Detail

      • set

        public final void set​(T value)
        Set a new Value for this thing.

        Example: Switch a light off: set(false)

        Parameters:
        value - Value to set
      • get

        public final T get()
        Returns the last known value from the underlying thing.

        Example: Returns false, when a light is off.

        Returns:
        The value.
      • notifyOfExternalUpdate

        public final void notifyOfExternalUpdate​(T value)
        Called if the underlying thing reported a new value. This informs observers about the update.

        Example: A sensor reports a new value.

        Parameters:
        value - the newly reported value