Class Primitives


  • public class Primitives
    extends java.lang.Object
    Utilities regarding primitive type and its wrapper class.
    Author:
    henrichen
    • Constructor Summary

      Constructors 
      Constructor Description
      Primitives()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object getDefaultValue​(java.lang.Class cls)
      Returns the default value of a primitive class, or null if it is not a primitive class.
      static char getNotation​(java.lang.String className)
      Returns the notation of a primitive class, or ((char)0) if it is not a primitive class.
      static boolean isPrimitive​(java.lang.String clsName)
      Tests whether a class name is a primitive class, e.g., int and void.
      static java.lang.Class toClass​(java.lang.String clsName)
      Converts a primitive from name to the class, or null if it is not a primitive class.
      static boolean toPrimitive​(java.lang.Boolean obj)
      Convert Boolean object to primitive boolean.
      static byte toPrimitive​(java.lang.Byte obj)
      Convert Byte object to primitive byte.
      static char toPrimitive​(java.lang.Character obj)
      Convert Character object to primitive char.
      static java.lang.Class toPrimitive​(java.lang.Class wrapper)
      Returns the primitive class of the giving wrapper class, or null if it is not a wrapper class.
      static double toPrimitive​(java.lang.Double obj)
      Convert Double object to primitive double.
      static float toPrimitive​(java.lang.Float obj)
      Convert Float object to primitive float.
      static int toPrimitive​(java.lang.Integer obj)
      Convert Integer object to primitive int.
      static long toPrimitive​(java.lang.Long obj)
      Convert Long object to primitive long.
      static short toPrimitive​(java.lang.Short obj)
      Convert Short object to primitive short.
      static java.lang.Boolean toWrapper​(boolean obj)
      Convert primitive boolean to Boolean.
      static java.lang.Byte toWrapper​(byte obj)
      Convert primitive byte to Byte.
      static java.lang.Character toWrapper​(char obj)
      Convert primitive char to Character.
      static java.lang.Double toWrapper​(double obj)
      Convert primitive double to Double.
      static java.lang.Float toWrapper​(float obj)
      Convert primitive float to Float.
      static java.lang.Integer toWrapper​(int obj)
      Convert primitive int to Integer.
      static java.lang.Long toWrapper​(long obj)
      Convert primitive long to Long.
      static java.lang.Short toWrapper​(short obj)
      Convert primitive short to Short.
      static java.lang.Class toWrapper​(java.lang.Class primitive)
      Returns the wrapper class of a primitive class, or null if it is not a primitive class.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Primitives

        public Primitives()
    • Method Detail

      • toPrimitive

        public static final boolean toPrimitive​(java.lang.Boolean obj)
        Convert Boolean object to primitive boolean.
      • toWrapper

        public static final java.lang.Boolean toWrapper​(boolean obj)
        Convert primitive boolean to Boolean.
      • toPrimitive

        public static final byte toPrimitive​(java.lang.Byte obj)
        Convert Byte object to primitive byte.
      • toWrapper

        public static final java.lang.Byte toWrapper​(byte obj)
        Convert primitive byte to Byte.
      • toPrimitive

        public static final char toPrimitive​(java.lang.Character obj)
        Convert Character object to primitive char.
      • toWrapper

        public static final java.lang.Character toWrapper​(char obj)
        Convert primitive char to Character.
      • toPrimitive

        public static final double toPrimitive​(java.lang.Double obj)
        Convert Double object to primitive double.
      • toWrapper

        public static final java.lang.Double toWrapper​(double obj)
        Convert primitive double to Double.
      • toPrimitive

        public static final float toPrimitive​(java.lang.Float obj)
        Convert Float object to primitive float.
      • toWrapper

        public static final java.lang.Float toWrapper​(float obj)
        Convert primitive float to Float.
      • toPrimitive

        public static final int toPrimitive​(java.lang.Integer obj)
        Convert Integer object to primitive int.
      • toWrapper

        public static final java.lang.Integer toWrapper​(int obj)
        Convert primitive int to Integer.
      • toPrimitive

        public static final long toPrimitive​(java.lang.Long obj)
        Convert Long object to primitive long.
      • toWrapper

        public static final java.lang.Long toWrapper​(long obj)
        Convert primitive long to Long.
      • toPrimitive

        public static final short toPrimitive​(java.lang.Short obj)
        Convert Short object to primitive short.
      • toWrapper

        public static final java.lang.Short toWrapper​(short obj)
        Convert primitive short to Short.
      • getNotation

        public static final char getNotation​(java.lang.String className)
        Returns the notation of a primitive class, or ((char)0) if it is not a primitive class. Example, I for int, Z for boolean...
      • getDefaultValue

        public static final java.lang.Object getDefaultValue​(java.lang.Class cls)
        Returns the default value of a primitive class, or null if it is not a primitive class. Example, getDefaultValue(int.class) returns Integer(0).
      • toClass

        public static final java.lang.Class toClass​(java.lang.String clsName)
        Converts a primitive from name to the class, or null if it is not a primitive class.

        Example, toClass("int") returns int.class.

      • toPrimitive

        public static final java.lang.Class toPrimitive​(java.lang.Class wrapper)
        Returns the primitive class of the giving wrapper class, or null if it is not a wrapper class.

        Example, toPrimitive(Integer.class) returns int.class.

      • toWrapper

        public static final java.lang.Class toWrapper​(java.lang.Class primitive)
        Returns the wrapper class of a primitive class, or null if it is not a primitive class.

        Example, toWrapper(int.class) return Integer.class.

      • isPrimitive

        public static final boolean isPrimitive​(java.lang.String clsName)
        Tests whether a class name is a primitive class, e.g., int and void.