Class PropertyAccessor<T,V>
java.lang.Object
org.linkki.util.reflection.accessor.PropertyAccessor<T,V>
- Type Parameters:
T- the type containing the propertyV- the property's type
Allows reading and writing a value from/to an object's property. Also provides the value class of
the property.
For accessing an object's property, create a PropertyAccessor for the class to be
accessed and the name of the property. The accessor can determine whether the property can be
read, written or invoked.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleancanRead()booleancanWrite()static <T> PropertyAccessor<T,?> getPropertyValue(T boundObject) Reads the property's value.Class<?>voidInvokes the method.voidsetPropertyValue(T boundObject, V value) Sets the property to the given value.
-
Method Details
-
getPropertyName
-
getPropertyValue
Reads the property's value.- Throws:
RuntimeException- if the method cannot be called
-
setPropertyValue
Sets the property to the given value.- Throws:
RuntimeException- if the method cannot be called
-
invoke
Invokes the method.- Throws:
RuntimeException- if the method cannot be called
-
canWrite
public boolean canWrite()- Returns:
trueif there is a read method (getter) for the given object and property
-
canInvoke
public boolean canInvoke()- Returns:
trueif there is a method that can be invoked for the given object and property
-
canRead
public boolean canRead()- Returns:
trueif there is a write method (setter) for the given object and property
-
getValueClass
- Returns:
- the return type of the getter, i.e. class of the value the read method returns.
- Throws:
IllegalStateException- if there is no read method for this property
-
get
- Parameters:
clazz- a classproperty- a property of the class- Returns:
- a
PropertyAccessorto access the property of instances of the class
-