org.fest.reflect.beanproperty
Class PropertyName

java.lang.Object
  extended by org.fest.reflect.beanproperty.PropertyName

public final class PropertyName
extends 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(new TypeRef<List<String>>() {}).in(jedi).get();

   // Sets the value of the property "powers"
   List<String> powers = new ArrayList<String>();
   powers.add("heal");
   property("powers").ofType(new TypeRef<List<String>>() {}).in(jedi).set(powers);
 

Since:
1.2
Author:
Alex Ruiz

Method Summary
<T> PropertyType<T>
ofType(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(String name)
          Creates a new PropertyName: the starting point of the fluent interface for accessing properties using Bean Introspection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

startPropertyAccess

public static PropertyName startPropertyAccess(String name)
Creates a new PropertyName: the starting point of the fluent interface for accessing properties using Bean Introspection.

Parameters:
name - the name of the property to access using Bean Introspection.
Returns:
the created PropertyName.
Throws:
NullPointerException - if the given name is null.
IllegalArgumentException - if the given name is empty.

ofType

public <T> PropertyType<T> ofType(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:
NullPointerException - if the given type is null.

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(new TypeRef<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 is null.


Copyright © 2007-2011 FEST (Fixtures for Easy Software Testing). All Rights Reserved.