Class ObjectType


  • public class ObjectType
    extends java.lang.Object
    Utilities for analyzing and converting Object types in Java Takes advantage of reflection
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ObjectType.NullObject  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String LANG_PACKAGE  
      static java.lang.Object NULL  
      static java.lang.String SQL_PACKAGE  
    • Constructor Summary

      Constructors 
      Constructor Description
      ObjectType()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Boolean doRealCompare​(java.lang.Object value1, java.lang.Object value2, java.lang.String operator, java.lang.String type, java.lang.String format, java.util.List<java.lang.Object> messages, java.util.Locale locale, java.lang.ClassLoader loader, boolean value2InlineConstant)  
      static java.lang.Object getInstance​(java.lang.String className)
      Returns an instance of the specified class.
      static boolean instanceOf​(java.lang.Class<?> objectClass, java.lang.String typeName)
      Tests if a class is a class of a sub-class of or properly implements an interface.
      static boolean instanceOf​(java.lang.Class<?> objectClass, java.lang.String typeName, java.lang.ClassLoader loader)
      Tests if a class is a class of a sub-class of or properly implements an interface.
      static boolean instanceOf​(java.lang.Object obj, java.lang.String typeName)
      Tests if an object is an instance of a sub-class of or properly implements an interface.
      static boolean instanceOf​(java.lang.Object obj, java.lang.String typeName, java.lang.ClassLoader loader)
      Tests if an object is an instance of a sub-class of or properly implements an interface.
      static boolean isEmpty​(java.lang.Object value)  
      static java.lang.Class<?> loadClass​(java.lang.String className)
      Loads a class with the current thread's context classloader.
      static java.lang.Class<?> loadClass​(java.lang.String className, java.lang.ClassLoader loader)
      Loads a class with the specified classloader.
      static java.lang.Class<?> loadInfoClass​(java.lang.String typeName, java.lang.ClassLoader loader)  
      static java.lang.Object simpleTypeOrObjectConvert​(java.lang.Object obj, java.lang.String type, java.lang.String format, java.util.Locale locale)
      static java.lang.Object simpleTypeOrObjectConvert​(java.lang.Object obj, java.lang.String type, java.lang.String format, java.util.Locale locale, boolean noTypeFail)
      static java.lang.Object simpleTypeOrObjectConvert​(java.lang.Object obj, java.lang.String type, java.lang.String format, java.util.TimeZone timeZone, java.util.Locale locale, boolean noTypeFail)
      Converts the passed object to the named type.
      • Methods inherited from class java.lang.Object

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

      • NULL

        public static final java.lang.Object NULL
    • Constructor Detail

      • ObjectType

        public ObjectType()
    • Method Detail

      • loadClass

        public static java.lang.Class<?> loadClass​(java.lang.String className)
                                            throws java.lang.ClassNotFoundException
        Loads a class with the current thread's context classloader.
        Parameters:
        className - The name of the class to load
        Returns:
        The requested class
        Throws:
        java.lang.ClassNotFoundException
      • loadClass

        public static java.lang.Class<?> loadClass​(java.lang.String className,
                                                   java.lang.ClassLoader loader)
                                            throws java.lang.ClassNotFoundException
        Loads a class with the specified classloader.
        Parameters:
        className - The name of the class to load
        loader - The ClassLoader to use
        Returns:
        The requested class
        Throws:
        java.lang.ClassNotFoundException
      • getInstance

        public static java.lang.Object getInstance​(java.lang.String className)
                                            throws java.lang.ClassNotFoundException,
                                                   java.lang.InstantiationException,
                                                   java.lang.IllegalAccessException,
                                                   java.lang.NoSuchMethodException,
                                                   java.lang.reflect.InvocationTargetException
        Returns an instance of the specified class. This uses the default no-arg constructor to create the instance.
        Parameters:
        className - Name of the class to instantiate
        Returns:
        An instance of the named class
        Throws:
        java.lang.ClassNotFoundException
        java.lang.InstantiationException
        java.lang.IllegalAccessException
        java.lang.NoSuchMethodException
        java.lang.reflect.InvocationTargetException
      • instanceOf

        public static boolean instanceOf​(java.lang.Class<?> objectClass,
                                         java.lang.String typeName)
        Tests if a class is a class of a sub-class of or properly implements an interface.
        Parameters:
        objectClass - Class to test
        typeName - name to test against
        Returns:
        true if objectClass is a class or a sub-class of, or properly implements an interface
      • instanceOf

        public static boolean instanceOf​(java.lang.Object obj,
                                         java.lang.String typeName)
        Tests if an object is an instance of a sub-class of or properly implements an interface.
        Parameters:
        obj - Object to test
        typeName - name to test against
        Returns:
        true if obj is an instance of a sub-class of, or properly implements an interface
      • instanceOf

        public static boolean instanceOf​(java.lang.Class<?> objectClass,
                                         java.lang.String typeName,
                                         java.lang.ClassLoader loader)
        Tests if a class is a class of a sub-class of or properly implements an interface.
        Parameters:
        objectClass - Class to test
        typeName - Object to test against
        loader -
        Returns:
        true if objectClass is a class of a sub-class of, or properly implements an interface
      • instanceOf

        public static boolean instanceOf​(java.lang.Object obj,
                                         java.lang.String typeName,
                                         java.lang.ClassLoader loader)
        Tests if an object is an instance of a sub-class of or properly implements an interface.
        Parameters:
        obj - Object to test
        typeName - Object to test against
        loader -
        Returns:
        true if obj is an instance of a sub-class of, or properly implements an interface
      • loadInfoClass

        public static java.lang.Class<?> loadInfoClass​(java.lang.String typeName,
                                                       java.lang.ClassLoader loader)
      • simpleTypeOrObjectConvert

        public static java.lang.Object simpleTypeOrObjectConvert​(java.lang.Object obj,
                                                                 java.lang.String type,
                                                                 java.lang.String format,
                                                                 java.util.TimeZone timeZone,
                                                                 java.util.Locale locale,
                                                                 boolean noTypeFail)
                                                          throws GeneralException
        Converts the passed object to the named type. Initially created for only simple types but actually handle more types and not all simple types. See ObjectTypeTests class for more, and (normally) up to date information Supported types: - All PRIMITIVES - Simple types: String, Boolean, Double, Float, Long, Integer, BigDecimal. - Other Objects: List, Map, Set, Calendar, Date (java.sql.Date), Time, Timestamp, TimeZone, Date (util.Date and sql.Date) - Simple types (maybe) not handled: Short, BigInteger, Byte, Character, ObjectName and Void...
        Parameters:
        obj - Object to convert
        type - Optional Java class name of type to convert to. A null or empty String will return the original object.
        format - Optional (can be null) format string for Date, Time, Timestamp
        timeZone - Optional (can be null) TimeZone for converting dates and times
        locale - Optional (can be null) Locale for formatting and parsing Double, Float, Long, Integer
        noTypeFail - Fail (Exception) when no type conversion is available, false will return the primary object
        Returns:
        the converted value
        Throws:
        GeneralException
      • doRealCompare

        public static java.lang.Boolean doRealCompare​(java.lang.Object value1,
                                                      java.lang.Object value2,
                                                      java.lang.String operator,
                                                      java.lang.String type,
                                                      java.lang.String format,
                                                      java.util.List<java.lang.Object> messages,
                                                      java.util.Locale locale,
                                                      java.lang.ClassLoader loader,
                                                      boolean value2InlineConstant)
      • isEmpty

        public static boolean isEmpty​(java.lang.Object value)