public class SensorTargetMediatorFactory extends java.lang.Object implements MediatorFactory<Sensor,Moveable,SensorTargetMediator>
Modifier and Type | Field and Description |
---|---|
private java.util.WeakHashMap<java.lang.Class<? extends Sensor>,java.util.Map<java.lang.Class<? extends Moveable>,SensorTargetMediator>> |
cache
Holds the Mediators that have been added to this factory, key by Sensor
and Moveable (target)
|
protected static SensorTargetMediatorFactory |
instance
Holds the instance of SensorTargetMediatorFactory.
|
Modifier | Constructor and Description |
---|---|
protected |
SensorTargetMediatorFactory()
Creates new empty SensorTargetMediatorFactory
|
Modifier and Type | Method and Description |
---|---|
static void |
addMediator(java.lang.Class<? extends Sensor> sensorClass,
java.lang.Class<? extends Moveable> targetClass,
java.lang.Class<? extends SensorTargetMediator> mediatorClass)
Constructs and adds a Mediator to the MediatorFactory.
|
static void |
addMediator(java.lang.Class<? extends Sensor> sensorClass,
java.lang.Class<? extends Moveable> targetClass,
SensorTargetMediator mediatorInstance) |
void |
addMediatorFor(java.lang.Class<? extends Sensor> sensorClass,
java.lang.Class<? extends Moveable> targetClass,
java.lang.Class<? extends SensorTargetMediator> mediatorClass)
Constructs and adds a Mediator to this MediatorFactory.
|
<S extends SensorTargetMediator> |
addMediatorFor(java.lang.Class<? extends Sensor> sensorClass,
java.lang.Class<? extends Moveable> targetClass,
S mediatorInstance) |
void |
addMediatorFor(Sensor sensor,
Moveable target,
SensorTargetMediator mediatorInstance) |
void |
addMediatorFor(java.lang.String first,
java.lang.String second,
java.lang.String mediator)
Constructs and adds a Mediator to the MediatorFactory.
|
void |
clear()
Removes all Mediators from this factory.
|
static MediatorFactory<Sensor,Moveable,SensorTargetMediator> |
getInstance() |
static Mediator |
getMediator(java.lang.Class<? extends Sensor> sensorClass,
java.lang.Class<? extends Mover> targetClass) |
Mediator |
getMediatorFor(java.lang.Class<? extends Sensor> sensorClass,
java.lang.Class<? extends Moveable> targetClass)
Gets the Mediator for the given Sensor Class and Moveable Class.
|
java.util.Map<java.lang.Class<? extends Sensor>,java.util.Map<java.lang.Class<? extends Moveable>,SensorTargetMediator>> |
getMediators()
Returns a copy of the HashMap of Mediators that have been added to this
MediatorFactory.
|
Mediator |
getMeditorFor(Sensor first,
Moveable second)
Gets the Mediator for the given Sensor and Moveable (target)
|
protected static final SensorTargetMediatorFactory instance
private java.util.WeakHashMap<java.lang.Class<? extends Sensor>,java.util.Map<java.lang.Class<? extends Moveable>,SensorTargetMediator>> cache
protected SensorTargetMediatorFactory()
public static MediatorFactory<Sensor,Moveable,SensorTargetMediator> getInstance()
public static void addMediator(java.lang.Class<? extends Sensor> sensorClass, java.lang.Class<? extends Moveable> targetClass, java.lang.Class<? extends SensorTargetMediator> mediatorClass)
sensorClass
- The Class of the Sensor for the added MediatortargetClass
- The Class of the target for the added Mediator (Must
be a Moveable)mediatorClass
- The Class of the Mediator to add.java.lang.IllegalArgumentException
- if the sensorClass is not a Sensor, the
targetClass is not a Moveable or the mediatorClass is not a Mediatorpublic static void addMediator(java.lang.Class<? extends Sensor> sensorClass, java.lang.Class<? extends Moveable> targetClass, SensorTargetMediator mediatorInstance)
public static Mediator getMediator(java.lang.Class<? extends Sensor> sensorClass, java.lang.Class<? extends Mover> targetClass)
sensorClass
- the Sensor Class for which to retrieve the Mediator.targetClass
- the Moveable Class for which to retrieve the Mediator.java.lang.IllegalArgumentException
- if there is no Mediator set for the
given Sensor-target pair.public void addMediatorFor(java.lang.Class<? extends Sensor> sensorClass, java.lang.Class<? extends Moveable> targetClass, java.lang.Class<? extends SensorTargetMediator> mediatorClass)
addMediatorFor
in interface MediatorFactory<Sensor,Moveable,SensorTargetMediator>
sensorClass
- The Class of the Sensor for the added MediatortargetClass
- The Class of the target for the added Mediator (Must
be a MoveablemediatorClass
- The Class of the Mediator to add.java.lang.IllegalArgumentException
- if the sensorClass is not a Sensor, the
targetClass is not a Moveable or the mediatorClass is not a Mediatorpublic void addMediatorFor(Sensor sensor, Moveable target, SensorTargetMediator mediatorInstance)
addMediatorFor
in interface MediatorFactory<Sensor,Moveable,SensorTargetMediator>
public <S extends SensorTargetMediator> void addMediatorFor(java.lang.Class<? extends Sensor> sensorClass, java.lang.Class<? extends Moveable> targetClass, S mediatorInstance)
addMediatorFor
in interface MediatorFactory<Sensor,Moveable,SensorTargetMediator>
public Mediator getMediatorFor(java.lang.Class<? extends Sensor> sensorClass, java.lang.Class<? extends Moveable> targetClass)
getMediatorFor
in interface MediatorFactory<Sensor,Moveable,SensorTargetMediator>
sensorClass
- the Sensor Class for which to retreve the Mediator.targetClass
- the Moveable Class for which to retrieve the Mediator.java.lang.IllegalArgumentException
- if there is no Mediator set for the
given Sensor-target pair, sensorClass is not a Sensor, or targetClass is
not a Moveable.public java.util.Map<java.lang.Class<? extends Sensor>,java.util.Map<java.lang.Class<? extends Moveable>,SensorTargetMediator>> getMediators()
getMediators
in interface MediatorFactory<Sensor,Moveable,SensorTargetMediator>
public void addMediatorFor(java.lang.String first, java.lang.String second, java.lang.String mediator) throws java.lang.ClassNotFoundException
addMediatorFor
in interface MediatorFactory<Sensor,Moveable,SensorTargetMediator>
first
- The name of the Sensor class for the added Mediator.second
- The name of the Moveable (target) class for the added
Meditor.mediator
- The name of the Mediator class to add.java.lang.ClassNotFoundException
- if any of the three parameters are not the
name of a valid Classjava.lang.IllegalArgumentException
- if first is not the name of a Sensor,
second is not the name of a Moveable or mediator is not the name of a
Mediator (but all three are names of valid Classes)public Mediator getMeditorFor(Sensor first, Moveable second)
getMeditorFor
in interface MediatorFactory<Sensor,Moveable,SensorTargetMediator>
first
- The Sensor to get the Mediator for.second
- The Moveable to get the Mediator for.java.lang.IllegalArgumentException
- if there is no Mediator set for the
given Sensor-target pair or if first is not a Sensor or second is not a
Moveable.public void clear()
clear
in interface MediatorFactory<Sensor,Moveable,SensorTargetMediator>