Enum Primitive

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<Primitive>

    public enum Primitive
    extends java.lang.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).

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Primitive.Flavor
      What kind of type?
      static interface  Primitive.Sink
      A place to send a value.
      static interface  Primitive.Source
      A place from which to read a value.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.util.Map<java.lang.Class,​Primitive> BOX_MAP  
      java.lang.Class boxClass  
      java.lang.String boxName  
      java.lang.Object defaultValue
      The default value of this primitive class.
      private int family  
      java.lang.Object max
      The maximum value of this primitive class.
      java.lang.Object maxNegative
      The largest value that is less than zero.
      java.lang.Object min
      The minimum value of this primitive class.
      java.lang.Object minPositive
      The smallest value that is greater than zero.
      private static java.util.Map<java.lang.Class,​Primitive> PRIMITIVE_MAP  
      java.lang.Class primitiveClass  
      java.lang.String primitiveName  
      int size
      The size of a value of this type, in bits.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Primitive​(java.lang.Class primitiveClass, java.lang.Class boxClass, int family, java.lang.Object defaultValue, java.lang.Object min, java.lang.Object maxNegative, java.lang.Object minPositive, java.lang.Object max, int size)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object arrayItem​(java.lang.Object dataSet, int ordinal)
      Gets an item from an array.
      void arrayItem​(java.lang.Object dataSet, int ordinal, Primitive.Sink sink)
      Sends to a sink an from an array.
      void arrayItem​(Primitive.Source source, java.lang.Object dataSet, int ordinal)
      Reads value from a source into an array.
      java.lang.String arrayToString​(java.lang.Object array)
      Converts an array to a string.
      static java.util.List<java.lang.Boolean> asList​(boolean[] elements)
      Adapts an array of boolean into a List of Boolean.
      static java.util.List<java.lang.Byte> asList​(byte[] elements)
      Adapts an array of byte into a List of Byte.
      static java.util.List<java.lang.Character> asList​(char[] elements)
      Adapts an array of char into a List of Character.
      static java.util.List<java.lang.Double> asList​(double[] elements)
      Adapts an array of double into a List of Double.
      static java.util.List<java.lang.Float> asList​(float[] elements)
      Adapts an array of float into a List of Float.
      static java.util.List<java.lang.Integer> asList​(int[] elements)
      Adapts an array of int into a List of Integer.
      static java.util.List<java.lang.Long> asList​(long[] elements)
      Adapts an array of long into a List of Long.
      static java.util.List<java.lang.Short> asList​(short[] elements)
      Adapts an array of short into a List of Short.
      static java.util.List<?> asList​(java.lang.Object array)
      Adapts a primitive array into a List.
      boolean assignableFrom​(Primitive primitive)  
      static java.lang.Class box​(java.lang.Class type)
      Converts a primitive class to a boxed class; returns other classes unchanged.
      static java.lang.reflect.Type box​(java.lang.reflect.Type type)
      Converts a primitive type to a boxed type; returns other types unchanged.
      static Primitive.Flavor flavor​(java.lang.reflect.Type type)
      Returns whether this type is a primitive, box or other type.
      static boolean is​(java.lang.reflect.Type type)
      Returns whether a given type is primitive.
      static boolean isBox​(java.lang.reflect.Type type)
      Returns whether a given type is a box type (e.g.
      boolean isFixedNumeric()
      Returns whether this Primitive is a fixed-point numeric type.
      boolean isNumeric()
      Returns whether this Primitive is a numeric type.
      void jdbc​(java.sql.ResultSet resultSet, int i, Primitive.Sink sink)
      Sends to a sink a value from a given column in a JDBC result set.
      java.lang.Object jdbcGet​(java.sql.ResultSet resultSet, int i)
      Gets a value from a given column in a JDBC result set.
      java.lang.Number number​(java.lang.Number value)
      Creates a number value of this primitive's box type.
      static Primitive of​(java.lang.reflect.Type type)
      Returns the Primitive object for a given primitive class.
      static Primitive ofBox​(java.lang.reflect.Type type)
      Returns the Primitive object for a given boxing class.
      static Primitive ofBoxOr​(java.lang.reflect.Type type)
      Returns the Primitive object for a given primitive or boxing class.
      java.lang.Object parse​(java.lang.String stringValue)
      Calls the appropriate valueOf(String) method.
      java.lang.Object permute​(java.lang.Object array, int[] sources)
      Permutes an array.
      void send​(java.lang.reflect.Field field, java.lang.Object o, Primitive.Sink sink)
      Sends a field value to a sink.
      void send​(Primitive.Source source, Primitive.Sink sink)
      Sends a value from a source to a sink.
      void sortArray​(java.lang.Object array)
      Sorts an array of this primitive type.
      void sortArray​(java.lang.Object array, int fromIndex, int toIndex)
      Sorts a specified range of an array of this primitive type.
      private static void sortBooleanArray​(boolean[] booleans, int fromIndex, int toIndex)  
      java.lang.Object toArray​(java.util.Collection collection)
      Converts a collection of boxed primitives into an array of primitives.
      java.lang.Object toArray2​(java.util.Collection<java.lang.Number> collection)
      Converts a collection of Number to a primitive array.
      static java.lang.Class unbox​(java.lang.Class type)
      Converts a boxed class to a primitive class; returns other types unchanged.
      static java.lang.reflect.Type unbox​(java.lang.reflect.Type type)
      Converts a boxed type to a primitive type; returns other types unchanged.
      static Primitive valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static Primitive[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • primitiveClass

        public final java.lang.Class primitiveClass
      • boxClass

        public final java.lang.Class boxClass
      • primitiveName

        public final java.lang.String primitiveName
      • boxName

        public final java.lang.String boxName
      • family

        private final int family
      • defaultValue

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

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

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

        public final java.lang.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.
      • PRIMITIVE_MAP

        private static final java.util.Map<java.lang.Class,​Primitive> PRIMITIVE_MAP
      • BOX_MAP

        private static final java.util.Map<java.lang.Class,​Primitive> BOX_MAP
    • Constructor Detail

      • Primitive

        private Primitive​(java.lang.Class primitiveClass,
                          java.lang.Class boxClass,
                          int family,
                          java.lang.Object defaultValue,
                          java.lang.Object min,
                          java.lang.Object maxNegative,
                          java.lang.Object minPositive,
                          java.lang.Object max,
                          int size)
    • 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​(java.lang.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:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • of

        public static Primitive of​(java.lang.reflect.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​(java.lang.reflect.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​(java.lang.reflect.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​(java.lang.reflect.Type type)
        Returns whether a given type is primitive.
      • isBox

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

        public static Primitive.Flavor flavor​(java.lang.reflect.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 java.lang.reflect.Type box​(java.lang.reflect.Type type)
        Converts a primitive type to a boxed type; returns other types unchanged.
      • box

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

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

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

        public static java.util.List<?> asList​(java.lang.Object array)
        Adapts a primitive array into a List. For example, asList(new double[2]) returns a List&lt;Double&gt;.
      • asList

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

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

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

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

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

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

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

        public static java.util.List<java.lang.Double> asList​(double[] elements)
        Adapts an array of double into a List of Double.
      • toArray

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

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

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

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

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

        public void sortArray​(java.lang.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)
      • send

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

        public java.lang.Object arrayItem​(java.lang.Object dataSet,
                                          int ordinal)
        Gets an item from an array.
      • arrayItem

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

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

        public java.lang.Object jdbcGet​(java.sql.ResultSet resultSet,
                                        int i)
                                 throws java.sql.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:
        java.sql.SQLException
      • jdbc

        public void jdbc​(java.sql.ResultSet resultSet,
                         int i,
                         Primitive.Sink sink)
                  throws java.sql.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:
        java.sql.SQLException
      • parse

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

        public boolean assignableFrom​(Primitive primitive)
      • number

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