Class Value<T>

java.lang.Object
io.openems.edge.common.channel.value.Value<T>
Type Parameters:
T - the type of the value

public class Value<T> extends Object
It is important to understand, that a Channel Value could be UNDEFINED (i.e. 'null') at any point in time - e.g. due to lost communication connection to a Device or Service, or because the system is just starting up and does not yet have any data. This class wraps a 'value' information for a Channel and provides convenience methods for retrieving it.

To get the actual value of a Channel using this object, typically one of the following methods will fit:

  • Field Details

    • UNDEFINED_VALUE_STRING

      public static final String UNDEFINED_VALUE_STRING
      The String for UNDEFINED, i.e. 'null' value channels.
      See Also:
  • Constructor Details

    • Value

      public Value(Channel<T> parent, T value)
  • Method Details

    • asString

      public String asString()
      Gets the value as a formatted String with its unit. (Same as toString())
      Returns:
      the value as formatted String
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • asStringWithoutUnit

      public String asStringWithoutUnit()
      Gets the value as a formatted String without its unit.
      Returns:
      formatted string without unit
    • get

      public T get()
      Gets the value or null.
      Returns:
      the value
    • getOrError

      public T getOrError() throws InvalidValueException
      Gets the value or throws an Exception on null.
      Returns:
      the value; never null
      Throws:
      InvalidValueException - if value is null
    • asOptional

      public Optional<T> asOptional()
      Gets the value as an Optional.
      Returns:
      the value as Optional
    • isDefined

      public boolean isDefined()
      Is the value defined?. This is an abbreviation for Value.asOptional().isPresent().
      Returns:
      true if the value is defined; false if it is UNDEFINED
    • ifPresent

      public void ifPresent(Consumer<? super T> action)
      If a value is present, performs the given action with the value, otherwise does nothing.
      Parameters:
      action - the action to be performed, if a value is present
      Throws:
      NullPointerException - if value is present and the given action is null
    • orElse

      public T orElse(T alternativeValue)
      Gets the value or the given alternativeValue. This is short for '.asOptional().or()'.
      Parameters:
      alternativeValue - the alternative value
      Returns:
      the value; or an alternative value if the value is null
    • asOptionString

      public String asOptionString()
      Gets the value as its String option. Enum options are converted to Strings.
      Returns:
      the String option of Enum values
      Throws:
      IllegalArgumentException - no matching option existing
    • asEnum

      public <O extends OptionsEnum> O asEnum()
      Gets the value as its Enum option.
      Type Parameters:
      O - the OptionsEnum type
      Returns:
      the Enum value
      Throws:
      IllegalArgumentException - no matching Enum option existing
    • asJson

      public com.google.gson.JsonElement asJson()
      Gets the value in GSON JSON format.
      Returns:
      the value as JsonElement
    • getTimestamp

      public LocalDateTime getTimestamp()
      Gets the timestamp when the value was created.
      Returns:
      the timestamp