Interface DataType

All Superinterfaces:
Serializable
All Known Implementing Classes:
ArrayType, BooleanType, ByteType, CharType, DateTimeType, DateType, DecimalType, DoubleType, FloatType, IntegerType, LongType, ObjectType, ShortType, StringType, StructType, TimeType

public interface DataType extends Serializable
The interface of data types.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    Data type ID.
  • Method Summary

    Modifier and Type
    Method
    Description
    default DataType
    Returns the boxed data type if this is a primitive type.
    static DataType
    Returns the common type.
    id()
    Returns the type ID enum.
    static DataType
    Infers the type of string.
    default boolean
    Returns true if the type is boolean or Boolean.
    default boolean
    Returns true if the type is byte or Byte.
    default boolean
    Returns true if the type is char or Char.
    default boolean
    Returns true if the type is double or Double.
    static boolean
    Returns true if the given type is of double, either primitive or boxed.
    default boolean
    Returns true if the type is float or Float.
    static boolean
    Returns true if the given type is of float, either primitive or boxed.
    default boolean
    Returns true if the type is float or double.
    default boolean
    Returns true if the type is int or Integer.
    static boolean
    Returns true if the given type is of int, short, byte, char, either primitive or boxed.
    default boolean
    Returns true if the type is int, long, short or byte.
    default boolean
    Returns true if the type is long or Long.
    static boolean
    Returns true if the given type is of long, either primitive or boxed.
    default boolean
    Returns true if the type is numeric (integral or floating).
    default boolean
    Returns true if the type is ObjectType.
    default boolean
    Returns true if this is a primitive data type.
    default boolean
    Returns true if the type is short or Short.
    default boolean
    Returns true if the type is String.
    Returns the type name used in external catalogs.
    static DataType
    of(Class clazz)
    Returns the DataType of a class.
    static DataType
    Returns a DataType from its string representation.
    static DataType
    of(JDBCType type, boolean nullable, String dbms)
    Returns the DataType of a JDBC type.
    static DataType
    Type promotion when apply to expressions.
    default String
    Returns the string representation of a value of the type.
    default DataType
    Returns the unboxed data type if this is a boxed primitive type.
    Returns the value from its string representation.
  • Method Details

    • name

      String name()
      Returns the type name used in external catalogs. DataType.of(name()) should return the same type.
      Returns:
      the type name used in external catalogs.
    • id

      Returns the type ID enum.
      Returns:
      the type ID enum.
    • valueOf

      Object valueOf(String s)
      Returns the value from its string representation.
      Parameters:
      s - the string representation of a value of this type.
      Returns:
      the value.
    • toString

      default String toString(Object o)
      Returns the string representation of a value of the type.
      Parameters:
      o - the value.
      Returns:
      the string representation
    • isPrimitive

      default boolean isPrimitive()
      Returns true if this is a primitive data type.
      Returns:
      true if this is a primitive data type.
    • isFloating

      default boolean isFloating()
      Returns true if the type is float or double.
      Returns:
      true if the type is float or double.
    • isIntegral

      default boolean isIntegral()
      Returns true if the type is int, long, short or byte.
      Returns:
      true if the type is int, long, short or byte.
    • isNumeric

      default boolean isNumeric()
      Returns true if the type is numeric (integral or floating).
      Returns:
      true if the type is numeric (integral or floating).
    • isBoolean

      default boolean isBoolean()
      Returns true if the type is boolean or Boolean.
      Returns:
      true if the type is boolean or Boolean.
    • isChar

      default boolean isChar()
      Returns true if the type is char or Char.
      Returns:
      true if the type is char or Char.
    • isByte

      default boolean isByte()
      Returns true if the type is byte or Byte.
      Returns:
      true if the type is byte or Byte.
    • isShort

      default boolean isShort()
      Returns true if the type is short or Short.
      Returns:
      true if the type is short or Short.
    • isInt

      default boolean isInt()
      Returns true if the type is int or Integer.
      Returns:
      true if the type is int or Integer.
    • isLong

      default boolean isLong()
      Returns true if the type is long or Long.
      Returns:
      true if the type is long or Long.
    • isFloat

      default boolean isFloat()
      Returns true if the type is float or Float.
      Returns:
      true if the type is float or Float.
    • isDouble

      default boolean isDouble()
      Returns true if the type is double or Double.
      Returns:
      true if the type is double or Double.
    • isString

      default boolean isString()
      Returns true if the type is String.
      Returns:
      true if the type is String.
    • isObject

      default boolean isObject()
      Returns true if the type is ObjectType.
      Returns:
      true if the type is ObjectType.
    • boxed

      default DataType boxed()
      Returns the boxed data type if this is a primitive type. Otherwise, return this type.
      Returns:
      the boxed data type.
    • unboxed

      default DataType unboxed()
      Returns the unboxed data type if this is a boxed primitive type. Otherwise, return this type.
      Returns:
      the unboxed data type.
    • infer

      static DataType infer(String s)
      Infers the type of string.
      Parameters:
      s - the string value.
      Returns:
      the inferred data type of string value.
    • of

      static DataType of(String s) throws ClassNotFoundException
      Returns a DataType from its string representation.
      Parameters:
      s - the string representation of data type.
      Returns:
      the data type.
      Throws:
      ClassNotFoundException - when fails to load a class.
    • of

      static DataType of(Class clazz)
      Returns the DataType of a class.
      Parameters:
      clazz - the Class object.
      Returns:
      Smile data type.
    • of

      static DataType of(JDBCType type, boolean nullable, String dbms)
      Returns the DataType of a JDBC type.
      Parameters:
      type - the JDBC data type.
      nullable - true if the column value may be null.
      dbms - The database product name.
      Returns:
      Smile data type.
    • prompt

      static DataType prompt(DataType a, DataType b)
      Type promotion when apply to expressions. First, all byte, short, and char values are promoted to int. Then, if one operand is a long, the whole expression is promoted to long. If one operand is a float, the entire expression is promoted to float. If any of the operands is double, the result is double.
      Parameters:
      a - the data type.
      b - the data type.
      Returns:
      the promoted type.
    • coerce

      static DataType coerce(DataType a, DataType b)
      Returns the common type. This method is intended to be used for inferring the schema from text files. This is NOT a general implementation of type coercion.
      Parameters:
      a - the data type.
      b - the data type.
      Returns:
      the common type.
    • isInt

      static boolean isInt(DataType t)
      Returns true if the given type is of int, short, byte, char, either primitive or boxed.
      Parameters:
      t - the data type.
      Returns:
      true if the given type is of int.
    • isLong

      static boolean isLong(DataType t)
      Returns true if the given type is of long, either primitive or boxed.
      Parameters:
      t - the data type.
      Returns:
      true if the given type is of long.
    • isFloat

      static boolean isFloat(DataType t)
      Returns true if the given type is of float, either primitive or boxed.
      Parameters:
      t - the data type.
      Returns:
      true if the given type is of float.
    • isDouble

      static boolean isDouble(DataType t)
      Returns true if the given type is of double, either primitive or boxed.
      Parameters:
      t - the data type.
      Returns:
      true if the given type is of double.