Class DataObject
- java.lang.Object
-
- org.openmuc.jdlms.datatypes.DataObject
-
public class DataObject extends java.lang.Object
Container class holding data about to send to the smart meter or received by the smart meterEither stores a
Number
,List
ofDataObject
s, a byte array,BitString
or a subtypeCosemDateFormat
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DataObject.Type
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
getRawValue()
Returns the raw object-value.DataObject.Type
getType()
The type of the currentDataObject
.<T> T
getValue()
Returns the value.boolean
isBitString()
Is used to determine if the data contains aBitString
object.boolean
isBoolean()
Checks if the data of this container is a boolean.boolean
isByteArray()
Checks if the data of this container is a byte array.boolean
isComplex()
Checks if the data of this container is of a complex type.boolean
isCosemDateFormat()
Checks if the data of this container is aCosemDateFormat
object.boolean
isNull()
Checks if the data of this container isnull
.boolean
isNumber()
Checks if the data of this container is a numberstatic DataObject
newArrayData(java.util.List<DataObject> array)
Constructs a array data.static DataObject
newBcdData(byte bcd)
Constructs a 2 digit BCD number datastatic DataObject
newBitStringData(BitString bitString)
Constructs a bit string data.static DataObject
newBoolData(boolean bool)
Constructs a bool data.static DataObject
newCompactArrayData(CompactArray compactArray)
static DataObject
newDateData(CosemDate date)
Constructs a calendar datum holding a datestatic DataObject
newDateTimeData(CosemDateTime dateTime)
Constructs a calendar datum holding date and timestatic DataObject
newEnumerateData(int enumVal)
Constructs a enum data.static DataObject
newFloat32Data(float float32)
Constructs a 32 bit floating point number data.static DataObject
newFloat64Data(double float64)
Constructs a 64 bit floating point number data.static DataObject
newInteger16Data(short int16)
Constructs a int 16 datastatic DataObject
newInteger32Data(int int32)
Constructs a int 32 data.static DataObject
newInteger64Data(long int64)
Constructs a int 64 data.static DataObject
newInteger8Data(byte int8)
Constructs a int 8 datastatic DataObject
newNullData()
Constructs a empty datum.static DataObject
newOctetStringData(byte[] string)
Constructs a byte array data.static DataObject
newStructureData(java.util.List<DataObject> structure)
Constructs a structure data.static DataObject
newStructureData(DataObject... element)
Constructs a structure data.static DataObject
newTimeData(CosemTime time)
Constructs a calendar datum holding a timestatic DataObject
newUInteger16Data(int uInt16)
Constructs a unsigned int 16 data.static DataObject
newUInteger32Data(long uIn32)
Constructs a unsigned int 32 data.static DataObject
newUInteger64Data(long uInt64)
Constructs a unsigned int 64 datastatic DataObject
newUInteger8Data(short uInt8)
Constructs a unsigned int 8 datastatic DataObject
newUtf8StringData(byte[] string)
Constructs a UTF-8 string, encoded as byte array data.static DataObject
newVisibleStringData(byte[] string)
Constructs a string, encoded as byte array data.java.lang.String
toString()
Returns a string representation of theDataObject
.
-
-
-
Method Detail
-
newNullData
public static DataObject newNullData()
Constructs a empty datum.COSEM Type
DataObject.Type.NULL_DATA
- Returns:
- The data
-
newArrayData
public static DataObject newArrayData(java.util.List<DataObject> array)
Constructs a array data.COSEM Type
DataObject.Type.ARRAY
- Parameters:
array
- The array of values- Returns:
- The data
- Throws:
java.lang.IllegalArgumentException
- If a sub element of array has another data type than the first
-
newCompactArrayData
public static DataObject newCompactArrayData(CompactArray compactArray)
-
newStructureData
public static DataObject newStructureData(java.util.List<DataObject> structure)
Constructs a structure data.COSEM Type
DataObject.Type.STRUCTURE
- Parameters:
structure
- The structure of values- Returns:
- The data
- See Also:
newStructureData(DataObject...)
-
newStructureData
public static DataObject newStructureData(DataObject... element)
Constructs a structure data.COSEM Type
DataObject.Type.STRUCTURE
- Parameters:
element
- the structure values.- Returns:
- The data
- See Also:
newStructureData(List)
-
newBoolData
public static DataObject newBoolData(boolean bool)
Constructs a bool data.COSEM Type
DataObject.Type.BOOLEAN
- Parameters:
bool
- The structure of values- Returns:
- The data
-
newBitStringData
public static DataObject newBitStringData(BitString bitString) throws java.lang.IllegalArgumentException
Constructs a bit string data.COSEM Type
DataObject.Type.BIT_STRING
- Parameters:
bitString
- TheBitString
object holding the bit string- Returns:
- The data
- Throws:
java.lang.IllegalArgumentException
-
newInteger32Data
public static DataObject newInteger32Data(int int32)
Constructs a int 32 data.COSEM Type
DataObject.Type.DOUBLE_LONG
- Parameters:
int32
- he number to store- Returns:
- The data
-
newUInteger32Data
public static DataObject newUInteger32Data(long uIn32)
Constructs a unsigned int 32 data.COSEM Type
DataObject.Type.DOUBLE_LONG_UNSIGNED
- Parameters:
uIn32
- he number to store- Returns:
- The data
- Throws:
java.lang.IllegalArgumentException
- if uInt32 is > 2^(32)-1 or negative
-
newOctetStringData
public static DataObject newOctetStringData(byte[] string)
Constructs a byte array data.COSEM Type
DataObject.Type.OCTET_STRING
- Parameters:
string
- The byte array to store- Returns:
- The data
-
newVisibleStringData
public static DataObject newVisibleStringData(byte[] string)
Constructs a string, encoded as byte array data.COSEM Type
DataObject.Type.VISIBLE_STRING
- Parameters:
string
- The byte string to store- Returns:
- The data
-
newUtf8StringData
public static DataObject newUtf8StringData(byte[] string)
Constructs a UTF-8 string, encoded as byte array data.COSEM Type
DataObject.Type.UTF8_STRING
- Parameters:
string
- The byte string to store- Returns:
- The data
-
newBcdData
public static DataObject newBcdData(byte bcd) throws java.lang.IllegalArgumentException
Constructs a 2 digit BCD number dataCOSEM Type
DataObject.Type.BCD
- Parameters:
bcd
- The BCD number to store- Returns:
- The data
- Throws:
java.lang.IllegalArgumentException
-
newInteger8Data
public static DataObject newInteger8Data(byte int8) throws java.lang.IllegalArgumentException
Constructs a int 8 dataCOSEM Type
DataObject.Type.INTEGER
- Parameters:
int8
- The number to store- Returns:
- The data
- Throws:
java.lang.IllegalArgumentException
-
newUInteger8Data
public static DataObject newUInteger8Data(short uInt8) throws java.lang.IllegalArgumentException
Constructs a unsigned int 8 dataCOSEM Type
DataObject.Type.UNSIGNED
- Parameters:
uInt8
- The number to store- Returns:
- The data
- Throws:
java.lang.IllegalArgumentException
- if uInt8 > 2^(8)-1 or negative
-
newInteger16Data
public static DataObject newInteger16Data(short int16)
Constructs a int 16 dataCOSEM Type
DataObject.Type.LONG_INTEGER
- Parameters:
int16
- The number to store- Returns:
- The data
-
newUInteger16Data
public static DataObject newUInteger16Data(int uInt16)
Constructs a unsigned int 16 data.COSEM Type
DataObject.Type.LONG_UNSIGNED
- Parameters:
uInt16
- The number to store- Returns:
- The data
- Throws:
java.lang.IllegalArgumentException
- If newVal > 2^(16)-1 or negative
-
newInteger64Data
public static DataObject newInteger64Data(long int64)
Constructs a int 64 data.COSEM Type
DataObject.Type.LONG64
- Parameters:
int64
- The number to store- Returns:
- The data
-
newUInteger64Data
public static DataObject newUInteger64Data(long uInt64)
Constructs a unsigned int 64 dataCOSEM Type
DataObject.Type.LONG64_UNSIGNED
- Parameters:
uInt64
- The number to store- Returns:
- The data
- Throws:
java.lang.IllegalArgumentException
- if uInt64 is negative
-
newEnumerateData
public static DataObject newEnumerateData(int enumVal)
Constructs a enum data.COSEM Type
DataObject.Type.ENUMERATE
- Parameters:
enumVal
- The enum value to store- Returns:
- The data
- Throws:
java.lang.IllegalArgumentException
- if newVal is > 2^(8)-1 or negative
-
newFloat32Data
public static DataObject newFloat32Data(float float32)
Constructs a 32 bit floating point number data.COSEM Type
DataObject.Type.FLOAT32
- Parameters:
float32
- The number to store- Returns:
- The data
-
newFloat64Data
public static DataObject newFloat64Data(double float64)
Constructs a 64 bit floating point number data.COSEM Type
DataObject.Type.FLOAT64
- Parameters:
float64
- The number to store- Returns:
- The data
-
newDateTimeData
public static DataObject newDateTimeData(CosemDateTime dateTime)
Constructs a calendar datum holding date and timeCOSEM Type
DataObject.Type.DATE_TIME
- Parameters:
dateTime
- The date and time to store- Returns:
- The data
-
newDateData
public static DataObject newDateData(CosemDate date)
Constructs a calendar datum holding a dateCOSEM Type
DataObject.Type.DATE
- Parameters:
date
- The date store- Returns:
- The data
-
newTimeData
public static DataObject newTimeData(CosemTime time)
Constructs a calendar datum holding a timeCOSEM Type
DataObject.Type.TIME
- Parameters:
time
- The time store- Returns:
- The data
-
getType
public DataObject.Type getType()
The type of the currentDataObject
.- Returns:
- the enumeration type.
-
getValue
public <T> T getValue() throws java.lang.ClassCastException
Returns the value.- Type Parameters:
T
- the type in which the raw data should be cast.- Returns:
- the typed value.
- Throws:
java.lang.ClassCastException
- when the value doesn't match the assigned type.- See Also:
getType()
-
getRawValue
public java.lang.Object getRawValue()
Returns the raw object-value.- Returns:
- the raw object-value.
-
isBitString
public boolean isBitString()
Is used to determine if the data contains aBitString
object.- Returns:
- true if it contains a
BitString
object.
-
isNumber
public boolean isNumber()
Checks if the data of this container is a number- Returns:
- true data is a number.
-
isComplex
public boolean isComplex()
Checks if the data of this container is of a complex type.A complex container holds one or more sub container of type
DataObject
as values.A container is of complex type if
getType()
returns eitherDataObject.Type.ARRAY
,DataObject.Type.STRUCTURE
orDataObject.Type.COMPACT_ARRAY
.- Returns:
- true is the
DataObject
holds aList
ofDataObject
.
-
isByteArray
public boolean isByteArray()
Checks if the data of this container is a byte array.A container is a byte array if
getType()
returns eitherDataObject.Type.OCTET_STRING
, DataObject.Type.VISIBLE_STRING, DataObject.Type.BIT_STRING or DataObject.Type.UTF8_STRING.- Returns:
- true if the data is a byte array (
byte[]
).
-
isBoolean
public boolean isBoolean()
Checks if the data of this container is a boolean.- Returns:
true
if the data is a boolean.
-
isCosemDateFormat
public boolean isCosemDateFormat()
Checks if the data of this container is aCosemDateFormat
object.A container is a calendar if
getType()
returns eitherDataObject.Type.DATE_TIME
,DataObject.Type.DATE
orDataObject.Type.TIME
.- Returns:
true
if the data is aCosemDateFormat
.
-
isNull
public boolean isNull()
Checks if the data of this container isnull
.- Returns:
true
if the data isnull
.
-
toString
public java.lang.String toString()
Returns a string representation of theDataObject
.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the string representation of the object.
-
-