com.devexperts.qd.kit
Class DefaultRecord

java.lang.Object
  extended by com.devexperts.qd.kit.DefaultRecord
All Implemented Interfaces:
DataRecord, RecordReader

public class DefaultRecord
extends java.lang.Object
implements DataRecord

The DefaultRecord is a basic implementation of data record. Note, that this implementation works only with fields that are derived from AbstractDataIntField and AbstractDataObjField classes.


Field Summary
protected  boolean has_time
           
protected  int id
           
protected  AbstractDataIntField[] int_fields
           
protected  RecordMapping mapping
           
protected  java.lang.String name
           
protected  AbstractDataObjField[] obj_fields
           
protected  DefaultScheme scheme
           
 
Constructor Summary
DefaultRecord(int id, java.lang.String name, boolean has_time, DataIntField[] int_fields, DataObjField[] obj_fields)
           
 
Method Summary
 int getId()
          Returns identifier of this record.
 DataRecord getIncomingRecord()
           
 AbstractDataIntField getIntField(int index)
          Returns Int-field by its index within this record.
 int getIntFieldCount()
          Returns a number of Int-fields in this record.
 RecordMapping getMapping()
          Returns mapping for this data record or null if there is no mapping for this record.
 java.lang.String getName()
          Returns name of this record.
 AbstractDataObjField getObjField(int index)
          Returns Obj-field by its index within this record.
 int getObjFieldCount()
          Returns a number of Obj-fields in this record.
 DataRecord getResultingRecord()
          Returns actual DataRecord that shall be used for subscription.
 DefaultScheme getScheme()
          Returns parent DataScheme of this field.
 boolean hasTime()
          Determines if this record contains time coordinate.
 void readFields(com.devexperts.io.BufferedInput in, RecordCursor cursor)
          Reads this record's field values in a binary from the specified buffered input.
 void readRecord(com.devexperts.io.BufferedInput in, RecordBuffer buffer, int cipher, java.lang.String symbol)
          Reads record from the specified input and adds it to the specified cursor.
static void setParentReferences(DataRecord record)
          Deprecated. No replacement. Just remove usages of this method. DefaultRecord(int, String, boolean, DataIntField[], DataObjField[]) constructor now does it automatically.
 void setScheme(DefaultScheme scheme)
          Sets reference to parent data scheme.
 java.lang.String toString()
           
 boolean update(RecordCursor from, RecordCursor to)
          Updates this record's field values in to cusor by values from cursor.
 void writeFields(com.devexperts.io.BufferedOutput out, RecordCursor cursor)
          Writes this record's field values in a binary form into a specified buffered output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

scheme

protected DefaultScheme scheme

mapping

protected final RecordMapping mapping

id

protected final int id

name

protected final java.lang.String name

has_time

protected final boolean has_time

int_fields

protected final AbstractDataIntField[] int_fields

obj_fields

protected final AbstractDataObjField[] obj_fields
Constructor Detail

DefaultRecord

public DefaultRecord(int id,
                     java.lang.String name,
                     boolean has_time,
                     DataIntField[] int_fields,
                     DataObjField[] obj_fields)
Method Detail

setScheme

public final void setScheme(DefaultScheme scheme)
Sets reference to parent data scheme.

Throws:
java.lang.IllegalStateException - if parent scheme already set to different instance.

setParentReferences

public static void setParentReferences(DataRecord record)
Deprecated. No replacement. Just remove usages of this method. DefaultRecord(int, String, boolean, DataIntField[], DataObjField[]) constructor now does it automatically.

Sets references to corresponding parent entities in the specified record. Requires that record is instance of DefaultRecord.

Throws:
java.lang.ClassCastException - if record is not an instance of DefaultRecord.
java.lang.IllegalStateException - if some parent reference already set to different instance.

toString

public final java.lang.String toString()
Overrides:
toString in class java.lang.Object

getScheme

