Enum 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.
      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.)
      name - the name of the enum constant to be returned.
      the enum constant with the specified name
      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)
    • numberValue

      public @Nullable Object numberValue(Number value)
      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.
      value - Value to convert.
      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.
      collection - Collection of boxed primitives
      array of primitives
      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.
      array - Array of this primitive type
      String representation of array
    • sortArray

      public void sortArray(Object array)
      Sorts an array of this primitive type.
      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.
      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.
    • 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.
      resultSet - Result set
      i - Ordinal of column (1-based, per JDBC)
    • 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.
      resultSet - Result set
      i - Ordinal of column (1-based, per JDBC)
      sink - Sink
    • 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).