Class LevelData

java.lang.Object
org.osgi.service.dal.FunctionData
org.osgi.service.dal.functions.data.LevelData
All Implemented Interfaces:
Comparable<Object>

public class LevelData extends FunctionData
Function level data wrapper. It supports all properties defined in FunctionData.
See Also:
  • Field Details

  • Constructor Details

    • LevelData

      public LevelData(Map<String,?> fields)
      Constructs new LevelData instance with the specified field values. The map keys must match to the field names. The map values will be assigned to the appropriate class fields. For example, the maps can be: {"level"=BigDecimal(1)...}. That map will initialize the FIELD_LEVEL field with 1.
      • FIELD_LEVEL - mandatory field. The value type must be BigDecimal.
      • FIELD_UNIT - optional field. The value type must be String.
      Parameters:
      fields - Contains the new LevelData instance field values.
      Throws:
      ClassCastException - If the field value types are not expected.
      IllegalArgumentException - If the level is missing.
      NullPointerException - If the fields map is null.
    • LevelData

      public LevelData(long timestamp, Map<String,Object> metadata, BigDecimal level, String unit)
      Constructs new LevelData instance with the specified arguments.
      Parameters:
      timestamp - The data timestamp optional field.
      metadata - The data metadata optional field.
      level - The level value mandatory field.
      unit - The data unit optional field.
      Throws:
      NullPointerException - If level is null.
  • Method Details

    • getLevel

      public BigDecimal getLevel()
      Returns LevelData value. The value type is BigDecimal instead of double to guarantee value accuracy.
      Returns:
      The LevelData value.
    • getUnit

      public String getUnit()
      Returns LevelData unit as it's specified in PropertyMetadata.UNITS or null if the unit is missing.
      Returns:
      The value unit or null if the unit is missing.
    • equals

      public boolean equals(Object o)
      Two LevelData instances are equal if they contain equal metadata, timestamp, unit and level.
      Overrides:
      equals in class FunctionData
      Parameters:
      o - The object to compare this data.
      Returns:
      true if this object is equivalent to the specified one.
      See Also:
    • hashCode

      public int hashCode()
      Returns the hash code for this LevelData object. The hash code is a sum of FunctionData.hashCode(), String.hashCode() and BigDecimal.hashCode(), where String.hashCode() represents the unit hash code and BigDecimal.hashCode() represents the level hash code.
      Overrides:
      hashCode in class FunctionData
      Returns:
      The hash code of this LevelData object.
      See Also:
    • compareTo

      public int compareTo(Object o)
      Compares this LevelData instance with the given argument. If the argument is not LevelData, it throws ClassCastException. Otherwise, this method returns:
      • -1 if this instance field is less than a field of the specified argument.
      • 0 if all fields are equivalent.
      • 1 if this instance field is greater than a field of the specified argument.
      The fields are compared in this order: timestamp, metadata, level, unit.
      Specified by:
      compareTo in interface Comparable<Object>
      Overrides:
      compareTo in class FunctionData
      Parameters:
      o - LevelData to be compared.
      Returns:
      -1, 0 or 1 depending on the comparison rules.
      Throws:
      ClassCastException - If the method argument is not of type LevelData.
      See Also:
    • toString

      public String toString()
      Returns the string representation of this level data.
      Overrides:
      toString in class Object
      Returns:
      The string representation of this level data.