Class ProjectionDryer<T extends Projection>
- java.lang.Object
-
- repast.simphony.freezedry.freezedryers.proj.ProjectionDryer<T>
-
- Direct Known Subclasses:
ContinuousProjectionDryer
,GeographyProjectionDryer
,GridProjectionDryer2
,NetworkProjectionDryer
public abstract class ProjectionDryer<T extends Projection> extends Object
Implementations of this class will handle storing settings for some projections. Implementations should override thehandles(Class)
,#addProperties(Context, T, Map)
,instantiate(Context, Map)
, and#loadProperties(Context, T, Map)
methods. By default this adds (through it's static {}) aNetworkProjectionDryer
, aContinuousProjectionDryer
, and arepast.simphony.freezedry.freezedryers.proj.GridProjectionDryer
.- Author:
- Jerry Vos
- See Also:
handles(Class)
,#addProperties(Context, T, Map)
,instantiate(Context, Map)
,#loadProperties(Context, T, Map)
-
-
Field Summary
Fields Modifier and Type Field Description static String
CONTEXT_LISTENING_KEY
static String
NAME_KEY
static String
PROJ_LISTENING_KEY
-
Constructor Summary
Constructors Constructor Description ProjectionDryer()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static void
addProjectionDryer(ProjectionDryer dryer)
Adds a dryer to be used by theContextFreezeDryer
.protected abstract void
addProperties(Context<?> context, T t, Map<String,Object> properties)
Called when attempting to save the given projection.T
buildAndAddProjection(Context<?> context, Map<String,Object> properties)
Creates a projection based on the given properties.static <T extends Projection>
ProjectionDryer<T>getDryer(Class<T> type)
Retrieves the last added dryer that handles the given type.Map<String,Object>
getProperties(Context<?> context, T t)
Retrieves the serializable properties for a given projection that is a member of the given context.abstract boolean
handles(Class<?> type)
This should return true if the implementation handles projections of the given type.protected abstract T
instantiate(Context<?> context, Map<String,Object> properties)
Should createa a Projection for the given context.protected void
loadProperties(Context<?> context, T proj, Map<String,Object> properties)
This handles loading of properties into the instantiated projection.
-
-
-
Field Detail
-
NAME_KEY
public static final String NAME_KEY
- See Also:
- Constant Field Values
-
PROJ_LISTENING_KEY
public static final String PROJ_LISTENING_KEY
- See Also:
- Constant Field Values
-
CONTEXT_LISTENING_KEY
public static final String CONTEXT_LISTENING_KEY
- See Also:
- Constant Field Values
-
-
Method Detail
-
addProperties
protected abstract void addProperties(Context<?> context, T t, Map<String,Object> properties)
Called when attempting to save the given projection. Implementations should store the settings they require to build the projection later during this method, and also call their super's method so that it can store its properties.- Parameters:
context
- the context this projection is a member oft
- the projection to store properties forproperties
- a place to store the properties for a projection
-
instantiate
protected abstract T instantiate(Context<?> context, Map<String,Object> properties)
Should createa a Projection for the given context. Implementing classes do not have to add the created projection to the context, that will be done after calling this method.- Parameters:
context
- the context the projection will be a member ofproperties
- the properties specified when saving the projection- Returns:
- a created projection
-
handles
public abstract boolean handles(Class<?> type)
This should return true if the implementation handles projections of the given type.- Parameters:
type
- the type of the projection- Returns:
- if the implementation handles the given type
-
loadProperties
protected void loadProperties(Context<?> context, T proj, Map<String,Object> properties)
This handles loading of properties into the instantiated projection. Implementations should override this method and load their properties here. If the properties are loaded in theirinstantiate(Context, Map)
method, then if a subclass overrides the instantiate method it will have to duplicate the property loading (or that loading will not be done). Implementations should call their super's#loadProperties(Context, T, Map)
method so that all properties can be loaded. This implementation loads the projection as a context listener (if it originally one) and the context as a projection listener if it was. This then adds the projection to the context.- Parameters:
context
- the context the projection is a member ofproj
- the projection that was instantiatedproperties
- the properties that should be used to loaded into the projection
-
getProperties
public Map<String,Object> getProperties(Context<?> context, T t)
Retrieves the serializable properties for a given projection that is a member of the given context. These properties should be reloaded and passed to thebuildAndAddProjection(Context, Map)
method when deserializing the projection.- Parameters:
context
- the context the projection is a member oft
- the projection to serialize- Returns:
- a Map of properties used to recreate the given projection
- See Also:
for retrieving the dryer of the projection type
-
buildAndAddProjection
public T buildAndAddProjection(Context<?> context, Map<String,Object> properties)
Creates a projection based on the given properties. It will also add the created projection to the given context.- Parameters:
context
- the context to build a projection forproperties
- the properties for building the projection- Returns:
- the created projection
-
addProjectionDryer
public static void addProjectionDryer(ProjectionDryer dryer)
Adds a dryer to be used by theContextFreezeDryer
. This will be added to the front of the dryer list, so it will override any equivalent dryer added before it that dries the same class.- Parameters:
dryer
- a projection dryer
-
getDryer
public static <T extends Projection> ProjectionDryer<T> getDryer(Class<T> type)
Retrieves the last added dryer that handles the given type. If none is found this returns null.- Parameters:
type
- the projection type to dry- Returns:
- a dryer for the given type
-
-