Class TrafficAssignmentComponentFactory<T extends Serializable>

  • 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 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
      • registeredTrafficAssignmentComponents

        protected static final HashMap<String,​TreeSet<String>> registeredTrafficAssignmentComponents
        Register per traffic assignment component type the derived classes that are supported
    • 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 constructor
        eventParameters - 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 interface org.djutils.event.EventProducerInterface
        Specified by:
        getSourceId in class org.djutils.event.EventProducer
        Returns:
        this class instance