Class TransformerDataImpl

java.lang.Object
com.caplin.transformer.module.datasrc.TransformerDataImpl
All Implemented Interfaces:
DSData, DSPacket, DSSerializable, TransformerData, TransformerFlags, Iterable<DSField>
Direct Known Subclasses:
TransformerContainerImpl, TransformerPermissionImpl, TransformerRecordImpl

public class TransformerDataImpl extends Object implements TransformerData

Implementation of the TransformerData interface.

  • Field Details

    • modCount

      protected int modCount

      Counts the number of times a new field is added to, or a field is removed from, the update. This is used by the FieldIterator to determine whether a concurrent modification has been made.

  • Constructor Details

    • TransformerDataImpl

      protected TransformerDataImpl(long dsDataPointer)

      Constructor is protected to prevent a TransformerData being instantiated except by the DSFactory class.

      A TransformerData created with this constructor will be responsible for freeing the memory for the underlying C ds_data struct.

      This is equivalent to calling TransformerData(dsDataPointer, true).

      Parameters:
      dsDataPointer - The pointer to the C ds_data struct that holds the state information for the update.
    • TransformerDataImpl

      protected TransformerDataImpl(long dsDataPointer, boolean freeDsDataPointer)

      Constructor is protected to prevent a TransformerData being instantiated except by the DSFactory class.

      Parameters:
      dsDataPointer - The pointer to the C ds_data struct that holds the state information for the update.
      freeDsDataPointer - true if the TransformerData is responsible for freeing up the memory for the C ds_data struct, or false if the Transformer core is responsible.
  • Method Details

    • getDSDataPointer

      public long getDSDataPointer()
      Description copied from interface: TransformerData

      Gets the pointer to the C ds_data struct that holds the state information for the update. This method is used internally by the TransformerData.

      Once the update has been sent, pointer is nulled down, and this method will throw a IllegalStateException.

      Specified by:
      getDSDataPointer in interface TransformerData
      Returns:
      The pointer to the ds_data struct.
    • setFlags

      public void setFlags(int flags)
      Description copied from interface: DSData

      Sets the flags to be sent with this packet.

      The flags that can be set are:

      Multiple flags can be set by bitwise ORing them together (e.g. F_CREATEOBJECT|F_CREATEPARENT|F_IMAGE).

      Specified by:
      setFlags in interface DSData
      Parameters:
      flags - The flags to be sent with this packet.
    • getFlags

      public int getFlags()
      Description copied from interface: DSData

      Gets the flags that are going to be sent with this packet.

      Specified by:
      getFlags in interface DSData
      Returns:
      The flags that are going to be sent.
    • setType

      public void setType(int type)
      Description copied from interface: DSData

      Sets the object type of this DSData to the specified value.

      Valid object types are:

      Specified by:
      setType in interface DSData
      Parameters:
      type - this object's type.
    • setType

      public void setType(ObjectType objectType)
      Description copied from interface: TransformerData

      Sets the update's object type to the specified type.

      Specified by:
      setType in interface TransformerData
      Parameters:
      objectType - The type of object.
    • getType

      public int getType()
      Description copied from interface: DSData

      Gets this object's type.

      Specified by:
      getType in interface DSData
      Returns:
      The object's type.
    • getObjectType

      public ObjectType getObjectType()
      Description copied from interface: TransformerData

      Gets the update's object type.

      Specified by:
      getObjectType in interface TransformerData
      Returns:
      The ObjectType that represents the object type for this update.
    • getSequenceNumber

      public int getSequenceNumber()
      Description copied from interface: TransformerData

      Gets the update's sequence number.

      Specified by:
      getSequenceNumber in interface TransformerData
      Returns:
      the sequence number of the update.
    • setSubject

      public void setSubject(String subject)
      Description copied from interface: DSData

      Sets this object's subject.

      Specified by:
      setSubject in interface DSData
      Parameters:
      subject - The subject, or object, name.
    • getSubject

      public String getSubject()
      Description copied from interface: DSData

      Gets this object's subject.

      Specified by:
      getSubject in interface DSData
      Returns:
      The subject, or object, name.
    • count

      public int count()
      Description copied from interface: DSData

      Gets the number of fields that are present in this packet.

      Specified by:
      count in interface DSData
      Returns:
      The number of fields in this packet.
    • elements

      public Enumeration<DSField> elements()
      Description copied from interface: DSData

      Returns an enumeration of the fields for this DSData. Each field is represented by a DSField.

      Specified by:
      elements in interface DSData
      Returns:
      An enumeration of the fields for this DSData.
    • iterator

      public Iterator<DSField> iterator()
      Description copied from interface: DSData

      Returns an iterator of the fields for this DSData. Each field is represented by a DSField.

      Specified by:
      iterator in interface DSData
      Specified by:
      iterator in interface Iterable<DSField>
      Returns:
      An iterator of the fields for this DSData.
    • getKeys

      public Enumeration<?> getKeys()
      Description copied from interface: DSData

      Returns as Enumeration of Integers indicating the field number .

      Specified by:
      getKeys in interface DSData
      Returns:
      null.
    • getValues

      public Enumeration<?> getValues()
      Description copied from interface: DSData

      Returns as Enumeration of Strings indicating the field values .

      Specified by:
      getValues in interface DSData
      Returns:
      null.
    • getFieldByFieldNumber

      public DSField getFieldByFieldNumber(int fieldNumber)
      Description copied from interface: DSData

      Gets the first occurrence of the field with the specified field number.

      If there are three occurrences of the field 12, with values "75", "75.5" and "75.25", then calling getFieldByFieldNumber(12) will return the field that contains the value "75".

      This is equivalent to calling getFieldByFieldNumber(fieldNumber, 0).

      Specified by:
      getFieldByFieldNumber in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      Returns:
      The field for the first occurrence of the field number, or null if the specified field is not found.
    • getFieldByFieldNumber

      public DSField getFieldByFieldNumber(int fieldNumber, int occurrence)
      Description copied from interface: DSData

      Gets the specified occurrence of the field with the specified field number.

      If there are three occurrences of the field 12, with values "75", "75.5" and "75.25", then calling getFieldByFieldNumber(12, 2) will return the field that contains the value "75.25".

      Specified by:
      getFieldByFieldNumber in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      occurrence - The occurrence of the field to be got. The first field is occurrence 0, the next occurrence 1, and so on.
      Returns:
      The field for the specified occurrence of the field number, or null if the specified field is not found.
    • removeField

      public boolean removeField(DSField dsField)
      Description copied from interface: DSData

      Removes the specified field from the DSData.

      Specified by:
      removeField in interface DSData
      Parameters:
      dsField - The field to remove.
      Returns:
      true if the field was successfully removed, or false if the field has already been removed.
      Throws:
      ConcurrentModificationException - If the any modifications have been made to the fields since the specified field was obtained. This prevents any unexpected behaviour from this method.
      NullPointerException - If the dsField argument is null.
    • updateData

      public boolean updateData(int fieldNumber, String value, int occurrence)

      Sets the value of the specified occurrence for the specified field number. The occurrence parameter is ignored in this version.

      If there are three occurrences of the field 12, "75", "75.5" and "75.25", then calling updateData(12, "76", 2) will change occurrences to be "76", "75.5" and "75.25".

      Specified by:
      updateData in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      value - The new value for the field.
      occurrence - The occurrence of the field to be updated. The first field is occurrence 0, the next occurrence 1, and so on.
      Returns:
      Always true. If the specified field does not exist, it will be added.
      Throws:
      NullPointerException - If the value argument is null.
    • updateData

      public boolean updateData(int fieldNumber, String value)
      Description copied from interface: DSData

      Sets the value of the first occurrence for the specified field number.

      If there are three occurrences of the field 12, "75", "75.5" and "75.25", then calling updateData(12, "76") will change occurrences to be "76", "75.5" and "75.25".

      This is equivalent to calling updateData(fieldNumber, value, 0).

      Specified by:
      updateData in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      value - The new value for the field.
      Returns:
      Always true. If the specified field does not exist, it will be added.
      Throws:
      NullPointerException - If the value argument is null.
    • merge

      public int merge(TransformerData transformerDataToMerge)

      Merges the fields from the specified TransformerData with those in this TransformerData. If a field does not exist within this TransformerData then the field will be added to it. If the field already exists, then its value will be updated.

      If a field exists multiple times (as occurs with type 2 and type 3 records), only the first occurrence will be merged.

      Specified by:
      merge in interface TransformerData
      Parameters:
      transformerDataToMerge - The TransformerData from which the fields should be merged from.
      Returns:
      The number of fields that were updated.
    • send

      public void send()

      Sends the update to the Transformer core. The data will be cached by the core and will be published to the DataSource peers, as well as to any Transformer modules that have subscribed to it.

      As soon as the update is sent, its memory is freed by the Transformer core. Any further attempts to use the object will result in IllegalStateExceptions being thrown. If the update needs to be sent, then further changes made to the object, the DSFactory.createTransformerData(TransformerData) method should be used to create a copy of the object before the update is sent.

      This method is equivalent to calling send(STORE_IN_CACHE|PUBLISH_TO_PEERS).

      Specified by:
      send in interface DSPacket
      Throws:
      IllegalStateException - If the update has already been sent.
    • send

      public void send(int flags)

      Sends the update to the Transformer core. The specified flags will determine what the core does with the update.

      As soon as the update is sent, its memory is freed by the Transformer core. Any further attempts to use the object will result in IllegalStateExceptions being thrown. If the update needs to be sent, then further changes made to the object, the DSFactory.createTransformerData(TransformerData) method should be used to create a copy of the object before the update is sent.

      The valid flags are:

      • NO_FLAGS
      • STORE_IN_CACHE
      • PUBLISH_TO_PEERS
      • SILENT_SEND
      • MAINTAIN_TIMESTAMP
      Specified by:
      send in interface TransformerData
      Parameters:
      flags - The flags that should be passed to the Transformer core to tell it how to process the update.
      Throws:
      IllegalStateException - If the update has already been sent.
    • sendDirect

      public void sendDirect()

      Invokes the send method.

      Specified by:
      sendDirect in interface DSPacket
    • sendToPeer

      public void sendToPeer(int peer)

      Invokes the send method.

      Specified by:
      sendToPeer in interface DSPacket
      Parameters:
      peer - the DataSource peer.
    • toBytes

      public byte[] toBytes()

      Returns null.

      Specified by:
      toBytes in interface DSSerializable
      Returns:
      null.
    • clearFields

      public void clearFields()
      Description copied from interface: DSData

      Removes all the fields.

      Specified by:
      clearFields in interface DSData
    • addData

      public void addData(int fieldNumber, String value)
      Description copied from interface: DSData

      Adds the String value for the specified field number.

      Specified by:
      addData in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      value - The value to be stored in the field.
      Throws:
      NullPointerException - If the value argument is null.
    • addData

      public void addData(int fieldNumber, char value)
      Description copied from interface: DSData

      Adds the String representation of the character value for the specified field number.

      Specified by:
      addData in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      value - The value to be stored in the field.
    • addData

      public void addData(int fieldNumber, char[] value)
      Description copied from interface: DSData

      Adds the String representation of the character array for the specified field number.

      Specified by:
      addData in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      value - The value to be stored in the field.
      Throws:
      NullPointerException - If the value argument is null.
    • addData

      public void addData(int fieldNumber, double value)
      Description copied from interface: DSData

      Adds the String representation of the double value for the specified field number.

      Warning: the underlying implementation will not guarantee any accuracy beyond 12 decimal places. If greater precision is required, the value should be formatted separately and added using the DSData.addData(int, String) method.

      Specified by:
      addData in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      value - The value to be stored in the field.
    • addData

      public void addData(int fieldNumber, float value)
      Description copied from interface: DSData

      Adds the String representation of the float value for the specified field number.

      Warning: the underlying implementation will not guarantee any accuracy beyond 6 decimal places. If greater precision is required, the value should be formatted separately and added using the DSData.addData(int, String) method.

      Specified by:
      addData in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      value - The value to be stored in the field.
    • addData

      public void addData(int fieldNumber, int value)
      Description copied from interface: DSData

      Adds the String representation of the integer value for the specified field number.

      Specified by:
      addData in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      value - The value to be stored in the field.
    • addData

      public void addData(int fieldNumber, long value)
      Description copied from interface: DSData

      Adds the String representation of the long value for the specified field number.

      Specified by:
      addData in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      value - The value to be stored in the field.
    • addData

      public void addData(DSField dsField)
      Description copied from interface: DSData

      Adds the DSField.

      Specified by:
      addData in interface DSData
      Parameters:
      dsField - the DSField to be added.
    • addBinaryData

      public void addBinaryData(int fieldNumber, byte value)
      Description copied from interface: DSData

      Adds the byte value for the specified field number. This method Base64 encodes the value before storing it.

      Specified by:
      addBinaryData in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      value - The byte value to be stored in the field.
    • addBinaryData

      public void addBinaryData(int fieldNumber, short value)
      Description copied from interface: DSData

      Adds the short value for the specified field number. This method Base64 encodes the value before storing it.

      Specified by:
      addBinaryData in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      value - The value to be stored in the field.
    • addBinaryData

      public void addBinaryData(int fieldNumber, int value)
      Description copied from interface: DSData

      Adds the integer value for the specified field number. This method Base64 encodes the value before storing it.

      Specified by:
      addBinaryData in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      value - The value to be stored in the field.
    • addBinaryData

      public void addBinaryData(int fieldNumber, long value)
      Description copied from interface: DSData

      Adds the long value for the specified field number. This method Base64 encodes the value before storing it.

      Specified by:
      addBinaryData in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      value - The value to be stored in the field.
    • addBinaryData

      public void addBinaryData(int fieldNumber, float value)
      Description copied from interface: DSData

      Adds the float value for the specified field number. This method Base64 encodes the value before storing it.

      Specified by:
      addBinaryData in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      value - The value to be stored in the field.
    • addBinaryData

      public void addBinaryData(int fieldNumber, double value)
      Description copied from interface: DSData

      Adds the double value for the specified field number. This method Base64 encodes the value before storing it.

      Specified by:
      addBinaryData in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      value - The value to be stored in the field.
    • addBinaryData

      public void addBinaryData(int fieldNumber, byte[] value)
      Description copied from interface: DSData

      Adds the byte array value for the specified field number. This method Base64 encodes the value before storing it.

      Specified by:
      addBinaryData in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      value - The array of bytes to be stored in the field.
      Throws:
      NullPointerException - If the value argument is null.
    • addBinaryData

      public void addBinaryData(int fieldNumber, String value)
      Description copied from interface: DSData

      Adds the String value for the specified field number. This method Base64 encodes the value before storing it.

      Specified by:
      addBinaryData in interface DSData
      Parameters:
      fieldNumber - The field identifier number.
      value - The value to be stored in the field.
      Throws:
      NullPointerException - If the value argument is null.
    • addString

      protected void addString(int fieldNumber, String value)

      Adds the String value for the specified field number with the default flag 0.

      Parameters:
      fieldNumber - The field identifier number.
      value - The value to be stored in the field.
      Throws:
      NullPointerException - If the value argument is null.
    • addString

      protected void addString(int fieldNumber, String value, int flags)

      Adds the String value for the specified field number with the specified flags.

      Parameters:
      fieldNumber - The field identifier number.
      value - The value to be stored in the field.
      flags - The flags to apply to the field.
      Throws:
      NullPointerException - If the value argument is null.
    • finalize

      public void finalize()

      Frees the memory for the underlying C ds_data struct stored within the Transformer core. If the send(int) method has been invoked, this method does nothing.

      Overrides:
      finalize in class Object