Class TypeHandling


  • public final class TypeHandling
    extends java.lang.Object
    Helper class to provide some formatting of type names.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private TypeHandling()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T cast​(java.lang.Object o, java.lang.Class<T> type)
      Check if an object is of a specified type and cast it to that if possible.
      private static java.lang.String createSizeString​(java.lang.String typeName, int size)  
      static java.lang.Class<?> getClassWithName​(java.lang.String name)
      Return the class object for given type name.
      static java.lang.String getNumericString​(java.lang.Number value)
      Check for missing values, and return the numeric value in string format JMC-6256: JMC doesn't respect Long.MIN_VALUE as a missing value As per the bug report, the following values should be considered "missing" - Integer.MIN_VALUE - Long.MIN_VALUE - Double.NaN - Double.NEGATIVE_INFINITY - Float.NaN - Float.NEGATIVE_INFINITY
      static java.lang.String getValueString​(java.lang.Object value)
      Returns the value in possible augmented way.
      static java.lang.String getVerboseString​(java.lang.Object value)
      Returns a possibly more verbose description of an object.
      private static boolean isMaxTimespan​(java.lang.Object value)  
      private static boolean isMinTimespan​(java.lang.Object value)  
      static boolean isPrimitive​(java.lang.String className)
      Check if a class name represents a primitive type or not.
      static java.lang.String simplifyType​(java.lang.String typeName)
      Returns a simplified description of a type name.
      static java.lang.Class<?> toNonPrimitiveClass​(java.lang.Class<?> primitiveClass)
      Return the non-primitive class corresponding to argument class (int -> Integer).
      • Methods inherited from class java.lang.Object

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

      • formalPrimitiveMap

        private static final java.util.HashMap<java.lang.String,​java.lang.String> formalPrimitiveMap
      • VALUE_COMPOSITE_DATA

        private static final java.lang.String VALUE_COMPOSITE_DATA
        See Also:
        Constant Field Values
      • VALUE_TABULAR_DATA

        private static final java.lang.String VALUE_TABULAR_DATA
        See Also:
        Constant Field Values
      • DOUBLE_NEGATIVE_INFINITY

        private static final java.lang.String DOUBLE_NEGATIVE_INFINITY
        See Also:
        Constant Field Values
      • FLOAT_NEGATIVE_INFINITY

        private static final java.lang.String FLOAT_NEGATIVE_INFINITY
        See Also:
        Constant Field Values
      • INTEGER_MIN_VALUE

        private static final java.lang.String INTEGER_MIN_VALUE
        See Also:
        Constant Field Values
      • primitiveNameToClassMap

        private static java.util.HashMap<java.lang.String,​java.lang.Class<?>> primitiveNameToClassMap
      • primitiveToObjectClassMap

        private static java.util.HashMap<java.lang.Class<?>,​java.lang.Class<?>> primitiveToObjectClassMap
    • Constructor Detail

      • TypeHandling

        private TypeHandling()
    • Method Detail

      • simplifyType

        public static java.lang.String simplifyType​(java.lang.String typeName)
        Returns a simplified description of a type name. This involves transforming type names from their formal descriptors to more human friendly forms, removing package names from certain well-known classes, transforming formal array specified to square brackets etc.
        Parameters:
        typeName - a type name
        Returns:
        a simplified description of the type name
      • createSizeString

        private static java.lang.String createSizeString​(java.lang.String typeName,
                                                         int size)
      • getValueString

        public static java.lang.String getValueString​(java.lang.Object value)
        Returns the value in possible augmented way. It could be viewed as an override of toString().
        Parameters:
        value - the value to textualize
        Returns:
        the value as a string
      • getVerboseString

        public static java.lang.String getVerboseString​(java.lang.Object value)
        Returns a possibly more verbose description of an object. This is similar to getValueString(Object), but can return longer texts.
        Parameters:
        value - the value to textualize
        Returns:
        the value as a string
      • isMinTimespan

        private static boolean isMinTimespan​(java.lang.Object value)
      • isMaxTimespan

        private static boolean isMaxTimespan​(java.lang.Object value)
      • getNumericString

        public static java.lang.String getNumericString​(java.lang.Number value)
        Check for missing values, and return the numeric value in string format JMC-6256: JMC doesn't respect Long.MIN_VALUE as a missing value As per the bug report, the following values should be considered "missing" - Integer.MIN_VALUE - Long.MIN_VALUE - Double.NaN - Double.NEGATIVE_INFINITY - Float.NaN - Float.NEGATIVE_INFINITY
        Parameters:
        value - the numeric value to be converted to a string
        Returns:
        a string with the numeric value, or a N/A message
      • getClassWithName

        public static java.lang.Class<?> getClassWithName​(java.lang.String name)
                                                   throws java.lang.ClassNotFoundException
        Return the class object for given type name.
        Parameters:
        name - the name of the type
        Returns:
        the class object of the type
        Throws:
        java.lang.ClassNotFoundException - if name is an invalid class name
      • toNonPrimitiveClass

        public static java.lang.Class<?> toNonPrimitiveClass​(java.lang.Class<?> primitiveClass)
        Return the non-primitive class corresponding to argument class (int -> Integer).
        Parameters:
        primitiveClass - the class to convert
        Returns:
        the non-primitive class or the argument class if non-primitive
      • isPrimitive

        public static boolean isPrimitive​(java.lang.String className)
        Check if a class name represents a primitive type or not.
        Parameters:
        className - the name to check
        Returns:
        true if the class name represents a primitive type, false otherwise
      • cast

        public static <T> T cast​(java.lang.Object o,
                                 java.lang.Class<T> type)
        Check if an object is of a specified type and cast it to that if possible.
        Parameters:
        o - object to cast
        type - type to cast the object to
        Returns:
        the object cast to the specified type if possible, null if not