public final class ObjectModel
extends java.lang.Object
ObjectModel
class provides various static models for object conversion and object property resolution.Modifier and Type | Field and Description |
---|---|
static java.util.Set<java.lang.Class<?>> |
PRIMITIVE_CLASSES
A
Set that stores all the supported primitive classes. |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
collectionToString(java.util.Collection<?> collection)
Converts the passed
collection to a comma separated values String representation. |
static java.lang.reflect.Method |
findBeanMethod(java.lang.Class<?> cls,
java.lang.String baseName)
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 java.util.Collection<java.lang.Object> |
fromIterator(java.util.Iterator<java.lang.Object> iterator)
Given an
iterator , this method will return a Collection . |
static java.lang.Object |
getField(java.lang.Object object,
java.lang.String fieldName)
Given an
object , this method will return the value of the public field identified by fieldName . |
static java.lang.Object |
getIndex(java.lang.Object object,
int index)
Given an indexable
object (i.e. |
static java.lang.Object |
invokeBeanMethod(java.lang.Object object,
java.lang.String methodName)
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(java.lang.reflect.Method method)
Returns
true if the method is not one of the Object 's class declared methods, with the exception of
Object.toString() . |
static boolean |
isPrimitive(java.lang.Object object)
Checks if the provided
object is an instance of a primitive class. |
static java.lang.Object |
resolveProperty(java.lang.Object target,
java.lang.Object property)
Given the
target object, this method attempts to resolve and return the value of the passed property . |
static boolean |
toBoolean(java.lang.Object object)
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 java.util.Collection<java.lang.Object> |
toCollection(java.lang.Object object)
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 java.lang.Number |
toNumber(java.lang.Object object)
Coerces the passed
object to a numeric value. |
static java.lang.String |
toString(java.lang.Object object)
Converts the passed
object to a String . |
public static final java.util.Set<java.lang.Class<?>> PRIMITIVE_CLASSES
Set
that stores all the supported primitive classes.public static boolean isPrimitive(java.lang.Object object)
object
is an instance of a primitive class.object
- the Object
to checktrue
if the object
is a primitive, false
otherwisepublic static java.lang.Object resolveProperty(java.lang.Object target, java.lang.Object property)
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:
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
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)
)target
- the target objectproperty
- the property to be resolvednull
public static boolean toBoolean(java.lang.Object object)
object
to a boolean value, applying the following rules:
object
is null
the returned value is false
object
is a Number
the method will return false
only if the number's value is 0String
representation of the object
is equal irrespective of its casing to "true", the method will
return true
object
is a Collection
or a Map
, the method will return true
only if the collection /
map is not emptytrue
only if the array is not emptyobject
- the target objectobject
according to the conversion rulespublic static java.lang.Number toNumber(java.lang.Object object)
object
to a numeric value. If the passed value is a String
the conversion rules are those of
NumberUtils.createNumber(String)
.object
- the target objectnull
NumberUtils.createNumber(String)
public static java.lang.String toString(java.lang.Object object)
object
to a String
. The following rules apply:
object
is null
an empty string will be returnedobject
is an instance of a String
the object itself will be returnedisPrimitive(Object)
), its String
representation will be returnedEnum
its name will be returned (see Enum.name()
)Collection
will be made and then the output of
collectionToString(Collection)
will be returnedobject
- the target objectpublic static java.util.Collection<java.lang.Object> toCollection(java.lang.Object object)
object
to a collection, according to the following rules:
object
is null
an empty collection will be returnedobject
is an array a list transformation of the array will be returnedobject
is a Collection
the object itself will be returnedobject
is an instance of a Map
the map's key set will be returned (see Map.keySet()
)object
is an instance of an Enumeration
a list transformation will be returnedobject
is an instance of an Iterator
or Iterable
the result of fromIterator(Iterator)
will be returnedobject
is an instance of a String
or Number
a Collection
containing only this
object will be returnedCollection
object
- the target objectpublic static java.lang.String collectionToString(java.util.Collection<?> collection)
collection
to a comma separated values String
representation.collection
- the collection to be converted to CSVcollection
is empty then an empty string will be returnedpublic static java.util.Collection<java.lang.Object> fromIterator(java.util.Iterator<java.lang.Object> iterator)
iterator
, this method will return a Collection
.iterator
- the iterator to be transformed into a collection
public static java.lang.Object getIndex(java.lang.Object object, int index)
object
(i.e. an array or a collection), this method will return the value available at the index
position.object
- the indexable objectindex
- the indexindex
or null
public static java.lang.Object getField(java.lang.Object object, java.lang.String fieldName)
object
, this method will return the value of the public field identified by fieldName
.object
- the target objectfieldName
- the name of the fieldnull
if the field was not foundpublic static java.lang.Object invokeBeanMethod(java.lang.Object object, java.lang.String methodName)
object
, this method will invoke the public method without parameters identified by methodName
and
return the invocation's result.object
- the target objectmethodName
- the name of the public method without parameters to invokenull
if such a method cannot be foundpublic static java.lang.reflect.Method findBeanMethod(java.lang.Class<?> cls, java.lang.String baseName)
baseName
BaseName
BaseName
cls
- the class into which to search for the methodbaseName
- the base method namenull
public static boolean isMethodAllowed(java.lang.reflect.Method method)
true
if the method is not one of the Object
's class declared methods, with the exception of
Object.toString()
.method
- the method to checktrue
if the method is not one of the Object
's class declared methods, with the exception of
Object.toString()
, false
otherwise"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"