Package org.fest.reflect.beanproperty
Class PropertyName
- java.lang.Object
-
- org.fest.reflect.beanproperty.PropertyName
-
public final class PropertyName extends java.lang.Object
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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> PropertyType<T>
ofType(java.lang.Class<T> type)
Sets the type of the property to access.<T> PropertyTypeRef<T>
ofType(TypeRef<T> type)
Sets the type reference of the property to access.static PropertyName
startPropertyAccess(java.lang.String name)
Creates a new
: the starting point of the fluent interface for accessing properties using Bean Introspection.PropertyName
-
-
-
Method Detail
-
startPropertyAccess
public static PropertyName startPropertyAccess(java.lang.String name)
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:
java.lang.NullPointerException
- if the given name isnull
.java.lang.IllegalArgumentException
- if the given name is empty.
-
ofType
public <T> PropertyType<T> ofType(java.lang.Class<T> type)
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:
java.lang.NullPointerException
- if the given type isnull
.
-
ofType
public <T> PropertyTypeRef<T> ofType(TypeRef<T> type)
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:
java.lang.NullPointerException
- if the given type reference isnull
.
-
-