Enum Primitive

    • Field Detail

      • primitiveClass

        public final Class primitiveClass
      • boxClass

        public final Class boxClass
      • primitiveName

        public final String primitiveName
      • family

        private final int family
      • defaultValue

        public final 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 Object min
        The minimum value of this primitive class.
      • maxNegative

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

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

        public final 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 Detail

      • values

        public static Primitive[] values​()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (Primitive c : Primitive.values())
            System.out.println(c);
        
        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 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 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 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.
      • asList

        public static List<?> asList​(Object array)
        Adapts a primitive array into a List. For example, asList(new double[2]) returns a List&lt;Double&gt;.
      • 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<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.
      • 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
      • 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
      • sortBooleanArray

        private static void sortBooleanArray​(boolean[] booleans,
                                             int fromIndex,
                                             int toIndex)
      • arrayItem

        public 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 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
      • 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).