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 the handles(Class), #addProperties(Context, T, Map), instantiate(Context, Map), and #loadProperties(Context, T, Map) methods.

By default this adds (through it's static {}) a NetworkProjectionDryer, a ContinuousProjectionDryer, and a repast.simphony.freezedry.freezedryers.proj.GridProjectionDryer.

Author:
Jerry Vos
See Also:
  • Field Details

  • Constructor Details

    • ProjectionDryer

      public ProjectionDryer()
  • Method Details

    • 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 of
      t - the projection to store properties for
      properties - 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 of
      properties - 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 their instantiate(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 of
      proj - the projection that was instantiated
      properties - 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 the buildAndAddProjection(Context, Map) method when deserializing the projection.
      Parameters:
      context - the context the projection is a member of
      t - the projection to serialize
      Returns:
      a Map of properties used to recreate the given projection
      See Also:
    • 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 for
      properties - the properties for building the projection
      Returns:
      the created projection
    • addProjectionDryer

      public static void addProjectionDryer(ProjectionDryer dryer)
      Adds a dryer to be used by the ContextFreezeDryer. 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