public final DefaultScheme getScheme()
Description copied from interface: DataRecord
Returns parent DataScheme of this field.

Specified by:
getScheme in interface DataRecord

getMapping

public final RecordMapping getMapping()
Description copied from interface: DataRecord
Returns mapping for this data record or null if there is no mapping for this record. The result of invoking getRecord() method on the resulting record mapping (when it is non null) is equal to this data record.

Specified by:
getMapping in interface DataRecord

getId

public final int getId()
Description copied from interface: DataRecord
Returns identifier of this record. The identifier coincides with record index in its parent DataScheme. It is also used for identification of data record in serialized form.

Specified by:
getId in interface DataRecord

getName

public final java.lang.String getName()
Description copied from interface: DataRecord
Returns name of this record. The name must be unique within whole DataScheme. It is recommended that full names of record's fields contain record name as a prefix like these: "FooRecord.Category", "FooRecord.Amount", etc.

Specified by:
getName in interface DataRecord

hasTime

public final boolean hasTime()
Description copied from interface: DataRecord
Determines if this record contains time coordinate.

Specified by:
hasTime in interface DataRecord

getIntFieldCount

public final int getIntFieldCount()
Description copied from interface: DataRecord
Returns a number of Int-fields in this record.

Specified by:
getIntFieldCount in interface DataRecord

getIntField

public final AbstractDataIntField getIntField(int index)
Description copied from interface: DataRecord
Returns Int-field by its index within this record.

Specified by:
getIntField in interface DataRecord

getObjFieldCount

public final int getObjFieldCount()
Description copied from interface: DataRecord
Returns a number of Obj-fields in this record.

Specified by:
getObjFieldCount in interface DataRecord

getObjField

public final AbstractDataObjField getObjField(int index)
Description copied from interface: DataRecord
Returns Obj-field by its index within this record.

Specified by:
getObjField in interface DataRecord

update

public boolean update(RecordCursor from,
                      RecordCursor to)
Description copied from interface: DataRecord
Updates this record's field values in to cusor by values from cursor. This method is used for implementation of ticker contract.

Specified by:
update in interface DataRecord
Returns:
true if any values were updated and listeners shall be notified on data change.

writeFields

public void writeFields(com.devexperts.io.BufferedOutput out,
                        RecordCursor cursor)
                 throws java.io.IOException
Description copied from interface: DataRecord
Writes this record's field values in a binary form into a specified buffered output. The bytes written should be the same as if each field is individually written using DataIntField.writeInt(java.io.DataOutput, int) and DataObjField.writeObj(java.io.DataOutput, java.lang.Object).

Specified by:
writeFields in interface DataRecord
Throws:
java.io.IOException

readFields

public void readFields(com.devexperts.io.BufferedInput in,
                       RecordCursor cursor)
                throws java.io.IOException
Description copied from interface: DataRecord
Reads this record's field values in a binary from the specified buffered input. The data read should be the same as if each field is individually read using DataIntField.readInt(java.io.DataInput) and DataObjField.readObj(java.io.DataInput).

Specified by:
readFields in interface DataRecord
Throws:
java.io.IOException

readRecord

public final void readRecord(com.devexperts.io.BufferedInput in,
                             RecordBuffer buffer,
                             int cipher,
                             java.lang.String symbol)
                      throws java.io.IOException
Description copied from interface: RecordReader
Reads record from the specified input and adds it to the specified cursor. DataRecord implementation of this method reads the record itself, but other implementations might perform complex transformations or do not read anything at all.

Specified by:
readRecord in interface RecordReader
Throws:
java.io.IOException

getResultingRecord

public final DataRecord getResultingRecord()
Description copied from interface: RecordReader
Returns actual DataRecord that shall be used for subscription. It might return null if this reader does not actually read anything. DataRecord implementation of this method returns this.

Specified by:
getResultingRecord in interface RecordReader

getIncomingRecord

public final DataRecord getIncomingRecord()
Specified by:
getIncomingRecord in interface RecordReader