Enum Primitive

java.lang.Object
java.lang.Enum<Primitive>
org.apache.calcite.linq4j.tree.Primitive
All Implemented Interfaces:
Serializable, Comparable<Primitive>, Constable

public enum Primitive extends Enum<Primitive>
Enumeration of Java's primitive types.

There are fields for the native class (e.g. int, also known as Integer.TYPE) and the boxing class (e.g. Integer).

  • Enum Constant Details

  • Field Details

    • primitiveClass

      public final @Nullable Class primitiveClass
    • boxClass

      public final @Nullable Class boxClass
    • primitiveName

      public final @Nullable String primitiveName
    • boxName

      public final @Nullable String boxName
    • defaultValue

      public final @Nullable Object defaultValue
      The default value of this primitive class. This is the value taken by uninitialized fields, for instance; 0 for int, false for boolean, etc.
    • min

      public final @Nullable Object min
      The minimum value of this primitive class.
    • maxNegative

      public final @Nullable Object maxNegative
      The largest value that is less than zero. Null if not applicable for this type.
    • minPositive

      public final @Nullable Object minPositive
      The smallest value that is greater than zero. Null if not applicable for this type.
    • max

      public final @Nullable Object max
      The maximum value of this primitive class.
    • size

      public final int size
      The size of a value of this type, in bits. Null if not applicable for this type.
  • Method Details

    • values

      public static Primitive[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static Primitive valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • of

      public static @Nullable Primitive of(Type type)
      Returns the Primitive object for a given primitive class.

      For example, of(long.class) returns LONG. Returns null when applied to a boxing or other class; for example of(Long.class) and of(String.class) return null.

    • ofBox

      public static @Nullable Primitive ofBox(Type type)
      Returns the Primitive object for a given boxing class.

      For example, ofBox(java.util.Long.class) returns LONG.

    • ofBoxOr

      public static @Nullable Primitive ofBoxOr(Type type)
      Returns the Primitive object for a given primitive or boxing class.

      For example, ofBoxOr(Long.class) and ofBoxOr(long.class) both return LONG.

    • is

      public static boolean is(Type type)
      Returns whether a given type is primitive.
    • isBox

      public static boolean isBox(Type type)
      Returns whether a given type is a box type (e.g. Integer).
    • flavor

      public static Primitive.Flavor flavor(Type type)
      Returns whether this type is a primitive, box or other type. Useful for switch statements.
    • isNumeric

      public boolean isNumeric()
      Returns whether this Primitive is a numeric type.
    • isFixedNumeric

      public boolean isFixedNumeric()
      Returns whether this Primitive is a fixed-point numeric type.
    • box

      public static Type box(Type type)
      Converts a primitive type to a boxed type; returns other types unchanged.
    • box

      public static Class box(Class type)
      Converts a primitive class to a boxed class; returns other classes unchanged.
    • unbox

      public static Type unbox(Type type)
      Converts a boxed type to a primitive type; returns other types unchanged.
    • unbox

      public static Class unbox(Class type)
      Converts a boxed class to a primitive class; returns other types unchanged.
    • getPrimitiveClass

      @API(since="1.27", status=EXPERIMENTAL) public Class<?> getPrimitiveClass()
    • getBoxClass

      @API(since="1.27", status=EXPERIMENTAL) public Class<?> getBoxClass()
    • getPrimitiveName

      @API(since="1.27", status=EXPERIMENTAL) public String getPrimitiveName()
    • getBoxName

      @API(since="1.27", status=EXPERIMENTAL) public String getBoxName()
    • asList

      public static List<?> asList(Object array)
      Adapts a primitive array into a List. For example, asList(new double[2]) returns a List<Double>.
    • asList

      public static List<Boolean> asList(boolean[] elements)
      Adapts an array of boolean into a List of Boolean.
    • asList

      public static List<Byte> asList(byte[] elements)
      Adapts an array of byte into a List of Byte.
    • asList

      public static List<Character> asList(char[] elements)
      Adapts an array of char into a List of Character.
    • asList

      public static List<Short> asList(short[] elements)
      Adapts an array of short into a List of Short.
    • asList

      public static List<Integer> asList(int[] elements)
      Adapts an array of int into a List of Integer.
    • asList

      public static List<Long> asList(long[] elements)
      Adapts an array of long into a List of Long.
    • asList

      public static List<Float> asList(float[] elements)
      Adapts an array of float into a List of Float.
    • asList

      public static List<Double> asList(double[] elements)
      Adapts an array of double into a List of Double.
    • integerCast

      public static @Nullable Object integerCast(Primitive primitive, Object value)
      Called from BuiltInMethod.INTEGER_CAST
    • integerCast

      public static @Nullable Object integerCast(Primitive primitive, Object value, RoundingMode roundingMode)
      Called from BuiltInMethod.INTEGER_CAST_ROUNDING_MODE
    • charToDecimalCast

      public static @Nullable Object charToDecimalCast(@Nullable String value, int precision, int scale)
      Called from BuiltInMethod.CHAR_DECIMAL_CAST
    • charToDecimalCast

      public static @Nullable Object charToDecimalCast(@Nullable String value, int precision, int scale, RoundingMode roundingMode)
      Called from BuiltInMethod.CHAR_DECIMAL_CAST_ROUNDING_MODE
    • shortIntervalToDecimalCast

      public static @Nullable Object shortIntervalToDecimalCast(@Nullable Long value, int precision, int scale, BigDecimal unitScale)
      Convert a short time interval to a decimal value. Called from BuiltInMethod.SHORT_INTERVAL_DECIMAL_CAST.
      Parameters:
      unitScale - Scale describing source interval type
    • shortIntervalToDecimalCast

      public static @Nullable Object shortIntervalToDecimalCast(@Nullable Long value, int precision, int scale, BigDecimal unitScale, RoundingMode roundingMode)
      Convert a short time interval to a decimal value. Called from BuiltInMethod.SHORT_INTERVAL_DECIMAL_CAST_ROUNDING_MODE.
      Parameters:
      unitScale - Scale describing source interval type
    • longIntervalToDecimalCast

      public static @Nullable Object longIntervalToDecimalCast(@Nullable Integer value, int precision, int scale, BigDecimal unitScale)
      Convert a long time interval to a decimal value. Called from BuiltInMethod.LONG_INTERVAL_DECIMAL_CAST.
      Parameters:
      unitScale - Scale describing source interval type
    • longIntervalToDecimalCast

      public static @Nullable Object longIntervalToDecimalCast(@Nullable Integer value, int precision, int scale, BigDecimal unitScale, RoundingMode roundingMode)
      Convert a long time interval to a decimal value. Called from BuiltInMethod.LONG_INTERVAL_DECIMAL_CAST_ROUNDING_MODE.
      Parameters:
      unitScale - Scale describing source interval type
    • decimalDecimalCast

      public static @Nullable Object decimalDecimalCast(@Nullable BigDecimal value, int precision, int scale)
      Called from BuiltInMethod.DECIMAL_DECIMAL_CAST
    • decimalDecimalCast

      public static @Nullable Object decimalDecimalCast(@Nullable BigDecimal value, int precision, int scale, RoundingMode roundingMode)
      Called from BuiltInMethod.DECIMAL_DECIMAL_CAST_ROUNDING_MODE
    • integerDecimalCast

      public static @Nullable Object integerDecimalCast(@Nullable Number value, int precision, int scale)
      Called from BuiltInMethod.INTEGER_DECIMAL_CAST
    • integerDecimalCast

      public static @Nullable Object integerDecimalCast(@Nullable Number value, int precision, int scale, RoundingMode roundingMode)
      Called from BuiltInMethod.INTEGER_DECIMAL_CAST_ROUNDING_MODE
    • fpDecimalCast

      public static @Nullable Object fpDecimalCast(@Nullable Number value, int precision, int scale)
      Called from BuiltInMethod.FP_DECIMAL_CAST
    • fpDecimalCast

      public static @Nullable Object fpDecimalCast(@Nullable Number value, int precision, int scale, RoundingMode roundingMode)
      Called from BuiltInMethod.FP_DECIMAL_CAST_ROUNDING_MODE
    • numberValueRoundDown

      public @Nullable Object numberValueRoundDown(Number value)
    • numberValue

      public @Nullable Object numberValue(Number value, RoundingMode roundingMode)
      Converts a number into a value of the type specified by this primitive using the SQL CAST rules. If the value conversion causes loss of significant digits, an exception is thrown.
      Parameters:
      value - Value to convert.
      roundingMode - Rounding behavior.
      Returns:
      The converted value, or null if the type of the result is not a number.
    • toArray

      public Object toArray(Collection collection)
      Converts a collection of boxed primitives into an array of primitives.
      Parameters:
      collection - Collection of boxed primitives
      Returns:
      array of primitives
      Throws:
      ClassCastException - if any element is not of the box type
      NullPointerException - if any element is null
    • toArray2

      public Object toArray2(Collection<Number> collection)
      Converts a collection of Number to a primitive array.
    • permute

      public Object permute(Object array, int[] sources)
      Permutes an array.
    • arrayToString

      public String arrayToString(Object array)
      Converts an array to a string.
      Parameters:
      array - Array of this primitive type
      Returns:
      String representation of array
    • sortArray

      public void sortArray(Object array)
      Sorts an array of this primitive type.
      Parameters:
      array - Array of this primitive type
    • sortArray

      public void sortArray(Object array, int fromIndex, int toIndex)
      Sorts a specified range of an array of this primitive type.
      Parameters:
      array - Array of this primitive type
      fromIndex - the index of the first element, inclusive, to be sorted
      toIndex - the index of the last element, exclusive, to be sorted
    • send

      public void send(Field field, Object o, Primitive.Sink sink) throws IllegalAccessException
      Sends a field value to a sink.
      Throws:
      IllegalAccessException
    • arrayItem

      public @Nullable Object arrayItem(Object dataSet, int ordinal)
      Gets an item from an array.
    • arrayItem

      public void arrayItem(Primitive.Source source, Object dataSet, int ordinal)
      Reads value from a source into an array.
    • arrayItem

      public void arrayItem(Object dataSet, int ordinal, Primitive.Sink sink)
      Sends to a sink an from an array.
    • jdbcGet

      public @Nullable Object jdbcGet(ResultSet resultSet, int i) throws SQLException
      Gets a value from a given column in a JDBC result set.
      Parameters:
      resultSet - Result set
      i - Ordinal of column (1-based, per JDBC)
      Throws:
      SQLException
    • jdbc

      public void jdbc(ResultSet resultSet, int i, Primitive.Sink sink) throws SQLException
      Sends to a sink a value from a given column in a JDBC result set.
      Parameters:
      resultSet - Result set
      i - Ordinal of column (1-based, per JDBC)
      sink - Sink
      Throws:
      SQLException
    • send

      public void send(Primitive.Source source, Primitive.Sink sink)
      Sends a value from a source to a sink.
    • parse

      public Object parse(String stringValue)
      Calls the appropriate valueOf(String) method.
    • assignableFrom

      public boolean assignableFrom(Primitive primitive)
    • number

      public Number number(Number value)
      Creates a number value of this primitive's box type. For example, SHORT.number(Integer(0)) will return Short(0).