Package org.yamcs.yarch
Class DataType
- java.lang.Object
-
- org.yamcs.yarch.DataType
-
- Direct Known Subclasses:
ListDataType
,ProtobufDataType
,TupleDataType
public class DataType extends Object
Types supported by yarch. Currently TUPLE and LIST do now work well. ENUM is just like String, except that when it's stored on disk a two bytes integer value from a map is stored instead of the String. (maximum allowed version is 2^16 (which is anyway too big considering that the map is stored as serialised yaml file) PROTOBUF is a Google Protocol Buffer message
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DataType._type
-
Field Summary
Fields Modifier and Type Field Description static DataType
BINARY
static DataType
BOOLEAN
static DataType
BYTE
static DataType
DOUBLE
static DataType
ENUM
static DataType
HRES_TIMESTAMP
static DataType
INT
static byte
LIST_ID
static DataType
LONG
static DataType
PARAMETER_VALUE
static byte
PROTOBUF_ID
static DataType
SHORT
static DataType
STRING
static DataType
TIMESTAMP
static byte
TUPLE_ID
static DataType
UUID
DataType._type
val
-
Constructor Summary
Constructors Modifier Constructor Description protected
DataType(DataType._type t, byte id)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DataType
byName(String name)
this is the inverse ofname()
static String
capitalized(String s)
static Object
castAs(DataType targetType, Object v)
Performs casting: numbers to numbers numbers to string string to numbersstatic Object
castAs(DataType sourceType, DataType targetType, Object v)
Performs casting of v from type1 to type2static int
compare(Object v1, Object v2)
static boolean
compatible(DataType dt1, DataType dt2)
static int
getSerializedSize(DataType dt)
return the size in bytes of the encoded data type if it can be encoded on fixed size, or -1 if not.byte
getTypeId()
static boolean
isComparable(DataType dt)
static boolean
isNumber(DataType dt)
String
javaType()
static DataType
list(TupleDefinition td)
String
name()
Returns type as string.String
primitiveJavaType()
static DataType
protobuf(String className)
String
toString()
static DataType
tuple(TupleDefinition td)
static DataType
typeOf(Object v)
-
-
-
Field Detail
-
val
public final DataType._type val
-
BYTE
public static final DataType BYTE
-
SHORT
public static final DataType SHORT
-
INT
public static final DataType INT
-
LONG
public static final DataType LONG
-
DOUBLE
public static final DataType DOUBLE
-
STRING
public static final DataType STRING
-
BINARY
public static final DataType BINARY
-
BOOLEAN
public static final DataType BOOLEAN
-
TIMESTAMP
public static final DataType TIMESTAMP
-
ENUM
public static final DataType ENUM
-
PARAMETER_VALUE
public static final DataType PARAMETER_VALUE
-
PROTOBUF_ID
public static final byte PROTOBUF_ID
- See Also:
- Constant Field Values
-
TUPLE_ID
public static final byte TUPLE_ID
- See Also:
- Constant Field Values
-
LIST_ID
public static final byte LIST_ID
- See Also:
- Constant Field Values
-
HRES_TIMESTAMP
public static final DataType HRES_TIMESTAMP
-
UUID
public static final DataType UUID
-
-
Constructor Detail
-
DataType
protected DataType(DataType._type t, byte id)
-
-
Method Detail
-
tuple
public static DataType tuple(TupleDefinition td)
-
list
public static DataType list(TupleDefinition td)
-
byName
public static DataType byName(String name) throws IllegalArgumentException
this is the inverse ofname()
- Parameters:
name
-- Returns:
- the DataType corresponding to the name
- Throws:
IllegalArgumentException
- thrown in case the name is invalid
-
getSerializedSize
public static int getSerializedSize(DataType dt)
return the size in bytes of the encoded data type if it can be encoded on fixed size, or -1 if not.- Parameters:
dt
-- Returns:
-
javaType
public String javaType()
-
primitiveJavaType
public String primitiveJavaType()
-
name
public String name()
Returns type as string.- Returns:
- for basic types returns the enum name for PROTOBUF returns PROTOBUF(className)
-
castAs
public static Object castAs(DataType sourceType, DataType targetType, Object v) throws IllegalArgumentException
Performs casting of v from type1 to type2- Parameters:
sourceType
-targetType
-v
-- Returns:
- the casted object (can be v if no casting is performed)
- Throws:
IllegalArgumentException
-
castAs
public static Object castAs(DataType targetType, Object v) throws IllegalArgumentException
Performs casting: numbers to numbers numbers to string string to numbers- Parameters:
targetType
-v
-- Returns:
- the casted object (can be to v if no casting is performed)
- Throws:
IllegalArgumentException
-
isNumber
public static boolean isNumber(DataType dt)
-
isComparable
public static boolean isComparable(DataType dt)
-
getTypeId
public byte getTypeId()
-
-