Class ObjectModel


  • @Deprecated
    public final class ObjectModel
    extends Object
    Deprecated.
    This class has been moved to ObjectModel.
    The ObjectModel class provides various static models for object conversion and object property resolution.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Set<Class<?>> PRIMITIVE_CLASSES
      Deprecated.
      A Set that stores all the supported primitive classes.
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static String collectionToString​(Collection<?> collection)
      Deprecated.
      Converts the passed collection to a comma separated values String representation.
      static Method findBeanMethod​(Class<?> cls, String baseName)
      Deprecated.
      Given a bean class and a base method name, this method will try to find a public method without parameters that is named: baseName get + BaseName is + BaseName
      static Collection<Object> fromIterator​(Iterator<Object> iterator)
      Deprecated.
      Given an iterator, this method will return a Collection.
      static Object getField​(Object object, String fieldName)
      Deprecated.
      Given an object, this method will return the value of the public field identified by fieldName.
      static Object getIndex​(Object object, int index)
      Deprecated.
      Given an indexable object (i.e.
      static Object invokeBeanMethod​(Object object, String methodName)
      Deprecated.
      Given a bean object, this method will invoke the public method without parameters identified by methodName and return the invocation's result.
      static boolean isMethodAllowed​(Method method)
      Deprecated.
      Returns true if the method is not one of the Object's class declared methods, with the exception of Object.toString().
      static boolean isPrimitive​(Object object)
      Deprecated.
      Checks if the provided object is an instance of a primitive class.
      static Object resolveProperty​(Object target, Object property)
      Deprecated.
      Given the target object, this method attempts to resolve and return the value of the passed property.
      static boolean toBoolean​(Object object)
      Deprecated.
      Converts the given object to a boolean value, applying the following rules: if the object is null the returned value is false if the object is a Number the method will return false only if the number's value is 0 if the String representation of the object is equal irrespective of its casing to "true", the method will return true if the object is a Collection or a Map, the method will return true only if the collection / map is not empty if the object is an array, the method will return true only if the array is not empty
      static Collection<Object> toCollection​(Object object)
      Deprecated.
      Forces the conversion of the passed object to a collection, according to the following rules: if the object is null an empty collection will be returned if the object is an array a list transformation of the array will be returned if the object is a Collection the object itself will be returned if the object is an instance of a Map the map's key set will be returned (see Map.keySet()) if the object is an instance of an Enumeration a list transformation will be returned if the object is an instance of an Iterator or Iterable the result of fromIterator(Iterator) will be returned if the object is an instance of a String or Number a Collection containing only this object will be returned any other case not covered by the previous rules will result in an empty Collection
      static Number toNumber​(Object object)
      Deprecated.
      Coerces the passed object to a numeric value.
      static String toString​(Object object)
      Deprecated.
      Converts the passed object to a String.
    • Field Detail

      • PRIMITIVE_CLASSES

        public static final Set<Class<?>> PRIMITIVE_CLASSES
        Deprecated.
        A Set that stores all the supported primitive classes.
    • Method Detail

      • isPrimitive

        public static boolean isPrimitive​(Object object)
        Deprecated.
        Checks if the provided object is an instance of a primitive class.
        Parameters:
        object - the Object to check
        Returns:
        true if the object is a primitive, false otherwise
      • resolveProperty

        public static Object resolveProperty​(Object target,
                                             Object property)
        Deprecated.

        Given the target object, this method attempts to resolve and return the value of the passed property.

        The property can be either an index or a name:

        • index: the property is considered an index if its value is an integer number and in this case the target will be assumed to be either an array or it will be converted to a Collection; a fallback to Map will be made in case the previous two attempts failed
        • name: the property will be converted to a String (see toString(Object)); the target will be assumed to be either a Map or an object; if the Map attempt fails, the property will be used to check if the target has a publicly accessible field with this name or a publicly accessible method with no parameters with this name or a combination of the "get" or "is" prefixes plus the capitalised name (see invokeBeanMethod(Object, String))
        Parameters:
        target - the target object
        property - the property to be resolved
        Returns:
        the value of the property or null
      • toBoolean

        public static boolean toBoolean​(Object object)
        Deprecated.
        Converts the given object to a boolean value, applying the following rules:
        • if the object is null the returned value is false
        • if the object is a Number the method will return false only if the number's value is 0
        • if the String representation of the object is equal irrespective of its casing to "true", the method will return true
        • if the object is a Collection or a Map, the method will return true only if the collection / map is not empty
        • if the object is an array, the method will return true only if the array is not empty
        Parameters:
        object - the target object
        Returns:
        the boolean representation of the object according to the conversion rules
      • toString

        public static String toString​(Object object)
        Deprecated.
        Converts the passed object to a String. The following rules apply:
        • if the object is null an empty string will be returned
        • if the object is an instance of a String the object itself will be returned
        • if the object is a primitive (see isPrimitive(Object)), its String representation will be returned
        • if the object is an Enum its name will be returned (see Enum.name())
        • otherwise an attempt to convert the object to a Collection will be made and then the output of collectionToString(Collection) will be returned
        Parameters:
        object - the target object
        Returns:
        the string representation of the object or an empty string
      • toCollection

        public static Collection<Object> toCollection​(Object object)
        Deprecated.
        Forces the conversion of the passed object to a collection, according to the following rules:
        • if the object is null an empty collection will be returned
        • if the object is an array a list transformation of the array will be returned
        • if the object is a Collection the object itself will be returned
        • if the object is an instance of a Map the map's key set will be returned (see Map.keySet())
        • if the object is an instance of an Enumeration a list transformation will be returned
        • if the object is an instance of an Iterator or Iterable the result of fromIterator(Iterator) will be returned
        • if the object is an instance of a String or Number a Collection containing only this object will be returned
        • any other case not covered by the previous rules will result in an empty Collection
        Parameters:
        object - the target object
        Returns:
        the collection representation of the object
      • collectionToString

        public static String collectionToString​(Collection<?> collection)
        Deprecated.
        Converts the passed collection to a comma separated values String representation.
        Parameters:
        collection - the collection to be converted to CSV
        Returns:
        the CSV; if the collection is empty then an empty string will be returned
      • fromIterator

        public static Collection<Object> fromIterator​(Iterator<Object> iterator)
        Deprecated.
        Given an iterator, this method will return a Collection.
        Parameters:
        iterator - the iterator to be transformed into a collection
        Returns:
        a collection with the iterator's elements
      • getIndex

        public static Object getIndex​(Object object,
                                      int index)
        Deprecated.
        Given an indexable object (i.e. an array or a collection), this method will return the value available at the index position.
        Parameters:
        object - the indexable object
        index - the index
        Returns:
        the value stored at the index or null
      • getField

        public static Object getField​(Object object,
                                      String fieldName)
        Deprecated.
        Given an object, this method will return the value of the public field identified by fieldName.
        Parameters:
        object - the target object
        fieldName - the name of the field
        Returns:
        the value of the field or null if the field was not found
      • invokeBeanMethod

        public static Object invokeBeanMethod​(Object object,
                                              String methodName)
        Deprecated.
        Given a bean object, this method will invoke the public method without parameters identified by methodName and return the invocation's result.
        Parameters:
        object - the target object
        methodName - the name of the public method without parameters to invoke
        Returns:
        the invocation's result or null if such a method cannot be found
      • findBeanMethod

        public static Method findBeanMethod​(Class<?> cls,
                                            String baseName)
        Deprecated.
        Given a bean class and a base method name, this method will try to find a public method without parameters that is named:
        1. baseName
        2. get + BaseName
        3. is + BaseName
        Parameters:
        cls - the class into which to search for the method
        baseName - the base method name
        Returns:
        a method that matches the criteria or null
      • isMethodAllowed

        public static boolean isMethodAllowed​(Method method)
        Deprecated.
        Returns true if the method is not one of the Object's class declared methods, with the exception of Object.toString().
        Parameters:
        method - the method to check
        Returns:
        true if the method is not one of the Object's class declared methods, with the exception of Object.toString(), false otherwise