Package uk.ac.starlink.array
Class TypeConverter
java.lang.Object
uk.ac.starlink.array.TypeConverter
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionTypeConverter(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
Modifier and TypeMethodDescriptionvoidConverts 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.voidConverts 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.Gets the bad value handler for end 1 of the converter.Gets the bad value handler for end 2 of the converter.getType1()Gets the primitive type for end 1 of the converter.getType2()Gets the primitive type for end 2 of the converter.booleanisUnit12()Indicates whether the conversion from type 1 to type 2 is known to be a unit transformation.booleanisUnit21()Indicates whether the conversion from type 2 to type 1 is known to be a unit transformation.
-
Constructor Details
-
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 additionaldoublefunction 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
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 Details
-
getType1
Gets the primitive type for end 1 of the converter. -
getType2
Gets the primitive type for end 2 of the converter. -
getBadHandler1
Gets the bad value handler for end 1 of the converter.- Specified by:
getBadHandler1in interfaceConverter- Returns:
- bad value handler 1
-
getBadHandler2
Gets the bad value handler for end 2 of the converter.- Specified by:
getBadHandler2in 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
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:
convert12in 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
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:
convert21in 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
-