org.moyoman.helper
Class Helper

java.lang.Object
  |
  +--org.moyoman.helper.Helper
All Implemented Interfaces:
Cloneable, Component, Serializable
Direct Known Subclasses:
RulesHelper

public abstract class Helper
extends Object
implements Component, Serializable, Cloneable

The base class for all helpers in the system. This class is analogous to the Module class for modules.

See Also:
Serialized Form

Field Summary
private  DebugType[] debugTypes
          The debug types that this helper supports.
private  HelperName helperName
          The name of the helper.
private  HashMap helpers
          The key is a HelperType object, and the value is a Helper object.
private  GameId id
          The game that this helper is associated with.
private  Mode mode
          The mode of the game that this helper is used in.
private  Component parent
          The component that this helper is associated with.
private  float time
           
 
Constructor Summary
protected Helper(GameId id, Mode m, HelperName name, Component component)
          Create the helper object.
 
Method Summary
protected  float checkTime()
          Return information on how the game as a whole is doing on time.
 Object clone()
          Clone the helper.
static Helper create(GameId id, Mode mode, HelperType type, Component component)
          Create a Helper object.
protected  Helper createHelper(HelperType ht)
          Create a new helper for the current helper to use.
protected  void debug(String msg)
          Log a debug message in the Helper.
protected  void error(Exception e)
          Log an error in the Helper.
protected  void error(String msg)
          Log an error in the Helper.
protected  void fatal(Exception e)
          Log a fatal error in the Helper.
protected  void fatal(String msg)
          Log a fatal error in the Helper.
protected  Helper[] getAllHelpers()
          Return all of the helpers that this helper is using.
abstract  Debug[] getDebugInformation(DebugType[] types)
          Return the debug information for this module.
abstract  DebugType[] getDebugTypes()
          Return the types of debug information that this module supports.
protected  Helper getHelper(HelperType ht)
          Get the helper of this helper of a particular type.
 HelperName getHelperName()
          Return the HelperName object.
protected  GameId getId()
          Get the id that this module is associated with.
protected  Mode getMode()
          Get the mode for this game.
 Module getModule()
          Get the Module object with which this helper is ultimately associated.
 Component getParent()
          Get the parent of this helper.
abstract  ModuleType[] getRequiredModuleList()
          Get the modules which this helper is dependent on.
 Scheduler getScheduler()
          Get a Scheduler object for the module that contains this helper.
protected  void information(String msg)
          Log an information message in the Helper.
 void setTime(float t)
          Set the time for this module.
protected  void warning(Exception e)
          Log a warning in the Helper.
protected  void warning(String msg)
          Log a warning in the Helper.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debugTypes

private DebugType[] debugTypes
The debug types that this helper supports.


id

private GameId id
The game that this helper is associated with.


mode

private Mode mode
The mode of the game that this helper is used in.


time

private float time

helperName

private HelperName helperName
The name of the helper.


parent

private Component parent
The component that this helper is associated with.


helpers

private HashMap helpers
The key is a HelperType object, and the value is a Helper object.

Constructor Detail

Helper

protected Helper(GameId id,
                 Mode m,
                 HelperName name,
                 Component component)
          throws InternalErrorException
Create the helper object.

Parameters:
id - The id of the game
m - The mode of the game
name - The name of the helper being created.
component - The parent of the helper being created.
Method Detail

create

public static final Helper create(GameId id,
                                  Mode mode,
                                  HelperType type,
                                  Component component)
                           throws InternalErrorException
Create a Helper object.

Parameters:
id - The id of the game.
Returns:
The Helper object.
Throws:
InternalErrorException - Thrown if an error occurs for any reason.

checkTime

protected float checkTime()
Return information on how the game as a whole is doing on time. There is no per-helper resource monitor. This method should be used when trying to determine how much processing to do.

