public class PropertyUtils extends Object
IProperty property = ConfigDiscovery.getPropertyCompiler().compile("propertyToAccess.subProperty");
for (MyBean bean: allBeans) {
SubPropertyType subPropertyValue = property.get(new PropertySource(bean));
// Do something with value...
}
Modifier | Constructor and Description |
---|---|
protected |
PropertyUtils() |
Modifier and Type | Method and Description |
---|---|
static Object |
get(Object obj,
String property)
Gets property value.
|
static PropertyUtils |
getDefaultInstance() |
static Class<?> |
getGenericCollectionType(Object obj,
String property)
Returns the generic type if the property type is a collection, or null if it cannot be resolved
or if the property type is not a collection.
|
static Class<?> |
getType(Object obj,
String property)
Gets property type if it can be resolved or null.
|
static boolean |
isReadable(Object obj,
String property)
Tells if property can be read.
|
static boolean |
isWriteable(Object obj,
String property)
Tells if property can be set.
|
static Object |
safeSet(Object obj,
String property,
Object value)
Calls
set after performing advanced cast, to handle
converting an object into a Collection of another type than the object's. |
static Object |
set(Object obj,
String property,
Object value)
Sets property value.
|
public static PropertyUtils getDefaultInstance()
public static boolean isReadable(Object obj, String property) throws UtilsException
obj
- The object with the getter/setter corresponding to the propertyproperty
- The target property. Null or empty property returns true.UtilsException
- If operation is impossiblepublic static boolean isWriteable(Object obj, String property) throws UtilsException
obj
- The object with the getter/setter corresponding to the propertyproperty
- The target property. Null or empty property returns true.UtilsException
- If operation is impossiblepublic static Object get(Object obj, String property) throws UtilsException
obj
- The object with the getter/setter corresponding to the propertyproperty
- The target property. Null or empty property returns obj directly.UtilsException
- If operation is impossiblepublic static Object set(Object obj, String property, Object value) throws UtilsException
obj
- The object with the getter/setter corresponding to the propertyproperty
- The target property. Null or empty property will throw an exception.value
- The value to setUtilsException
- If operation is impossiblepublic static Object safeSet(Object obj, String property, Object value) throws UtilsException
set
after performing advanced cast, to handle
converting an object into a Collection of another type than the object's.obj
- The object with the getter/setter corresponding to the propertyproperty
- The target property. Null or empty property will throw an exception.value
- The value to setUtilsException
- If operation is impossiblepublic static Class<?> getType(Object obj, String property) throws UtilsException
obj
- The object with the getter/setter corresponding to the propertyproperty
- The target property. Null or empty property will return obj type.UtilsException
- If operation is impossible (property does not exist, ...)public static Class<?> getGenericCollectionType(Object obj, String property) throws UtilsException
obj
- The object with the getter/setter corresponding to the propertyproperty
- The target property. Null or empty property will return null.UtilsException