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 TypeMethodDescriptionvoidaddAttribute(int id, double value) Add a double attribute to the OSAR.final voidaddAttribute(int id, float value) Add a float attribute to the OSAR.final voidaddAttribute(int id, int value) final voidaddAttribute(int id, int type, byte[] value) This method adds/replaces an attribute with the value in byte form.final voidaddAttribute(int id, int type, String s) final voidaddAttribute(int id, long value) final voidaddAttribute(int id, short value) final voidaddAttribute(OSARecAttr attr) voidaddMillisAttribute(int id, long time) Add aTIMEINMILLISattribute to the OSAR.voidaddSecondsAttribute(int id, int time) Add aTIMEINSECONDSattribute to the OSAR.booleancontainsAttr(int id) Tests if there is an attribute with the specified id in this OSAR.static final OSARfromBytes(byte[] buff) The method gets an OSAR object from a byte arrayThe method to get all DCFieldsbytegetAttrAsByte(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 theDatevalue of the attribute associated with the specified id.doublegetAttrAsDouble(int id) Gets the double value of the attribute associated with the specified id.floatgetAttrAsFloat(int id) Gets the float value of the attribute associated with the specified id.intgetAttrAsInt(int id) Gets the integer value of the attribute associated with the specified id.longgetAttrAsLong(int id) Gets the long value of the attribute associated with the specified id.longgetAttrAsMillis(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.shortgetAttrAsShort(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 theTimevalue of the attribute associated with the specified id.getAttrAsTimestamp(int id) Gets theTimestampvalue 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.intgetAttrType(int id) Gets the type of the attribute associated with the specified id.intReturns the length in bytesintReturns the length in wordsintThe method to get the number of attributesremoveAttribute(int id) This method removes an attribute with the given id.voidshiftAttribute(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.voidtoStream(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 aTIMEINMILLISattribute 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 aTIMEINSECONDSattribute 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:
trueif an attribute with the given id exists in this OSAR;falseotherwise
-
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 forBYTEattribute 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 forBYTESattribute 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 byteSTRINGattribute 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,TIMEINSECONDSand four byteSTRINGattribute 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,TIMEINSECONDSIP,FLOAT,TIMEINMILLIS,MAC,DOUBLEand eight byteSTRINGattribute 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,TIMEINSECONDSand four byteSTRINGattribute 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,LONGand eight byteSTRINGattribute 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 theDatevalue of the attribute associated with the specified id. This method should only be used forBYTE,SHORT,INTEGER,TIMEINSECONDS,FLOAT,LONG,TIMEINMILLIS,DOUBLEand eight byteSTRINGattribute types.- Parameters:
id- the id of the attribute- Returns:
- the
Datevalue 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.IOExceptionClassNotFoundException
-
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,DOUBLEand eight byteSTRINGattribute 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 theTimevalue of the attribute associated with the specified id. This method should only be used forBYTE,SHORT,INTEGER,TIMEINSECONDS,FLOAT,LONG,TIMEINMILLIS,DOUBLEand eight byteSTRINGattribute types.- Parameters:
id- the id of the attribute- Returns:
- the
Timevalue 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 theTimestampvalue of the attribute associated with the specified id. This method should only be used forBYTE,SHORT,INTEGER,TIMEINSECONDS,FLOAT,LONG,TIMEINMILLIS,DOUBLEand eight byteSTRINGattribute types.- Parameters:
id- the id of the attribute- Returns:
- the
Timestampvalue 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 forOBJECTattribute 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
-