uk.ac.starlink.array
Class TypeConverter

java.lang.Object
  extended by uk.ac.starlink.array.TypeConverter
All Implemented Interfaces:
Converter

public class TypeConverter
extends 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
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
 void convert12(Object src1, int srcPos, 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(Object src2, int srcPos, 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 conversion
handler1 - a bad value handler for the data at end 1 of the conversion
type2 - primitive type for data at end 2 of the conversion
handler2 - a bad value handler for the data at end 2 of the conversion
func - a Function object representing an additional double 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 conversion
handler1 - a bad value handler for the data at end 1 of the conversion
type2 - primitive type for data at end 2 of the conversion
handler2 - 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.

Specified by:
getType1 in interface Converter
Returns:
type 1

getType2

public Type getType2()
Gets the primitive type for end 2 of the converter.

Specified by:
getType2 in interface Converter
Returns:
type 2

getBadHandler1

public BadHandler getBadHandler1()
Gets the bad value handler for end 1 of the converter.

Specified by:
getBadHandler1 in interface Converter
Returns:
bad value handler 1

getBadHandler2

public BadHandler getBadHandler2()
Gets the bad value handler for end 2 of the converter.

Specified by:
getBadHandler2 in interface Converter
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.

Specified by:
isUnit12 in interface Converter
Returns:
true if the output of 1->2 conversion always equals its input

isUnit21

public boolean isUnit21()
Indicates whether the conversion from type 2 to type 1 is known to be a unit transformation.

Specified by:
isUnit21 in interface Converter
Returns:
true if the output of 2->1 conversion always equals its input

convert12

public void convert12(Object src1,
                      int srcPos,
                      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 interface Converter
Parameters:
src1 - array of type 1 containing input values
srcPos - starting position of elements to convert in src1
dest2 - array of type 2 to reaceive output values
destPos - starting position of elements to write in dest2
length - number of elements to convert

convert21

public void convert21(Object src2,
                      int srcPos,
                      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 interface Converter
Parameters:
src2 - array of type 2 containing input values
srcPos - starting position of elements to convert in src2
dest1 - array of type 1 to reaceive output values
destPos - starting position of elements to write in dest1
length - number of elements to convert


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.