Package org.goplanit.utils.builder
Class Configurator<T>
- java.lang.Object
-
- org.goplanit.utils.builder.Configurator<T>
-
- Direct Known Subclasses:
FundamentalDiagramConfigurator
,GapFunctionConfigurator
,LogitChoiceModelConfigurator
,NodeModelConfigurator
,PathChoiceConfigurator
,PhysicalCostConfigurator
,SmoothingConfigurator
,StopCriterionConfigurator
,TrafficAssignmentConfigurator
,VirtualCostConfigurator
public class Configurator<T> extends Object
This is the base class for all configuration oriented proxy classes. Whenever we configure a traffic assignment component, or any other component with functionality that should not be exposed to the user, while at the same time this user must be able to configure this class by setting one or more configuration options, we must use this class to provide a convenient mapping mechanism that work for any such situation without having to manually implement all the configuration options that are already present on the class that contains the functionality. The aim of this configurator is to store all the function calls that should be delayed and deferred to the class that contains the actual functionality in a concise and general way.- Author:
- markr
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<String,List<Object[]>>
delayedMethodCalls
The methods to invoke on the to be configured object instance and their parameters.
-
Constructor Summary
Constructors Constructor Description Configurator(Class<T> instanceType)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
callVoidMethod(T instance, String methodName, Object... parameters)
Call a void method on the toConfigure class instanceprotected Class<?>[]
collectParameterTypes(Object... parameters)
collect the parameter types of the passed in object in their original ordervoid
configure(T toConfigureInstance)
Configure the passed in instance with the registered method callsClass<T>
getClassTypeToConfigure()
collect the class type we are configuring forprotected Object
getFirstParameterOfDelayedMethodCall(String methodName)
Collect the first parameter submitted with (last) registered delayed method call of given signature.protected void
registerDelayedMethodCall(String methodName, Object... parameters)
Register a method call to a setter that should be invoked on the to be configured object instance once it is available
-
-
-
Method Detail
-
collectParameterTypes
protected Class<?>[] collectParameterTypes(Object... parameters) throws PlanItException
collect the parameter types of the passed in object in their original order- Parameters:
parameters
- the parameters- Returns:
- parameterTypes array
- Throws:
PlanItException
- thrown if error
-
callVoidMethod
protected void callVoidMethod(T instance, String methodName, Object... parameters) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, PlanItException, NoSuchMethodException, SecurityException
Call a void method on the toConfigure class instance- Parameters:
instance
- to call method onmethodName
- to callparameters
- to add to call- Throws:
IllegalAccessException
- thrown if errorIllegalArgumentException
- thrown if errorInvocationTargetException
- thrown if errorPlanItException
- thrown if instance or its class are unknownNoSuchMethodException
- thrown if errorSecurityException
- thrown if error
-
registerDelayedMethodCall
protected void registerDelayedMethodCall(String methodName, Object... parameters)
Register a method call to a setter that should be invoked on the to be configured object instance once it is available- Parameters:
methodName
- the method nameparameters
- the parameters of the method
-
getFirstParameterOfDelayedMethodCall
protected Object getFirstParameterOfDelayedMethodCall(String methodName)
Collect the first parameter submitted with (last) registered delayed method call of given signature. If not available null is returned. Useful to mimic getters for a given setter on configurator derived class.- Parameters:
methodName
- that reflects the delayed call- Returns:
- first parameter of delay method name call
-
getClassTypeToConfigure
public Class<T> getClassTypeToConfigure()
collect the class type we are configuring for- Returns:
- class type
-
configure
public void configure(T toConfigureInstance) throws PlanItException
Configure the passed in instance with the registered method calls- Parameters:
toConfigureInstance
- the instance to configure- Throws:
PlanItException
- thrown if error
-
-