Returns:
This value can vary between -1.0 and 1.0. A value of 1.0 indicates that the game is way ahead on time, -1.0 would indicate severe time problems, and 0.0 indicates that the game is on schedule.

getMode

protected Mode getMode()
Get the mode for this game.

Returns:
A Mode object.

clone

public Object clone()
Clone the helper. This method overrides the one in Object. Cloning helpers is an important requirement for the system to function correctly. The derived class of Helper must override this method. It may be as straightforward as calling super.clone(). Consult any Java textbook for more details. If you are not sure, ask for help.

Overrides:
clone in class Object
Returns:
The cloned Helper object.

setTime

public void setTime(float t)
             throws IllegalArgumentException
Set the time for this module. This value represents the time for the game as a whole, not the particular helper.

Parameters:
t - The time to be set.
Throws:
IllegalArgumentException - Thrown if t is outside the range of -1.0 to 1.0.

getScheduler

public final Scheduler getScheduler()
Get a Scheduler object for the module that contains this helper. The parent of this Helper object may be another Helper object, so keep getting parents until you get a Module object. The Scheduler object contains all objects terminating with one that is the same type as this object. This allows the module to do search based processing.

Returns:
The Scheduler object.

getModule

public Module getModule()
Get the Module object with which this helper is ultimately associated.

Returns:
A Module object.

fatal

protected void fatal(Exception e)
Log a fatal error in the Helper. Eventually, calling this method should result in this helper being terminated, and another helper of the same type replacing it.

Parameters:
e - The exception that was thrown.

error

protected void error(Exception e)
Log an error in the Helper.

Parameters:
e - The exception that was thrown.

warning

protected void warning(Exception e)
Log a warning in the Helper.

Parameters:
e - The exception that was thrown.

fatal

protected void fatal(String msg)
Log a fatal error in the Helper. Eventually, calling this method should result in this helper being terminated, and another helper of the same type replacing it.

Parameters:
msg - The message to be logged.

error

protected void error(String msg)
Log an error in the Helper.

Parameters:
msg - The message to be logged.

warning

protected void warning(String msg)
Log a warning in the Helper.

Parameters:
msg - The message to be logged.

information

protected void information(String msg)
Log an information message in the Helper.

Parameters:
msg - The message to be logged.

debug

protected void debug(String msg)
Log a debug message in the Helper.

Parameters:
msg - The message to be logged.

getParent

public Component getParent()
Get the parent of this helper. It may be either another Helper, or a Module.

Returns:
A Component object.

getDebugInformation

public abstract Debug[] getDebugInformation(DebugType[] types)
Return the debug information for this module.

Parameters:
types - Only return a subset of the debug types in this array.
Returns:
The debug information that this module supports.

getDebugTypes

public abstract DebugType[] getDebugTypes()
Return the types of debug information that this module supports.

Returns:
The types of debug information that this module supports.

getId

protected final GameId getId()
Get the id that this module is associated with.

Returns:
The id of the game.

getHelperName

public final HelperName getHelperName()
Return the HelperName object.

Returns:
The HelperName object.

getAllHelpers

protected Helper[] getAllHelpers()
Return all of the helpers that this helper is using.

Returns:
An array of HelperType objects.

getHelper

protected Helper getHelper(HelperType ht)
                    throws NoSuchDataException
Get the helper of this helper of a particular type.

Parameters:
ht - The helper type to be retrieved.
Returns:
A Helper object.
Throws:
NoSuchDataException - Thrown if this helper does not use a helper of that type.

createHelper

protected Helper createHelper(HelperType ht)
                       throws InternalErrorException
Create a new helper for the current helper to use.

Parameters:
ht - The HelperType of the new helper.
Returns:
A Helper object.
Throws:
InternalErrorException - Thrown if the operation fails for any reason.

getRequiredModuleList

public abstract ModuleType[] getRequiredModuleList()
Get the modules which this helper is dependent on.

Returns:
An array of ModuleType objects.