Class OSAR

java.lang.Object
com.nt.udc.osar.OSAR
All Implemented Interfaces:
Serializable

public class OSAR extends Object implements Serializable
Used for passing data between Nodes.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor, no prior attributes.
    OSAR(byte[] bytes)
    Creates an OSAR, where the OSAR is completely in byte form.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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
     
    void
    addMillisAttribute(int id, long time)
    Add a TIMEINMILLIS attribute to the OSAR.
    void
    addSecondsAttribute(int id, int time)
    Add a TIMEINSECONDS 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 array
    The method to get all DCFields
    byte
    getAttrAsByte(int id)
    Gets the byte value of the attribute associated with the specified id.
    byte[]
    Gets the bytes value of the attribute associated with the specified id.
    getAttrAsDate(int id)
    Gets the Date value of the attribute associated with the specified id.
    double
    Gets the double value of the attribute associated with the specified id.
    float
    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
    Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by the attribute associated with the specified id.
    Gets the OBJECT value of the attribute associated with the specified id.
    short
    Gets the short value of the attribute associated with the specified id.
    Gets the string representation of the attribute associated with the specified id.
    getAttrAsTime(int id)
    Gets the Time value of the attribute associated with the specified id.
    Gets the Timestamp value of the attribute associated with the specified id.
    getAttribute(int id)
    The method to get an DCField object with tag
    byte[]
    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 bytes
    int
    Returns the length in words
    int
    The method to get the number of attributes
    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
    The method outputs an OSAR to the output stream
    The method to return a string of the OSAR object

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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

      public static final OSAR fromBytes(byte[] buff)
      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 id
      type - attribute type
      value - 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

      public final void addAttribute(int id, int type, String s)
    • addAttribute

      public final void addAttribute(OSARecAttr attr)
    • 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 attribute
      value - 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 attribute
      value - the double value of the attribute
    • addMillisAttribute

      public void addMillisAttribute(int id, long time)
      Add a TIMEINMILLIS attribute to the OSAR. If there is an attribute already associated with id, its value is replaced.
      Parameters:
      id - the id of the attribute
      value - the time in milliseconds value of the attribute
    • addSecondsAttribute

      public void addSecondsAttribute(int id, int time)
      Add a TIMEINSECONDS attribute to the OSAR. If there is an attribute already associated with id, its value is replaced.
      Parameters:
      id - the id of the attribute
      value - 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 ID
      newId - New attribute ID
    • removeAttribute

      public OSARecAttr removeAttribute(int id)
      This method removes an attribute with the given id.
      Parameters:
      id - id of the attribute
      Returns:
      DCField object, of the id
    • getAttribute

      public OSARecAttr getAttribute(int id)
      The method to get an DCField object with tag
      Parameters:
      id - id of the attribute
      Returns:
      DCField object, of the id
    • getAllAttributes

      public OSARecAttr[] 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

      public static OSAR[] toRecArray(byte[] bytes)
      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

      public void toStream(OutputStream oStream) throws IOException
      The method outputs an OSAR to the output stream
      Parameters:
      oStream - output stream to write the OSAR to
      Throws:
      IOException
    • toString

      public String toString()
      The method to return a string of the OSAR object
      Overrides:
      toString in class Object
      Returns:
      OSAR, in String form
    • getAttrAsByte

      public byte getAttrAsByte(int id) throws NoSuchFieldException, UnsupportedTypeException
      Gets the byte value of the attribute associated with the specified id. This method should only be used for BYTE 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 for BYTES attribute types.
      Parameters:
      id - the id of the attribute
      Returns:
      the bytes value of the attribute associated with the specified id
    • getAttrAsShort

      public short getAttrAsShort(int id) throws NoSuchFieldException, UnsupportedTypeException
      Gets the short value of the attribute associated with the specified id. This method should only be used for SHORT, BYTE, and two byte STRING 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

      public int getAttrAsInt(int id) throws NoSuchFieldException, UnsupportedTypeException
      Gets the integer value of the attribute associated with the specified id. This method should only be used for INTEGER, BYTE, SHORT, IP, TIMEINSECONDS and four byte STRING 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

      public long getAttrAsLong(int id) throws NoSuchFieldException, UnsupportedTypeException
      Gets the long value of the attribute associated with the specified id. This method should only be used for LONG, BYTE, SHORT, INTEGER, TIMEINSECONDS IP, FLOAT, TIMEINMILLIS, MAC, DOUBLE and eight byte STRING 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

      public float getAttrAsFloat(int id) throws NoSuchFieldException, UnsupportedTypeException
      Gets the float value of the attribute associated with the specified id. This method should only be used for FLOAT, BYTE, SHORT, INTEGER, TIMEINSECONDS and four byte STRING 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

      public double getAttrAsDouble(int id) throws NoSuchFieldException, UnsupportedTypeException
      Gets the double value of the attribute associated with the specified id. This method should only be used for DOUBLE, BYTE, SHORT, INTEGER, TIMEINSECONDS, FLOAT, TIMEINMILLIS, LONG and eight byte STRING 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

      public Date getAttrAsDate(int id) throws NoSuchFieldException, UnsupportedTypeException
      Gets the Date value of the attribute associated with the specified id. This method should only be used for BYTE, SHORT, INTEGER, TIMEINSECONDS, FLOAT, LONG, TIMEINMILLIS, DOUBLE and eight byte STRING 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

      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

      public long getAttrAsMillis(int id) throws NoSuchFieldException, UnsupportedTypeException
      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 for BYTE, SHORT, INTEGER, TIMEINSECONDS, FLOAT, LONG, TIMEINMILLIS, DOUBLE and eight byte STRING 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

      public Time getAttrAsTime(int id) throws NoSuchFieldException, UnsupportedTypeException
      Gets the Time value of the attribute associated with the specified id. This method should only be used for BYTE, SHORT, INTEGER, TIMEINSECONDS, FLOAT, LONG, TIMEINMILLIS, DOUBLE and eight byte STRING 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

      public Timestamp getAttrAsTimestamp(int id) throws NoSuchFieldException, UnsupportedTypeException
      Gets the Timestamp value of the attribute associated with the specified id. This method should only be used for BYTE, SHORT, INTEGER, TIMEINSECONDS, FLOAT, LONG, TIMEINMILLIS, DOUBLE and eight byte STRING 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

      public Object getAttrAsObject(int id)
      Gets the OBJECT value of the attribute associated with the specified id. This method should only be used for OBJECT 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