org.fudgemsg.types
Class PrimitiveFieldTypesConverter<Target>

java.lang.Object
  extended by org.fudgemsg.types.PrimitiveFieldTypesConverter<Target>
Type Parameters:
Target - primitive field type to convert to
All Implemented Interfaces:
FudgeTypeConverter<Object,Target>

public abstract class PrimitiveFieldTypesConverter<Target>
extends Object
implements FudgeTypeConverter<Object,Target>

Basic conversions between the types defined in PrimitiveFieldTypes. Conversion which will lose data (i.e. out of range) are not permitted and will trigger exceptions. The main use of these is to support field value conversion between the various width integral types.


Field Summary
static PrimitiveFieldTypesConverter<Boolean> BOOLEAN_CONVERTER
          Singleton converter for the Boolean type.
static PrimitiveFieldTypesConverter<Byte> BYTE_CONVERTER
          Singleton converter for the Byte type.
static PrimitiveFieldTypesConverter<Double> DOUBLE_CONVERTER
          Singleton converter for the Double type.
static PrimitiveFieldTypesConverter<Float> FLOAT_CONVERTER
          Singleton converter for the Float type.
static PrimitiveFieldTypesConverter<Integer> INT_CONVERTER
          Singleton converter for the Integer type.
static PrimitiveFieldTypesConverter<Long> LONG_CONVERTER
          Singleton converter for the Long type.
static PrimitiveFieldTypesConverter<Short> SHORT_CONVERTER
          Singleton converter for the Short type.
 
Method Summary
 boolean canConvertPrimary(Class<?> clazz)
          Returns true if this converter can manipulate the requested class.
protected  String getTargetTypeName()
          Returns the descriptive target type name (e.g.
 Target primaryToSecondary(Object value)
          Converts an object to the secondary type this converter supports.
protected  double rangeCheck(double value)
          Checks a value is within the range specified at construction
protected  double rangeCheck(double lo, double hi, double value)
          Checks a value is within the range (inclusive)
protected  int rangeCheck(int value)
          Checks a value is within the range specified at construction.
protected  long rangeCheck(long value)
          Checks a value is within the range specified at construction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BOOLEAN_CONVERTER

public static final PrimitiveFieldTypesConverter<Boolean> BOOLEAN_CONVERTER
Singleton converter for the Boolean type.


BYTE_CONVERTER

public static final PrimitiveFieldTypesConverter<Byte> BYTE_CONVERTER
Singleton converter for the Byte type.


SHORT_CONVERTER

public static final PrimitiveFieldTypesConverter<Short> SHORT_CONVERTER
Singleton converter for the Short type.


INT_CONVERTER

public static final PrimitiveFieldTypesConverter<Integer> INT_CONVERTER
Singleton converter for the Integer type.


LONG_CONVERTER

public static final PrimitiveFieldTypesConverter<Long> LONG_CONVERTER
Singleton converter for the Long type.


FLOAT_CONVERTER

public static final PrimitiveFieldTypesConverter<Float> FLOAT_CONVERTER
Singleton converter for the Float type.


DOUBLE_CONVERTER

public static final PrimitiveFieldTypesConverter<Double> DOUBLE_CONVERTER
Singleton converter for the Double type.

Method Detail

getTargetTypeName

protected String getTargetTypeName()
Returns the descriptive target type name (e.g. for error messages).

Returns:
the target type name

rangeCheck

protected int rangeCheck(int value)
Checks a value is within the range specified at construction.

Parameters:
value - value to check
Returns:
the value
Throws:
IllegalArgumentException - if the value is out of range

rangeCheck

protected long rangeCheck(long value)
Checks a value is within the range specified at construction.

Parameters:
value - value to check
Returns:
the value
Throws:
IllegalArgumentException - if the value is out of range

rangeCheck

protected double rangeCheck(double value)
Checks a value is within the range specified at construction

Parameters:
value - value to check
Returns:
the value
Throws:
IllegalArgumentException - if the value is out of range

rangeCheck

protected double rangeCheck(double lo,
                            double hi,
                            double value)
Checks a value is within the range (inclusive)

Parameters:
lo - lower-bound of the range
hi - upper-bound of the range
value - value to check
Returns:
the value
Throws:
IllegalArgumentException - if the value is out of range

canConvertPrimary

public boolean canConvertPrimary(Class<?> clazz)
Returns true if this converter can manipulate the requested class.

Specified by:
canConvertPrimary in interface FudgeTypeConverter<Object,Target>
Parameters:
clazz - to query
Returns:
true if a call to FudgeTypeConverter.primaryToSecondary(Primary) will succeed, false if it would fail

primaryToSecondary

public Target primaryToSecondary(Object value)
Converts an object to the secondary type this converter supports.

Specified by:
primaryToSecondary in interface FudgeTypeConverter<Object,Target>
Parameters:
value - to convert
Returns:
the converted object


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