nl.jqno.equalsverifier.util
Class ConditionalPrefabValueBuilder

java.lang.Object
  extended by nl.jqno.equalsverifier.util.ConditionalPrefabValueBuilder

public class ConditionalPrefabValueBuilder
extends Object

Builds prefab values for classes that may or may not be present on the classpath. Will try to create precisely two prefab values for a given class by calling its constructor, a factory method, or a public static final constant declared within the class, and add them to a PrefabValues object. If the class is not present on the classpath, or if calling any of its members fails, it will result in a no-op. ConditionalPrefabValueBuilder will not throw an exception.

Author:
Jan Ouwens

Method Summary
 void addTo(PrefabValues prefabValues)
          Adds two instances of the given type to a PrefabValues object.
 ConditionalPrefabValueBuilder callFactory(String factoryMethod, Class<?>[] paramTypes, Object[] paramValues)
          Attempts to instantiate the given type by calling a factory method.
 ConditionalPrefabValueBuilder callFactory(String factoryType, String factoryMethod, Class<?>[] paramTypes, Object[] paramValues)
          Attempts to instantiate the given type by calling a factory method.
 ConditionalPrefabValueBuilder instantiate(Class<?>[] paramTypes, Object[] paramValues)
          Attempts to instantiate the given type by calling its constructor.
 ConditionalPrefabValueBuilder instantiate(Class<?>[] paramTypes, PrefabValues prefabValues)
          Attempts to instantiate the given type by calling its constructor.
static ConditionalPrefabValueBuilder of(String fullyQualifiedClassName)
          Factory method.
 ConditionalPrefabValueBuilder withConcreteClass(String fullyQualifiedClassName)
          Provides a concrete implementing class in case the desired type is abstract or an interface.
 ConditionalPrefabValueBuilder withConstant(String constantName)
          Attempts to obtain a reference to the given type by calling a public static final constant defined within the type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

of

public static ConditionalPrefabValueBuilder of(String fullyQualifiedClassName)
Factory method.

Parameters:
fullyQualifiedClassName - The fully qualified class name of the class for which we intend to create prefab values.
Returns:
A ConditionalPrefabValueBuilder.

withConcreteClass

public ConditionalPrefabValueBuilder withConcreteClass(String fullyQualifiedClassName)
Provides a concrete implementing class in case the desired type is abstract or an interface.

Parameters:
fullyQualifiedClassName - The fully qualified class name of the concrete implementing class.
Returns:
this, for easy method chaining.

instantiate

public ConditionalPrefabValueBuilder instantiate(Class<?>[] paramTypes,
                                                 Object[] paramValues)
Attempts to instantiate the given type by calling its constructor. If this fails, it will short-circuit any further calls.

Parameters:
paramTypes - A list of types that identifies the constructor to be called.
paramValues - A list of values to pass to the constructor. Their types must match the paramTypes.
Returns:
this, for easy method chaining.

instantiate

public ConditionalPrefabValueBuilder instantiate(Class<?>[] paramTypes,
                                                 PrefabValues prefabValues)
Attempts to instantiate the given type by calling its constructor. If this fails, it will short-circuit any further calls.

Parameters:
paramTypes - A list of types that identifies the constructor to be called.
prefabValues - The PrefabValues to draw values from.
Returns:
this, for easy method chaining.

callFactory

public ConditionalPrefabValueBuilder callFactory(String factoryMethod,
                                                 Class<?>[] paramTypes,
                                                 Object[] paramValues)
Attempts to instantiate the given type by calling a factory method. If this fails, it will short-circuit any further calls.

Parameters:
factoryMethod - The name of the factory method.
paramTypes - A list of types that identifies the factory method's overload to be called.
paramValues - A list of values to pass to the constructor. Their types must match the paramTypes.
Returns:
this, for easy method chaining.

callFactory

public ConditionalPrefabValueBuilder callFactory(String factoryType,
                                                 String factoryMethod,
                                                 Class<?>[] paramTypes,
                                                 Object[] paramValues)
Attempts to instantiate the given type by calling a factory method. If this fails, it will short-circuit any further calls.

Parameters:
factoryType - The type that contains the factory method.
factoryMethod - The name of the factory method.
paramTypes - A list of types that identifies the factory method's overload to be called.
paramValues - A list of values to pass to the constructor. Their types must match the paramTypes.
Returns:
this, for easy method chaining.

withConstant

public ConditionalPrefabValueBuilder withConstant(String constantName)
Attempts to obtain a reference to the given type by calling a public static final constant defined within the type. If this fails, it will short-circuit any further calls.

Parameters:
constantName - The name of the constant.
Returns:
this, for easy method chaining.

addTo

public void addTo(PrefabValues prefabValues)
Adds two instances of the given type to a PrefabValues object.

Parameters:
prefabValues - The PrefabValues object to add the instances to.


Copyright © 2015. All Rights Reserved.