Class TypeUtils

java.lang.Object
io.deephaven.util.type.TypeUtils

public class TypeUtils extends Object
Utility functions to convert primitive types.
  • Field Details

    • PRIMITIVE_TYPES

      public static final Set<Class<?>> PRIMITIVE_TYPES
    • BOXED_TYPES

      public static final Set<Class<?>> BOXED_TYPES
    • primitiveClassNameToClass

      public static final Map<String,Class<?>> primitiveClassNameToClass
  • Constructor Details

    • TypeUtils

      public TypeUtils()
  • Method Details

    • getBoxedType

      public static Class<?> getBoxedType(Class<?> type)
      Returns a reference type corresponding to the given type. If type is itself a reference type, then type is returned. If type is a primitive type, then the appropriate boxed type is returned.
      Parameters:
      type - The type
    • getUnboxedType

      public static Class<?> getUnboxedType(Class<?> type)
      Returns the primitive type corresponding to the given type. If type is itself a primitive type, then type is returned. If type is neither a primitive type nor a boxed type, then null is returned.
      Parameters:
      type - The type
      Returns:
      type's primitive equivalent, or null
    • getUnboxedTypeIfBoxed

      public static Class<?> getUnboxedTypeIfBoxed(@NotNull @NotNull Class<?> type)
      Same as getUnboxedType(Class), but returns non-wrapper classes unmolested.
      Parameters:
      type - The type
      Returns:
      type's unboxed equivalent, or type
    • toByteArray

      public static byte[] toByteArray(float[] array)
    • toByteArray

      public static byte[] toByteArray(int[] array)
    • toByteArray

      public static byte[] toByteArray(short[] array)
    • toByteArray

      public static byte[] toByteArray(long[] array)
    • toByteArray

      public static byte[] toByteArray(double[] array)
    • toFloatArray

      public static float[] toFloatArray(byte[] array)
    • toFloatArray

      public static float[] toFloatArray(int[] array)
    • toFloatArray

      public static float[] toFloatArray(short[] array)
    • toFloatArray

      public static float[] toFloatArray(long[] array)
    • toFloatArray

      public static float[] toFloatArray(double[] array)
    • toShortArray

      public static short[] toShortArray(float[] array)
    • toShortArray

      public static short[] toShortArray(int[] array)
    • toShortArray

      public static short[] toShortArray(byte[] array)
    • toShortArray

      public static short[] toShortArray(long[] array)
    • toShortArray

      public static short[] toShortArray(double[] array)
    • toLongArray

      public static long[] toLongArray(float[] array)
    • toLongArray

      public static long[] toLongArray(int[] array)
    • toLongArray

      public static long[] toLongArray(short[] array)
    • toLongArray

      public static long[] toLongArray(byte[] array)
    • toLongArray

      public static long[] toLongArray(double[] array)
    • toIntArray

      public static int[] toIntArray(float[] array)
    • toIntArray

      public static int[] toIntArray(byte[] array)
    • toIntArray

      public static int[] toIntArray(short[] array)
    • toIntArray

      public static int[] toIntArray(long[] array)
    • toIntArray

      public static int[] toIntArray(double[] array)
    • toDoubleArray

      public static double[] toDoubleArray(float[] array)
    • toDoubleArray

      public static double[] toDoubleArray(int[] array)
    • toDoubleArray

      public static double[] toDoubleArray(short[] array)
    • toDoubleArray

      public static double[] toDoubleArray(long[] array)
    • toDoubleArray

      public static double[] toDoubleArray(double[] array)
    • isConvertibleToPrimitive

      public static boolean isConvertibleToPrimitive(Class<?> type)
    • isBoxedType

      public static boolean isBoxedType(Class<?> exprType)
    • nullConstantForType

      public static String nullConstantForType(Class<?> type)
    • isPrimitiveChar

      public static boolean isPrimitiveChar(@NotNull @NotNull Class<?> c)
      Whether the class is equal to char.class.
      Parameters:
      c - class
      Returns:
      true if c equals char.class, false otherwise
    • isBoxedChar

      public static boolean isBoxedChar(@NotNull @NotNull Class<?> c)
      Whether the class is an instance of Character.class.
      Parameters:
      c - class
      Returns:
      true if Character.class is assignable from c, false otherwise
    • isBoxedInteger

      public static boolean isBoxedInteger(@NotNull @NotNull Class<?> c)
      Whether the class is an instance of Integer.class.
      Parameters:
      c - class
      Returns:
      true if Integer.class is assignable from c, false otherwise
    • isBoxedLong

      public static boolean isBoxedLong(@NotNull @NotNull Class<?> c)
      Whether the class is an instance of Long.class.
      Parameters:
      c - class
      Returns:
      true if Long.class is assignable from c, false otherwise
    • isBoxedShort

      public static boolean isBoxedShort(@NotNull @NotNull Class<?> c)
      Whether the class is an instance of Short.class.
      Parameters:
      c - class
      Returns:
      true if Short.class is assignable from c, false otherwise
    • isBoxedFloat

      public static boolean isBoxedFloat(@NotNull @NotNull Class<?> c)
      Whether the class is an instance of Float.class.
      Parameters:
      c - class
      Returns:
      true if Float.class is assignable from c, false otherwise
    • isBoxedDouble

      public static boolean isBoxedDouble(@NotNull @NotNull Class<?> c)
      Whether the class is an instance of Double.class.
      Parameters:
      c - class
      Returns:
      true if Double.class is assignable from c, false otherwise
    • isBoxedByte

      public static boolean isBoxedByte(@NotNull @NotNull Class<?> c)
      Whether the class is an instance of Byte.class.
      Parameters:
      c - class
      Returns:
      true if Byte.class is assignable from c, false otherwise
    • isBoxedArithmetic

      public static boolean isBoxedArithmetic(@NotNull @NotNull Class<?> c)
      Whether the class is a boxed arithmetic type (Long, Integer, Short, Byte)
      Parameters:
      c - class
      Returns:
      true if the class is a boxed arithmetic type, false otherwise
    • isBoxedBoolean

      public static boolean isBoxedBoolean(@NotNull @NotNull Class<?> c)
      Whether the class is an instance of Boolean.class.
      Parameters:
      c - class
      Returns:
      true if Boolean.class is assignable from c, false otherwise
    • isCharacter

      public static boolean isCharacter(@NotNull @NotNull Class<?> c)
      Whether the class equals char.class or Character.class is assignable from it.
      Parameters:
      c - class
      Returns:
      true if Character.class is assignable from c or c equals char.class
    • isString

      public static boolean isString(Class<?> type)
      Whether the class is a String
      Parameters:
      type - the class
      Returns:
      true if the type is a String, false otherwise
    • isFloatType

      public static boolean isFloatType(Class<?> type)
      Checks if the type is a primitive or Boxed floate type (double or float).
      Parameters:
      type - the class
      Returns:
      true if it is a float type, false otherwise
    • getTypeBoxer

      public static <T> TypeUtils.TypeBoxer<T> getTypeBoxer(Class<T> type)
    • box

      public static Boolean box(Boolean value)
    • box

      public static Byte box(byte value)
    • box

      public static Character box(char value)
    • box

      public static Double box(double value)
    • box

      public static Float box(float value)
    • box

      public static Integer box(int value)
    • box

      public static Long box(long value)
    • box

      public static Short box(short value)
    • unbox

      public static boolean unbox(Boolean value)
    • unbox

      public static byte unbox(Byte value)
    • unbox

      public static char unbox(Character value)
    • unbox

      public static double unbox(Double value)
    • unbox

      public static float unbox(Float value)
    • unbox

      public static int unbox(Integer value)
    • unbox

      public static long unbox(Long value)
    • unbox

      public static short unbox(Short value)