Class DataType

java.lang.Object
org.yamcs.yarch.DataType
Direct Known Subclasses:
ArrayDataType, 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
  • Field Details

  • Constructor Details

  • Method Details

    • tuple

      public static DataType tuple(TupleDefinition td)
    • array

      public static DataType array(DataType elementType)
    • protobuf

      public static DataType protobuf(String className)
    • protobuf

      public static DataType protobuf(Class<? extends com.google.protobuf.MessageLite> clazz)
    • byName

      public static DataType byName(String name) throws IllegalArgumentException
      this is the inverse of name()
      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:
    • capitalized

      public static String capitalized(String s)
    • javaType

      public String javaType()
    • primitiveJavaType

      public String primitiveJavaType()
    • isPrimitiveJavaType

      public boolean isPrimitiveJavaType()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • name

      public String name()
      Returns type as string.
      Returns:
      for basic types returns the enum name for PROTOBUF returns PROTOBUF(className)
    • typeOf

      public static DataType typeOf(Object v)
    • compare

      public static int compare(Object v1, Object v2)
    • castAs

      public static Object castAs(DataType sourceType, DataType targetType, Object v) throws IllegalArgumentException
      Performs casting of v from sourceType to targetType
      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)
    • compatible

      public static boolean compatible(DataType dt1, DataType dt2)
    • getTypeId

      public byte getTypeId()
    • hasEnums

      public boolean hasEnums()
      Return true if this data type is an enum or a composite type (array) containing an enum
    • isComparable

      public boolean isComparable()
      Returns:
      true if two values of this type are comparable (i.e. if they support a natural ordering)