Package org.planit.assignment
Class TrafficAssignmentComponentFactory<T extends Serializable>
- java.lang.Object
-
- org.djutils.event.EventProducer
-
- org.planit.assignment.TrafficAssignmentComponentFactory<T>
-
- Type Parameters:
T
- generic type of a type traffic assignment component for which we construct the eligible derived classes by class name
- All Implemented Interfaces:
Serializable
,org.djutils.event.EventProducerInterface
public class TrafficAssignmentComponentFactory<T extends Serializable> extends org.djutils.event.EventProducer implements Serializable
Generic factory class for registered subclasses of predefined traffic assignment components, so it does not create instances of T but of sublcasses of T.- Author:
- markr
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected String
componentSuperTypeCanonicalName
instance of the super component class this factory creates subclass instances forprotected static HashMap<String,TreeSet<String>>
registeredTrafficAssignmentComponents
Register per traffic assignment component type the derived classes that are supportedstatic org.djutils.event.EventType
TRAFFICCOMPONENT_CREATE
event type fired off when a new traffic assignment component is created
-
Constructor Summary
Constructors Constructor Description TrafficAssignmentComponentFactory(Class<U> componentSuperType)
Constructor.TrafficAssignmentComponentFactory(String componentSuperTypeCanonicalName)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description T
create(String trafficAssignmentComponentClassName, Object[] constructorParameters)
Create traffic assignment componentT
create(String trafficAssignmentComponentClassName, Object[] constructorParameters, Object... eventParameters)
Create traffic assignment componentSerializable
getSourceId()
sourceId provides information of the source of an event fired from this class instancestatic void
registerTrafficAssignmentComponentType(Class<? extends TrafficAssignmentComponent<?>> trafficAssignmentComponent)
Register a component type that one can choose for the given traffic component-
Methods inherited from class org.djutils.event.EventProducer
addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, getEventTypesWithListeners, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener
-
-
-
-
Field Detail
-
TRAFFICCOMPONENT_CREATE
public static final org.djutils.event.EventType TRAFFICCOMPONENT_CREATE
event type fired off when a new traffic assignment component is created
-
componentSuperTypeCanonicalName
protected final String componentSuperTypeCanonicalName
instance of the super component class this factory creates subclass instances for
-
-
Constructor Detail
-
TrafficAssignmentComponentFactory
public TrafficAssignmentComponentFactory(Class<U> componentSuperType)
Constructor. Here we make sure it is a type that extends the traffic assignment component class. We do not do so generally on the class level since this might lead to conflicts when the class has generic arguments itself which leads to issues (that I have not been able to solve). In the latter case use the other constructor which gets around this problem by simply providing the canoncial class name corresponding to type T- Type Parameters:
U
- traffic assignment component type- Parameters:
componentSuperType
- super type for this factory
-
TrafficAssignmentComponentFactory
public TrafficAssignmentComponentFactory(String componentSuperTypeCanonicalName)
Constructor. Use this constructor when the component super type that you use is not compatible with ClassT, for example because the super type itself uses generics, i.e., T(U,V), in which case the default constructor does not work. Make sure however, that the provided canonical class name is compatible with T, i.e., it must extend from TrafficAssigmentComponent- Parameters:
componentSuperTypeCanonicalName
- super type's canonical class name for this factory which should be the same as ClassT.getCanonicalName()
-
-
Method Detail
-
registerTrafficAssignmentComponentType
public static void registerTrafficAssignmentComponentType(Class<? extends TrafficAssignmentComponent<?>> trafficAssignmentComponent) throws PlanItException
Register a component type that one can choose for the given traffic component- Parameters:
trafficAssignmentComponent
- TrafficAssignmentComponent to be registered- Throws:
PlanItException
- thrown if there is an error
-
create
public T create(String trafficAssignmentComponentClassName, Object[] constructorParameters) throws PlanItException
Create traffic assignment component- Parameters:
trafficAssignmentComponentClassName
- the derived class name of the traffic assignment component (without packages)constructorParameters
- parameters to pass to the constructor- Returns:
- the created TrafficAssignmentComponent
- Throws:
PlanItException
- thrown if there is an error
-
create
public T create(String trafficAssignmentComponentClassName, Object[] constructorParameters, Object... eventParameters) throws PlanItException
Create traffic assignment component- Parameters:
trafficAssignmentComponentClassName
- the derived class name of the traffic assignment component (without packages)constructorParameters
- parameters to pass to the constructoreventParameters
- object array which contains any data required to create the component- Returns:
- the created TrafficAssignmentComponent
- Throws:
PlanItException
- thrown if there is an error
-
getSourceId
public Serializable getSourceId()
sourceId provides information of the source of an event fired from this class instance- Specified by:
getSourceId
in interfaceorg.djutils.event.EventProducerInterface
- Specified by:
getSourceId
in classorg.djutils.event.EventProducer
- Returns:
- this class instance
-
-