Package dap4.core.util
Class Convert
- java.lang.Object
-
- dap4.core.util.Convert
-
public abstract class Convert extends Object
This code manages value conversions. The src and target types are specified using DapType. The values themselves are represented as Java typed values. The mapping between DAPType and the Java atomic type system is imperfect because Java does not have unsigned types, so we need to convert to signed value that has the same bits as the unsigned value would have.Additionally: since we need to pass arbitrary values of primitive types, we pass an Object which is assumed to be a vector of the primitive type. So we pass int[] instead of int or Integer. This is because the primitive type values are not a subclass of Object. We could use the wrapper types (e.g. Integer) but using a vector is more closely aligned with the way CDM does it.
-
-
Constructor Summary
Constructors Constructor Description Convert()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Object
convert(DapType dsttype, DapType srctype, Object values)
Convert Object to a value consistent with the given type.protected static long[]
double2long(double[] in)
protected static double[]
long2double(long[] in)
protected static double[]
string2double(String[] in)
protected static long[]
string2long(String[] in)
static DapType
vectorType(Object o)
-
-
-
Method Detail
-
convert
public static Object convert(DapType dsttype, DapType srctype, Object values)
Convert Object to a value consistent with the given type. This is the primary conversion method.- Parameters:
dsttype
- Type to which the object is to be converted.srctype
- Assumed type of the value; must be consistent in sense that if srctype == float32, then e.g value instanceof float[] must be true.values
- The vector of values to convert- Returns:
- converted values as a vector
- Throws:
ConversionException
- if cannot convert (runtime exception)
-
double2long
protected static long[] double2long(double[] in)
-
long2double
protected static double[] long2double(long[] in)
-
string2long
protected static long[] string2long(String[] in)
-
string2double
protected static double[] string2double(String[] in)
-
-