org.fudgemsg
Class FudgeFieldType<T>

java.lang.Object
  extended by org.fudgemsg.FudgeFieldType<T>
Type Parameters:
T - underlying Java class this type represents
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ByteArrayFieldType, DateFieldType, DateTimeFieldType, DoubleArrayFieldType, FloatArrayFieldType, FudgeMsgFieldType, IndicatorFieldType, IntArrayFieldType, LongArrayFieldType, SecondaryFieldTypeBase, ShortArrayFieldType, StringFieldType, TimeFieldType, UnknownFudgeFieldType

public class FudgeFieldType<T>
extends Object
implements Serializable

The type of a field as defined by Fudge.

In order to efficiently send messages, Fudge needs to know the type of each piece of data. A standard set of types is supported by all Fudge-compliant systems. This set may be extended with custom types within a closed Fudge implementation. Custom types must be registered with FudgeTypeDictionary.

This class is not final but is thread-safe in isolation. Subclasses must be immutable and thread-safe.

See Also:
Serialized Form

Constructor Summary
FudgeFieldType(int typeId, Class<T> javaType, boolean isVariableSize, int fixedSize)
          Constructs a new type based on the underlying Java type.
 
Method Summary
 boolean equals(Object obj)
          Checks if this type equals another.
 int getFixedSize()
          Gets the number of bytes used to encode a value if the type is fixed width.
 Class<T> getJavaType()
          Gets the underlying Java type for values of this type.
 int getTypeId()
          Gets the Fudge type identifier.
 int getVariableSize(T value, FudgeTaxonomy taxonomy)
          Gets the number of bytes used to encode a value.
 int hashCode()
          Gets a suitable hash code.
 boolean isVariableSize()
          Checks if the field may contain variable width data.
 T readValue(DataInput input, int dataSize)
          Reads a value of this type to the output.
 String toString()
          Returns a description of the type.
 void writeValue(DataOutput output, T value)
          Writes a value of this type to the output.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FudgeFieldType

public FudgeFieldType(int typeId,
                      Class<T> javaType,
                      boolean isVariableSize,
                      int fixedSize)
Constructs a new type based on the underlying Java type.

The Fudge type identifier must be unique within the FudgeTypeDictionary.

Parameters:
typeId - the type dictionary unique type identifier, from 0 to 255
javaType - the underlying Java type, not null
isVariableSize - true if the field may contain variable width data
fixedSize - the size in bytes if fixed size, zero for variable width
Method Detail

getTypeId

public final int getTypeId()
Gets the Fudge type identifier.

Returns:
the type identifier, from 0 to 255

getJavaType

public final Class<T> getJavaType()
Gets the underlying Java type for values of this type.

Returns:
the equivalent Java type, not null

isVariableSize

public final boolean isVariableSize()
Checks if the field may contain variable width data.

Returns:
true if variable width, false for fixed width

getFixedSize

public final int getFixedSize()
Gets the number of bytes used to encode a value if the type is fixed width.

Returns:
the fixed width size in bytes, zero if variable width

getVariableSize

public int getVariableSize(T value,
                           FudgeTaxonomy taxonomy)
Gets the number of bytes used to encode a value.

A variable width type must override this method. A fixed width type will return the fixed size.

Parameters:
value - the value to check, not used for fixed width types
taxonomy - the taxonomy being used for the encoding, not used for fixed width types
Returns:
the size in bytes

writeValue

public void writeValue(DataOutput output,
                       T value)
                throws IOException
Writes a value of this type to the output.

This is intended for use by variable width types and must write the given value. The implementation must write exactly the number of bytes returned by the size calculation.

Parameters:
output - the output target to write the value to, not null
value - the value to write
Throws:
IOException - if an error occurs, which must be wrapped by the caller

readValue

public T readValue(DataInput input,
                   int dataSize)
            throws IOException
Reads a value of this type to the output.

This is intended for use by variable width types and must read the given value. The implementation must read exactly the number of bytes passed into the method.

Parameters:
input - the input source to read the value from, not null
dataSize - the number of bytes of data to read
Returns:
the value that was read
Throws:
IOException - if an error occurs, which must be wrapped by the caller

equals

public final boolean equals(Object obj)
Checks if this type equals another.

For performance, this only checks the type identifier.

Overrides:
equals in class Object
Parameters:
obj - the object to compare to, null returns false
Returns:
true if equal

hashCode

public final int hashCode()
Gets a suitable hash code.

Overrides:
hashCode in class Object
Returns:
the hash code

toString

public final String toString()
Returns a description of the type.

Overrides:
toString in class Object
Returns:
the descriptive string, not null


Copyright 2009-Present by OpenGamma Inc. and individual contributors
Released under the Apache License, Version 2.0