sysModel.env
Class AGlobalEnv.ALocalEnv

java.lang.Object
  extended by sysModel.env.AGlobalEnv.ALocalEnv
Direct Known Subclasses:
ASquareEnv.ASquareLocalEnvironment, NoGridEnv.LocalEnvironment
Enclosing class:
AGlobalEnv

public abstract class AGlobalEnv.ALocalEnv
extends java.lang.Object

Abstract bsae class of the environment local to a fish.

Author:
Mathias Ricken

Field Summary
(package private)  ILocalEnvState _state
          State.
 
Constructor Summary
AGlobalEnv.ALocalEnv()
           
 
Method Summary
abstract  void drawFish(AFish fish, java.awt.Graphics2D g, java.awt.Component comp)
          Draw the fish on the graphics object.
 java.lang.Object execute(AGlobalEnv.ILocalEnvVisitor visitor, java.lang.Object param)
          Execute a visitor on this local environment.
protected abstract  AGlobalEnv.ALocalEnv makeMoveFwdLocalEnv()
          Make local environment in forward direction.
protected abstract  ILambda makeMoveLambda(AGlobalEnv.ALocalEnv le)
          Factory method for a move lambda.
 void removeFish(AFish fish)
          Remove the fish from the environment.
 void setState(ILocalEnvState state)
          Set state.
 java.lang.Object tryBreedFwd(AFish fish, ILambda blockedCmd, ILambda openCmd)
          Attempt to breed the fish forward, which may or may not be successful.
 java.lang.Object tryMoveFwd(AFish fish, ILambda blockedCmd, ILambda openCmd)
          Attempt to move the fish forward, which may or may not be successful.
abstract  void turnRight(AFish fish, double radians)
          Turn the fish radians to the right.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_state

ILocalEnvState _state
State.

Constructor Detail

AGlobalEnv.ALocalEnv

public AGlobalEnv.ALocalEnv()
Method Detail

tryMoveFwd

public java.lang.Object tryMoveFwd(AFish fish,
                                   ILambda blockedCmd,
                                   ILambda openCmd)
Attempt to move the fish forward, which may or may not be successful. The behavior in each case is defined by the visitor: - If the move cannot be executed, the blockedCmd lambda is applied. The parameter is not used and set to null. - If the move can be executed, the openCmd lambda is applied. The parameter is an ILambda that can to be executed to actually move the fish to the target location of this move. The ILambda ignores the input parameter and returns null.

Parameters:
fish - AFish to move
blockedCmd - lambda to apply if blocked
openCmd - lambda to apply if open
Returns:
return value of lambda executed

tryBreedFwd

public java.lang.Object tryBreedFwd(AFish fish,
                                    ILambda blockedCmd,
                                    ILambda openCmd)
Attempt to breed the fish forward, which may or may not be successful. The behavior in each case is defined by the visitor: - If the breeding cannot be executed, the blockedCmd lambda is applied. The parameter is not used and set to null. - If the breeding can be executed, the openCmd lambda is applied. The parameter is an ILambda that can to be executed to actually move the fish to the target location of this breeding. The ILambda ignores the input parameter and returns null.

Parameters:
fish - AFish to move
blockedCmd - lambda to apply if blocked
openCmd - lambda to apply if open
Returns:
return value of lambda executed

drawFish

public abstract void drawFish(AFish fish,
                              java.awt.Graphics2D g,
                              java.awt.Component comp)
Draw the fish on the graphics object. The graphics object still has to be translated and rotated properly,

Parameters:
fish - AFish to drawFish
g - graphics object to drawFish on
comp - component to drawFish on

turnRight

public abstract void turnRight(AFish fish,
                               double radians)
Turn the fish radians to the right.

Parameters:
fish - AFish to turn
radians - radians to turn

removeFish

public void removeFish(AFish fish)
Remove the fish from the environment.

Parameters:
fish - AFish to remove

execute

public java.lang.Object execute(AGlobalEnv.ILocalEnvVisitor visitor,
                                java.lang.Object param)
Execute a visitor on this local environment.

Parameters:
visitor - visitor to execute
param - visitor-specific parameter
Returns:
visitor-specific return value

setState

public void setState(ILocalEnvState state)
Set state.

Parameters:
state - new state

makeMoveLambda

protected abstract ILambda makeMoveLambda(AGlobalEnv.ALocalEnv le)
Factory method for a move lambda.

Parameters:
le - local environment for the target
Returns:
move lambda to execute the move to the target

makeMoveFwdLocalEnv

protected abstract AGlobalEnv.ALocalEnv makeMoveFwdLocalEnv()
Make local environment in forward direction. Do not block yourself.

Returns:
new local environment in forward direction