Class LevelData
- java.lang.Object
-
- org.osgi.service.dal.FunctionData
-
- org.osgi.service.dal.functions.data.LevelData
-
- All Implemented Interfaces:
java.lang.Comparable<java.lang.Object>
public class LevelData extends FunctionData
Function level data wrapper. It supports all properties defined inFunctionData
.- See Also:
MultiLevelControl
,MultiLevelSensor
,Meter
,FunctionData
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
FIELD_LEVEL
Represents the level field name.static java.lang.String
FIELD_UNIT
Represents the unit field name.-
Fields inherited from class org.osgi.service.dal.FunctionData
DESCRIPTION, FIELD_METADATA, FIELD_TIMESTAMP
-
-
Constructor Summary
Constructors Constructor Description LevelData(long timestamp, java.util.Map<java.lang.String,java.lang.Object> metadata, java.math.BigDecimal level, java.lang.String unit)
Constructs newLevelData
instance with the specified arguments.LevelData(java.util.Map<java.lang.String,?> fields)
Constructs newLevelData
instance with the specified field values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(java.lang.Object o)
Compares thisLevelData
instance with the given argument.boolean
equals(java.lang.Object o)
TwoLevelData
instances are equal if they contain equal metadata, timestamp, unit and level.java.math.BigDecimal
getLevel()
ReturnsLevelData
value.java.lang.String
getUnit()
int
hashCode()
Returns the hash code for thisLevelData
object.java.lang.String
toString()
Returns the string representation of this level data.-
Methods inherited from class org.osgi.service.dal.FunctionData
getMetadata, getTimestamp
-
-
-
-
Field Detail
-
FIELD_LEVEL
public static final java.lang.String FIELD_LEVEL
Represents the level field name. The field value is available withgetLevel()
. The field type isBigDecimal
. The constant can be used as a key toLevelData(Map)
.- See Also:
- Constant Field Values
-
FIELD_UNIT
public static final java.lang.String FIELD_UNIT
Represents the unit field name. The field value is available withgetUnit()
. The field type isString
. The constant can be used as a key toLevelData(Map)
.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LevelData
public LevelData(java.util.Map<java.lang.String,?> fields)
Constructs newLevelData
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 theFIELD_LEVEL
field with 1.FIELD_LEVEL
- mandatory field. The value type must beBigDecimal
.FIELD_UNIT
- optional field. The value type must beString
.
- Parameters:
fields
- Contains the newLevelData
instance field values.- Throws:
java.lang.ClassCastException
- If the field value types are not expected.java.lang.IllegalArgumentException
- If the level is missing.java.lang.NullPointerException
- If the fields map isnull
.
-
LevelData
public LevelData(long timestamp, java.util.Map<java.lang.String,java.lang.Object> metadata, java.math.BigDecimal level, java.lang.String unit)
Constructs newLevelData
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:
java.lang.NullPointerException
- Iflevel
isnull
.
-
-
Method Detail
-
getLevel
public java.math.BigDecimal getLevel()
ReturnsLevelData
value. The value type isBigDecimal
instead ofdouble
to guarantee value accuracy.- Returns:
- The
LevelData
value.
-
getUnit
public java.lang.String getUnit()
- Returns:
- The value unit or
null
if the unit is missing.
-
equals
public boolean equals(java.lang.Object o)
TwoLevelData
instances are equal if they contain equal metadata, timestamp, unit and level.- Overrides:
equals
in classFunctionData
- Parameters:
o
- The object to compare this data.- Returns:
true
if this object is equivalent to the specified one.- See Also:
FunctionData.equals(java.lang.Object)
-
hashCode
public int hashCode()
Returns the hash code for thisLevelData
object. The hash code is a sum ofFunctionData.hashCode()
,String.hashCode()
andBigDecimal.hashCode()
, whereString.hashCode()
represents the unit hash code andBigDecimal.hashCode()
represents the level hash code.- Overrides:
hashCode
in classFunctionData
- Returns:
- The hash code of this
LevelData
object. - See Also:
FunctionData.hashCode()
-
compareTo
public int compareTo(java.lang.Object o)
Compares thisLevelData
instance with the given argument. If the argument is notLevelData
, it throwsClassCastException
. 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.
- Specified by:
compareTo
in interfacejava.lang.Comparable<java.lang.Object>
- Overrides:
compareTo
in classFunctionData
- Parameters:
o
-LevelData
to be compared.- Returns:
-1
,0
or1
depending on the comparison rules.- Throws:
java.lang.ClassCastException
- If the method argument is not of typeLevelData
.- See Also:
Comparable.compareTo(java.lang.Object)
-
toString
public java.lang.String toString()
Returns the string representation of this level data.- Overrides:
toString
in classjava.lang.Object
- Returns:
- The string representation of this level data.
-
-