Package org.fest.reflect.beanproperty
Class PropertyName
java.lang.Object
org.fest.reflect.beanproperty.PropertyName
Understands the name of a property to access using Bean Introspection.
The following is an example of proper usage of this class:
// Retrieves the value of the property "name" String name =property
("name").ofType
(String.class).in
(person).get
(); // Sets the value of the property "name" to "Yoda"property
("name").ofType
(String.class).in
(person).set
("Yoda"); // Retrieves the value of the property "powers" List<String> powers =property
("powers").ofType
(newTypeRef
<List<String>>() {}).in
(jedi).get
(); // Sets the value of the property "powers" List<String> powers = new ArrayList<String>(); powers.add("heal");property
("powers").ofType
(newTypeRef
<List<String>>() {}).in
(jedi).set
(powers);
- Since:
- 1.2
- Author:
- Alex Ruiz
-
Method Summary
Modifier and TypeMethodDescription<T> PropertyType<T>
Sets the type of the property to access.<T> PropertyTypeRef<T>
Sets the type reference of the property to access.static PropertyName
startPropertyAccess
(String name) Creates a new
: the starting point of the fluent interface for accessing properties using Bean Introspection.PropertyName
-
Method Details
-
startPropertyAccess
Creates a new
: the starting point of the fluent interface for accessing properties using Bean Introspection.PropertyName
- Parameters:
name
- the name of the property to access using Bean Introspection.- Returns:
- the created
PropertyName
. - Throws:
NullPointerException
- if the given name isnull
.IllegalArgumentException
- if the given name is empty.
-
ofType
Sets the type of the property to access.- Type Parameters:
T
- the generic type of the property type.- Parameters:
type
- the type of the property to access.- Returns:
- a recipient for the property type.
- Throws:
NullPointerException
- if the given type isnull
.
-
ofType
Sets the type reference of the property to access. This method reduces casting when the type of the property to access uses generics.For example:
List<String> powers =
property
("powers").ofType
(newTypeRef
<List<String>>() {}).in
(jedi).get
();- Type Parameters:
T
- the generic type of the property type.- Parameters:
type
- the type of the property to access.- Returns:
- a recipient for the property type.
- Throws:
NullPointerException
- if the given type reference isnull
.
-