Package com.nt.udc.osar
Class OSAR
java.lang.Object
com.nt.udc.osar.OSAR
- All Implemented Interfaces:
Serializable
Used for passing data between Nodes.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttribute
(int id, double value) Add a double attribute to the OSAR.final void
addAttribute
(int id, float value) Add a float attribute to the OSAR.final void
addAttribute
(int id, int value) final void
addAttribute
(int id, int type, byte[] value) This method adds/replaces an attribute with the value in byte form.final void
addAttribute
(int id, int type, String s) final void
addAttribute
(int id, long value) final void
addAttribute
(int id, short value) final void
addAttribute
(OSARecAttr attr) void
addMillisAttribute
(int id, long time) Add aTIMEINMILLIS
attribute to the OSAR.void
addSecondsAttribute
(int id, int time) Add aTIMEINSECONDS
attribute to the OSAR.boolean
containsAttr
(int id) Tests if there is an attribute with the specified id in this OSAR.static final OSAR
fromBytes
(byte[] buff) The method gets an OSAR object from a byte arrayThe method to get all DCFieldsbyte
getAttrAsByte
(int id) Gets the byte value of the attribute associated with the specified id.byte[]
getAttrAsBytes
(int id) Gets the bytes value of the attribute associated with the specified id.getAttrAsDate
(int id) Gets theDate
value of the attribute associated with the specified id.double
getAttrAsDouble
(int id) Gets the double value of the attribute associated with the specified id.float
getAttrAsFloat
(int id) Gets the float value of the attribute associated with the specified id.int
getAttrAsInt
(int id) Gets the integer value of the attribute associated with the specified id.long
getAttrAsLong
(int id) Gets the long value of the attribute associated with the specified id.long
getAttrAsMillis
(int id) Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by the attribute associated with the specified id.getAttrAsObject
(int id) Gets the OBJECT value of the attribute associated with the specified id.short
getAttrAsShort
(int id) Gets the short value of the attribute associated with the specified id.getAttrAsString
(int id) Gets the string representation of the attribute associated with the specified id.getAttrAsTime
(int id) Gets theTime
value of the attribute associated with the specified id.getAttrAsTimestamp
(int id) Gets theTimestamp
value of the attribute associated with the specified id.getAttribute
(int id) The method to get an DCField object with tagbyte[]
getAttributeValueBytes
(int id) Returns the attribute's value in bytes.int
getAttrType
(int id) Gets the type of the attribute associated with the specified id.int
Returns the length in bytesint
Returns the length in wordsint
The method to get the number of attributesremoveAttribute
(int id) This method removes an attribute with the given id.void
shiftAttribute
(int oldId, int newId) Change an attribute's ID to a new ID.final byte[]
Returns a copy of the OSAR's byte array.static OSAR[]
toRecArray
(byte[] bytes) Create an array of OSARs from the byte array passed in.void
toStream
(OutputStream oStream) The method outputs an OSAR to the output streamtoString()
The method to return a string of the OSAR object
-
Constructor Details
-
OSAR
public OSAR()Default constructor, no prior attributes. -
OSAR
public OSAR(byte[] bytes) Creates an OSAR, where the OSAR is completely in byte form. (This means the byte array contains the OSAR length as well as the attributes).- Parameters:
bytes
- bytes of the OSAR
-
-
Method Details
-
toByteArray
public final byte[] toByteArray()Returns a copy of the OSAR's byte array.- Returns:
- OSAR, in byte form
-
fromBytes
The method gets an OSAR object from a byte array- Parameters:
buff
- bytes of the OSAR- Returns:
- new OSAR object, or null if unable to create a OSAR
-
addAttribute
public final void addAttribute(int id, int type, byte[] value) This method adds/replaces an attribute with the value in byte form.- Parameters:
id
- attribute idtype
- attribute typevalue
- byte representation of attribute's value
-
addAttribute
public final void addAttribute(int id, short value) -
addAttribute
public final void addAttribute(int id, int value) -
addAttribute
public final void addAttribute(int id, long value) -
addAttribute
-
addAttribute
-
addAttribute
public final void addAttribute(int id, float value) Add a float attribute to the OSAR. If there is an attribute already associated with id, its value is replaced.- Parameters:
id
- the id of the attributevalue
- the float value of the attribute
-
addAttribute
public void addAttribute(int id, double value) Add a double attribute to the OSAR. If there is an attribute already associated with id, its value is replaced.- Parameters:
id
- the id of the attributevalue
- the double value of the attribute
-
addMillisAttribute
public void addMillisAttribute(int id, long time) Add aTIMEINMILLIS
attribute to the OSAR. If there is an attribute already associated with id, its value is replaced.- Parameters:
id
- the id of the attributevalue
- the time in milliseconds value of the attribute
-
addSecondsAttribute
public void addSecondsAttribute(int id, int time) Add aTIMEINSECONDS
attribute to the OSAR. If there is an attribute already associated with id, its value is replaced.- Parameters:
id
- the id of the attributevalue
- the time in seconds value of the attribute
-
shiftAttribute
public void shiftAttribute(int oldId, int newId) Change an attribute's ID to a new ID.- Parameters:
oldId
- Old attribute IDnewId
- New attribute ID
-
removeAttribute
This method removes an attribute with the given id.- Parameters:
id
- id of the attribute- Returns:
- DCField object, of the id
-
getAttribute
The method to get an DCField object with tag- Parameters:
id
- id of the attribute- Returns:
- DCField object, of the id
-
getAllAttributes
The method to get all DCFields- Returns:
- array of DCField objects
-
getAttributeValueBytes
public byte[] getAttributeValueBytes(int id) Returns the attribute's value in bytes.- Parameters:
id
- id of the attribute- Returns:
- the bytes of the attribute's value
-
containsAttr
public boolean containsAttr(int id) Tests if there is an attribute with the specified id in this OSAR.- Parameters:
id
- the id of the attribute- Returns:
true
if an attribute with the given id exists in this OSAR;false
otherwise
-
getAttrType
public int getAttrType(int id) Gets the type of the attribute associated with the specified id.- Parameters:
id
- the id of the attribute- Returns:
- the type that is associated with the attribute specified by the id; -1 if the id does not identify an attribute in this OSAR
-
getLength
public int getLength()Returns the length in bytes- Returns:
- length of the OSAR in bytes
-
getLengthInWord
public int getLengthInWord()Returns the length in words- Returns:
- length of the OSAR in words
-
getNumAttrs
public int getNumAttrs()The method to get the number of attributes- Returns:
- number of attributes in the OSAR
-
toRecArray
Create an array of OSARs from the byte array passed in.- Parameters:
bytes
- bytes to create the OSAR's from- Returns:
- array of OSAR's
-
toStream
The method outputs an OSAR to the output stream- Parameters:
oStream
- output stream to write the OSAR to- Throws:
IOException
-
toString
The method to return a string of the OSAR object -
getAttrAsByte
Gets the byte value of the attribute associated with the specified id. This method should only be used forBYTE
attribute types.- Parameters:
id
- the id of the attribute- Returns:
- the byte value of the attribute associated with the specified id
- Throws:
NoSuchFieldException
- Thrown when the given id is not found.UnsupportedTypeException
- Thrown when the type of the id cannot be converted to the return type.
-
getAttrAsBytes
public byte[] getAttrAsBytes(int id) Gets the bytes value of the attribute associated with the specified id. This method should only be used forBYTES
attribute types.- Parameters:
id
- the id of the attribute- Returns:
- the bytes value of the attribute associated with the specified id
-
getAttrAsShort
Gets the short value of the attribute associated with the specified id. This method should only be used forSHORT
,BYTE
, and two byteSTRING
attribute types.- Parameters:
id
- the id of the attribute- Returns:
- the short value of the attribute associated with the specified id
- Throws:
NoSuchFieldException
- Thrown when the given id is not found.UnsupportedTypeException
- Thrown when the type of the id cannot be converted to the return type.
-
getAttrAsInt
Gets the integer value of the attribute associated with the specified id. This method should only be used forINTEGER
,BYTE
,SHORT
,IP
,TIMEINSECONDS
and four byteSTRING
attribute types.- Parameters:
id
- the id of the attribute- Returns:
- the integer value of the attribute associated with the specified id
- Throws:
NoSuchFieldException
- Thrown when the given id is not found.UnsupportedTypeException
- Thrown when the type of the id cannot be converted to the return type.
-
getAttrAsLong
Gets the long value of the attribute associated with the specified id. This method should only be used forLONG
,BYTE
,SHORT
,INTEGER
,TIMEINSECONDS
IP
,FLOAT
,TIMEINMILLIS
,MAC
,DOUBLE
and eight byteSTRING
attribute types.- Parameters:
id
- the id of the attribute- Returns:
- the long value of the attribute associated with the specified id
- Throws:
NoSuchFieldException
- Thrown when the given id is not found.UnsupportedTypeException
- Thrown when the type of the id cannot be converted to the return type.
-
getAttrAsFloat
Gets the float value of the attribute associated with the specified id. This method should only be used forFLOAT
,BYTE
,SHORT
,INTEGER
,TIMEINSECONDS
and four byteSTRING
attribute types.- Parameters:
id
- the id of the attribute- Returns:
- the float value of the attribute associated with the specified id
- Throws:
NoSuchFieldException
- Thrown when the given id is not found.UnsupportedTypeException
- Thrown when the type of the id cannot be converted to the return type.
-
getAttrAsDouble
Gets the double value of the attribute associated with the specified id. This method should only be used forDOUBLE
,BYTE
,SHORT
,INTEGER
,TIMEINSECONDS
,FLOAT
,TIMEINMILLIS
,LONG
and eight byteSTRING
attribute types.- Parameters:
id
- the id of the attribute- Returns:
- the double value of the attribute associated with the specified id
- Throws:
NoSuchFieldException
- Thrown when the given id is not found.UnsupportedTypeException
- Thrown when the type of the id cannot be converted to the return type.
-
getAttrAsDate
Gets theDate
value of the attribute associated with the specified id. This method should only be used forBYTE
,SHORT
,INTEGER
,TIMEINSECONDS
,FLOAT
,LONG
,TIMEINMILLIS
,DOUBLE
and eight byteSTRING
attribute types.- Parameters:
id
- the id of the attribute- Returns:
- the
Date
value of the attribute associatedi with the specified id - Throws:
NoSuchFieldException
- Thrown when the given id is not found.UnsupportedTypeException
- Thrown when the type of the id cannot be converted to the return type.
-
getAttrAsString
public String getAttrAsString(int id) throws NoSuchFieldException, UnsupportedTypeException, IOException, ClassNotFoundException Gets the string representation of the attribute associated with the specified id.- Parameters:
id
- the id of the attribute- Returns:
- a new String object representing the attribute associated with the specified id
- Throws:
NoSuchFieldException
- Thrown when the given id is not found.UnsupportedTypeException
- Thrown when the type of the id cannot be converted to the return type.IOException
ClassNotFoundException
-
getAttrAsMillis
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by the attribute associated with the specified id. This method should only be used forBYTE
,SHORT
,INTEGER
,TIMEINSECONDS
,FLOAT
,LONG
,TIMEINMILLIS
,DOUBLE
and eight byteSTRING
attribute types.- Parameters:
id
- the id of the attribute- Returns:
- the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by the attribute associated with the specified id
- Throws:
NoSuchFieldException
- Thrown when the given id is not found.UnsupportedTypeException
- Thrown when the type of the id cannot be converted to the return type.
-
getAttrAsTime
Gets theTime
value of the attribute associated with the specified id. This method should only be used forBYTE
,SHORT
,INTEGER
,TIMEINSECONDS
,FLOAT
,LONG
,TIMEINMILLIS
,DOUBLE
and eight byteSTRING
attribute types.- Parameters:
id
- the id of the attribute- Returns:
- the
Time
value of the attribute associated with the specified id - Throws:
NoSuchFieldException
- Thrown when the given id is not found.UnsupportedTypeException
- Thrown when the type of the id cannot be converted to the return type.
-
getAttrAsTimestamp
Gets theTimestamp
value of the attribute associated with the specified id. This method should only be used forBYTE
,SHORT
,INTEGER
,TIMEINSECONDS
,FLOAT
,LONG
,TIMEINMILLIS
,DOUBLE
and eight byteSTRING
attribute types.- Parameters:
id
- the id of the attribute- Returns:
- the
Timestamp
value of the attribute associated with the specified id - Throws:
NoSuchFieldException
- Thrown when the given id is not found.UnsupportedTypeException
- Thrown when the type of the id cannot be converted to the return type.
-
getAttrAsObject
Gets the OBJECT value of the attribute associated with the specified id. This method should only be used forOBJECT
attribute types.- Parameters:
id
- the id of the attribute- Returns:
- the object value of the attribute associated with the specified id; 0 if the associated attribute type does not support this value request, or if the id does not identify an attribute in this OSAR
-