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.String module  
      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 java.lang.Object getInstance​(java.lang.String className, java.lang.Object[] parameters)
      Returns an instance of the specified class using the constructor matching the specified parameters.
      static boolean instanceOf​(java.lang.Class<?> objectClass, java.lang.Class<?> typeClass)
      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.Object typeObject)
      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)
      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.Class<?> typeClass)
      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.Object typeObject)
      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)
      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 interfaceOf​(java.lang.Class<?> objectClass, java.lang.Class<?> interfaceClass)
      Tests if a class properly implements the specified interface.
      static boolean interfaceOf​(java.lang.Class<?> objectClass, java.lang.Object interfaceObject)
      Tests if a class properly implements the specified interface.
      static boolean interfaceOf​(java.lang.Class<?> objectClass, java.lang.String interfaceName)
      Tests if a class properly implements the specified interface.
      static boolean interfaceOf​(java.lang.Object obj, java.lang.Class<?> interfaceClass)
      Tests if an object properly implements the specified interface.
      static boolean interfaceOf​(java.lang.Object obj, java.lang.Object interfaceObject)
      Tests if an object properly implements the specified interface.
      static boolean interfaceOf​(java.lang.Object obj, java.lang.String interfaceName)
      Tests if an object properly implements the specified interface.
      static boolean isEmpty​(java.lang.Object value)  
      static boolean isOrSubOf​(java.lang.Class<?> objectClass, java.lang.Class<?> parentClass)
      Tests if a class is a class of or a sub-class of the parent.
      static boolean isOrSubOf​(java.lang.Class<?> objectClass, java.lang.Object parentObject)
      Tests if a class is a class of or a sub-class of the parent.
      static boolean isOrSubOf​(java.lang.Class<?> objectClass, java.lang.String parentName)
      Tests if a class is a class of or a sub-class of the parent.
      static boolean isOrSubOf​(java.lang.Object obj, java.lang.Class<?> parentClass)
      Tests if an object is an instance of or a sub-class of the parent.
      static boolean isOrSubOf​(java.lang.Object obj, java.lang.Object parentObject)
      Tests if an object is an instance of or a sub-class of the parent.
      static boolean isOrSubOf​(java.lang.Object obj, java.lang.String parentName)
      Tests if an object is an instance of or a sub-class of the parent.
      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 simpleTypeConvert​(java.lang.Object obj, java.lang.String type, java.lang.String format, java.util.Locale locale)  
      static java.lang.Object simpleTypeConvert​(java.lang.Object obj, java.lang.String type, java.lang.String format, java.util.Locale locale, boolean noTypeFail)  
      static java.lang.Object simpleTypeConvert​(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 simple type.
      • Methods inherited from class java.lang.Object

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

      • module

        public static final java.lang.String module
      • 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
      • interfaceOf

        public static boolean interfaceOf​(java.lang.Class<?> objectClass,
                                          java.lang.String interfaceName)
                                   throws java.lang.ClassNotFoundException
        Tests if a class properly implements the specified interface.
        Parameters:
        objectClass - Class to test
        interfaceName - Name of the interface to test against
        Returns:
        true if interfaceName is an interface of objectClass
        Throws:
        java.lang.ClassNotFoundException
      • interfaceOf

        public static boolean interfaceOf​(java.lang.Class<?> objectClass,
                                          java.lang.Object interfaceObject)
        Tests if a class properly implements the specified interface.
        Parameters:
        objectClass - Class to test
        interfaceObject - to test against
        Returns:
        true if interfaceObject is an interface of the objectClass
      • getInstance

        public static java.lang.Object getInstance​(java.lang.String className,
                                                   java.lang.Object[] parameters)
                                            throws java.lang.ClassNotFoundException,
                                                   java.lang.InstantiationException,
                                                   java.lang.IllegalAccessException,
                                                   java.lang.NoSuchMethodException,
                                                   java.lang.reflect.InvocationTargetException
        Returns an instance of the specified class using the constructor matching the specified parameters.
        Parameters:
        className - Name of the class to instantiate
        parameters - Parameters passed to the constructor
        Returns:
        An instance of the className
        Throws:
        java.lang.ClassNotFoundException
        java.lang.InstantiationException
        java.lang.IllegalAccessException
        java.lang.NoSuchMethodException
        java.lang.reflect.InvocationTargetException
      • interfaceOf

        public static boolean interfaceOf​(java.lang.Object obj,
                                          java.lang.String interfaceName)
                                   throws java.lang.ClassNotFoundException
        Tests if an object properly implements the specified interface.
        Parameters:
        obj - Object to test
        interfaceName - Name of the interface to test against
        Returns:
        true if interfaceName is an interface of obj
        Throws:
        java.lang.ClassNotFoundException
      • interfaceOf

        public static boolean interfaceOf​(java.lang.Object obj,
                                          java.lang.Object interfaceObject)
        Tests if an object properly implements the specified interface.
        Parameters:
        obj - Object to test
        interfaceObject - to test against
        Returns:
        true if interfaceObject is an interface of obj
      • interfaceOf

        public static boolean interfaceOf​(java.lang.Object obj,
                                          java.lang.Class<?> interfaceClass)
        Tests if an object properly implements the specified interface.
        Parameters:
        obj - Object to test
        interfaceClass - Class to test against
        Returns:
        true if interfaceClass is an interface of obj
      • interfaceOf

        public static boolean interfaceOf​(java.lang.Class<?> objectClass,
                                          java.lang.Class<?> interfaceClass)
        Tests if a class properly implements the specified interface.
        Parameters:
        objectClass - Class to test
        interfaceClass - Class to test against
        Returns:
        true if interfaceClass is an interface of objectClass
      • isOrSubOf

        public static boolean isOrSubOf​(java.lang.Class<?> objectClass,
                                        java.lang.String parentName)
                                 throws java.lang.ClassNotFoundException
        Tests if a class is a class of or a sub-class of the parent.
        Parameters:
        objectClass - Class to test
        parentName - Name of the parent class to test against
        Returns:
        true if objectClass is a class of or a sub-class of the parent
        Throws:
        java.lang.ClassNotFoundException
      • isOrSubOf

        public static boolean isOrSubOf​(java.lang.Class<?> objectClass,
                                        java.lang.Object parentObject)
        Tests if a class is a class of or a sub-class of the parent.
        Parameters:
        objectClass - Class to test
        parentObject - Object to test against
        Returns:
        true if objectClass is a class of or a sub-class of the parent
      • isOrSubOf

        public static boolean isOrSubOf​(java.lang.Object obj,
                                        java.lang.String parentName)
                                 throws java.lang.ClassNotFoundException
        Tests if an object is an instance of or a sub-class of the parent.
        Parameters:
        obj - Object to test
        parentName - Name of the parent class to test against
        Returns:
        true if obj is an instance of or a sub-class of the parent
        Throws:
        java.lang.ClassNotFoundException
      • isOrSubOf

        public static boolean isOrSubOf​(java.lang.Object obj,
                                        java.lang.Object parentObject)
        Tests if an object is an instance of or a sub-class of the parent.
        Parameters:
        obj - Object to test
        parentObject - Object to test against
        Returns:
        true if obj is an instance of or a sub-class of the parent
      • isOrSubOf

        public static boolean isOrSubOf​(java.lang.Object obj,
                                        java.lang.Class<?> parentClass)
        Tests if an object is an instance of or a sub-class of the parent.
        Parameters:
        obj - Object to test
        parentClass - Class to test against
        Returns:
        true if obj is an instance of or a sub-class of the parent
      • isOrSubOf

        public static boolean isOrSubOf​(java.lang.Class<?> objectClass,
                                        java.lang.Class<?> parentClass)
        Tests if a class is a class of or a sub-class of the parent.
        Parameters:
        objectClass - Class to test
        parentClass - Class to test against
        Returns:
        true if objectClass is a class of or a sub-class of the parent
      • instanceOf

        public static boolean instanceOf​(java.lang.Class<?> objectClass,
                                         java.lang.Object typeObject)
        Tests if a class is a class of a sub-class of or properly implements an interface.
        Parameters:
        objectClass - Class to test
        typeObject - Object to test against
        Returns:
        true if objectClass is a class of a sub-class of, or properly implements an interface
      • 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.Object typeObject)
        Tests if an object is an instance of a sub-class of or properly implements an interface.
        Parameters:
        obj - Object to test
        typeObject - Object 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.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)
      • instanceOf

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

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

        public static java.lang.Object simpleTypeConvert​(java.lang.Object obj,
                                                         java.lang.String type,
                                                         java.lang.String format,
                                                         java.util.Locale locale,
                                                         boolean noTypeFail)
                                                  throws GeneralException
        Throws:
        GeneralException
      • simpleTypeConvert

        public static java.lang.Object simpleTypeConvert​(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 simple type. Supported types include: String, Boolean, Double, Float, Long, Integer, Date (java.sql.Date), Time, Timestamp, TimeZone;
        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
      • simpleTypeConvert

        public static java.lang.Object simpleTypeConvert​(java.lang.Object obj,
                                                         java.lang.String type,
                                                         java.lang.String format,
                                                         java.util.Locale locale)
                                                  throws GeneralException
        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)