Package uk.ac.starlink.array
Class TypeConverter
- java.lang.Object
-
- uk.ac.starlink.array.TypeConverter
-
- All Implemented Interfaces:
Converter
public class TypeConverter extends java.lang.Object implements Converter
A Converter which converts between primitive types, optionally passing the values through a real function. Bad value propagation is taken care of, and conversion overflows lead to bad values in the output data.- Version:
- $Id$
- Author:
- Mark Taylor (Starlink)
-
-
Constructor Summary
Constructors Constructor Description TypeConverter(Type type1, BadHandler handler1, Type type2, BadHandler handler2)
Creates a converter from one primitive type to another.TypeConverter(Type type1, BadHandler handler1, Type type2, BadHandler handler2, Function func)
Creates a converter from one primitive type to another, which will pass the values through a real function prior to doing the type conversion.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
convert12(java.lang.Object src1, int srcPos, java.lang.Object dest2, int destPos, int length)
Converts a sequence of elements in an array of type 1 and places the results in a sequence of elements in an array of type 2.void
convert21(java.lang.Object src2, int srcPos, java.lang.Object dest1, int destPos, int length)
Converts a sequence of elements in an array of type 2 and places the results in a sequence of elements in an array of type 1.BadHandler
getBadHandler1()
Gets the bad value handler for end 1 of the converter.BadHandler
getBadHandler2()
Gets the bad value handler for end 2 of the converter.Type
getType1()
Gets the primitive type for end 1 of the converter.Type
getType2()
Gets the primitive type for end 2 of the converter.boolean
isUnit12()
Indicates whether the conversion from type 1 to type 2 is known to be a unit transformation.boolean
isUnit21()
Indicates whether the conversion from type 2 to type 1 is known to be a unit transformation.
-
-
-
Constructor Detail
-
TypeConverter
public TypeConverter(Type type1, BadHandler handler1, Type type2, BadHandler handler2, Function func)
Creates a converter from one primitive type to another, which will pass the values through a real function prior to doing the type conversion.- Parameters:
type1
- primitive type for data at end 1 of the conversionhandler1
- a bad value handler for the data at end 1 of the conversiontype2
- primitive type for data at end 2 of the conversionhandler2
- a bad value handler for the data at end 2 of the conversionfunc
- a Function object representing an additionaldouble
function to apply to values in addition to the type conversion. The forward mapping will be used for 1->2 conversions, and the inverse one for 2->1 conversions. If null, a unit function is used (efficiently)
-
TypeConverter
public TypeConverter(Type type1, BadHandler handler1, Type type2, BadHandler handler2)
Creates a converter from one primitive type to another.- Parameters:
type1
- primitive type for data at end 1 of the conversionhandler1
- a bad value handler for the data at end 1 of the conversiontype2
- primitive type for data at end 2 of the conversionhandler2
- a bad value handler for the data at end 2 of the conversion
-
-
Method Detail
-
getType1
public Type getType1()
Gets the primitive type for end 1 of the converter.
-
getType2
public Type getType2()
Gets the primitive type for end 2 of the converter.
-
getBadHandler1
public BadHandler getBadHandler1()
Gets the bad value handler for end 1 of the converter.- Specified by:
getBadHandler1
in interfaceConverter
- Returns:
- bad value handler 1
-
getBadHandler2
public BadHandler getBadHandler2()
Gets the bad value handler for end 2 of the converter.- Specified by:
getBadHandler2
in interfaceConverter
- Returns:
- bad value handler 2
-
isUnit12
public boolean isUnit12()
Indicates whether the conversion from type 1 to type 2 is known to be a unit transformation.
-
isUnit21
public boolean isUnit21()
Indicates whether the conversion from type 2 to type 1 is known to be a unit transformation.
-
convert12
public void convert12(java.lang.Object src1, int srcPos, java.lang.Object dest2, int destPos, int length)
Converts a sequence of elements in an array of type 1 and places the results in a sequence of elements in an array of type 2.- Specified by:
convert12
in interfaceConverter
- Parameters:
src1
- array of type 1 containing input valuessrcPos
- starting position of elements to convert in src1dest2
- array of type 2 to reaceive output valuesdestPos
- starting position of elements to write in dest2length
- number of elements to convert
-
convert21
public void convert21(java.lang.Object src2, int srcPos, java.lang.Object dest1, int destPos, int length)
Converts a sequence of elements in an array of type 2 and places the results in a sequence of elements in an array of type 1.- Specified by:
convert21
in interfaceConverter
- Parameters:
src2
- array of type 2 containing input valuessrcPos
- starting position of elements to convert in src2dest1
- array of type 1 to reaceive output valuesdestPos
- starting position of elements to write in dest1length
- number of elements to convert
-
-