com.natpryce.makeiteasy
Class Maker<T>

java.lang.Object
  extended by com.natpryce.makeiteasy.Maker<T>
Type Parameters:
T - the type of object to make
All Implemented Interfaces:
Donor<T>, PropertyLookup<T>

public class Maker<T>
extends Object
implements PropertyLookup<T>, Donor<T>

Makes objects of a given type with a specified initial state.


Constructor Summary
Maker(Instantiator<T> instantiator, PropertyValue<? super T,?>... propertyValues)
          Creates a Maker for objects of a given type with a given initial state.
 
Method Summary
 Maker<T> but(PropertyValue<? super T,?>... propertyValues)
          Returns a new Maker for the same type of object and with the same initial state except where overridden by the given propertyValues.
 T make()
          Makes a new object.
 T value()
          Donate the value.
<V> V
valueOf(Property<? super T,V> property, Donor<? extends V> defaultValue)
           
<V> V
valueOf(Property<? super T,V> property, V defaultValue)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Maker

public Maker(Instantiator<T> instantiator,
             PropertyValue<? super T,?>... propertyValues)
Creates a Maker for objects of a given type with a given initial state.

Parameters:
instantiator - creates the new objects
propertyValues - define the initial state of the new objects
Method Detail

make

public T make()
Makes a new object. The MakeItEasy.make method is syntactic sugar to make calls to this method read more naturally in most contexts.

Returns:
a new object

value

public T value()
Description copied from interface: Donor
Donate the value.

Specified by:
value in interface Donor<T>
Returns:
the value donated

but

public Maker<T> but(PropertyValue<? super T,?>... propertyValues)
Returns a new Maker for the same type of object and with the same initial state except where overridden by the given propertyValues.

Parameters:
propertyValues - those initial properties of the new Make that will differ from this Maker
Returns:
a new Maker

valueOf

public <V> V valueOf(Property<? super T,V> property,
                     V defaultValue)
Specified by:
valueOf in interface PropertyLookup<T>
Type Parameters:
V - the type of the value
Parameters:
property - the property for which a value will be returned
defaultValue - the default value to use if no value can be found
Returns:
the value for the given property, or defaultValue if no value can be found.

valueOf

public <V> V valueOf(Property<? super T,V> property,
                     Donor<? extends V> defaultValue)
Specified by:
valueOf in interface PropertyLookup<T>
Type Parameters:
V - the type of the value
Parameters:
property - the property for which a value will be returned
defaultValue - an object that can provide the default value to use if no value can be found
Returns:
the value for the given property, or defaultValueDonor.value() if no value can be found.


Copyright © 2010. All Rights Reserved.