com.rubecula.darwin.domain.environment
Class Environment_

java.lang.Object
  extended by net.sf.tostring0.AToString
      extended by com.rubecula.darwin.domain.environment.Environment_
All Implemented Interfaces:
CacheSignature, Censusible, Environment, Countable, Visualizable, java.lang.Cloneable, net.sf.tostring0.Identifiable, net.sf.tostring0.IToString
Direct Known Subclasses:
Environment_Muirian, Environment_PepperedMoth, Environment_Susceptible

public abstract class Environment_
extends net.sf.tostring0.AToString
implements Environment

Abstract class defining base methods which implement Environment interface.

Author:
Robin Hillyard

Field Summary
protected  long idealPopulation
          This is the ideal number of organisms for this environment, i.e.
protected static org.apache.commons.logging.Log LOG
          The logger for this class.
 
Fields inherited from interface com.rubecula.darwin.domain.helper.Environment
IDEAL_POPULATION_DEFAULT, S_ID_UNIDENTIFIED
 
Fields inherited from interface net.sf.tostring0.IToString
ANGBR_OPEN, ANGBRA_CLSE, BRA_CLSE, BRA_OPEN, BRCE_OPEN, BRCS_CLSE, COLON, LIST_SEPARATOR, MAX_ELEMENTS_DEFAULT, S_MT, S_PERCENT, SEPARATOR, SPACE
 
Constructor Summary
protected Environment_(Realm realm)
          Secondary constructor of an empty unidentified environment with default initial value for ideal population (no eco factors).
protected Environment_(java.lang.String identifier, Realm realm)
          Secondary constructor of an empty identified environment with default initial value for ideal population (no eco factors).
protected Environment_(java.lang.String identifier, Realm realm, long idealPopulation)
          Primary constructor an empty identified environment with given ideal population (no eco factors).
 
Method Summary
 java.lang.Object addFactor(EcoFactor factor)
          Not the favored method of adding an EcoFactor to an Environment.
 boolean addListener(EnvironmentListener listener)
          Mutating method to add a listener to changes in this Environment.
 boolean censusMe(Census census, java.lang.Object context)
          Method to census this object.
 java.lang.Object clone()
           
protected  void environmentChanged()
          This method should be called whenever the environment has changed.
 boolean equals(java.lang.Object obj)
           
 java.util.Set<java.lang.String> factorKeys()
           
 void fireEnvironmentChanged()
          XXX
 java.util.Collection<? extends Censusible> getCensusibleChildren()
          Method to return a list of censusible children of this object.
 int getCount()
           
 double getEcoFactorValue(java.lang.String name)
          Method to retrieve the value of the eco factor defined by name.
 java.util.Collection<EcoFactor> getEcoSystem()
           
 EcoFactor getFactor(java.lang.String name)
          Method to retrieve the eco factor defined by name.
 long getIdealPopulation()
          XXX
 java.lang.String getIdentifier()
           
 java.util.Collection<Individual> getIndividuals()
           
 java.util.Collection<EnvironmentListener> getListeners()
           
 Realm getRealm()
           
 java.lang.String getSignature()
           
 Sink getSink()
           
 int hashCode()
           
 void setEcoSystem(java.util.Collection<EcoFactor> ecoFactors)
          Set the ecoFactors for this environment to the collection provided.
 void setIdealPopulation(long idealPopulation)
           
 void setListeners(java.util.Collection<EnvironmentListener> listeners)
          Add the given set of environment listeners according to the collection provided.
 void setSink(Sink sink)
           
 boolean update(java.lang.String factorKey, java.lang.Object factorValue)
          Find and set the eco factor to have the factor value, then, if successful, invoke fireEnvironmentChanged().
 
Methods inherited from class net.sf.tostring0.AToString
toString, toString, toStringBrief, toStringId
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.rubecula.darwin.domain.helper.Environment
init
 

Field Detail

LOG

protected static final org.apache.commons.logging.Log LOG
The logger for this class.


idealPopulation

protected transient long idealPopulation
This is the ideal number of organisms for this environment, i.e. the number that the environment can support. If more than one population exists in this environment, each will compete -- the ideal population refers to the total of all populations. The default value is Environment.IDEAL_POPULATION_DEFAULT.

Constructor Detail

Environment_

protected Environment_(Realm realm)
Secondary constructor of an empty unidentified environment with default initial value for ideal population (no eco factors).

Parameters:
realm -

Environment_

protected Environment_(java.lang.String identifier,
                       Realm realm)
Secondary constructor of an empty identified environment with default initial value for ideal population (no eco factors).

Parameters:
identifier -
realm -

Environment_

protected Environment_(java.lang.String identifier,
                       Realm realm,
                       long idealPopulation)
Primary constructor an empty identified environment with given ideal population (no eco factors).

Parameters:
identifier - the identifier for this Environment (for logging).
realm -
idealPopulation - the initial value of ideal population
Method Detail

addFactor

public java.lang.Object addFactor(EcoFactor factor)
Not the favored method of adding an EcoFactor to an Environment. Normally, we use setEcoSystem(Collection).

Specified by:
addFactor in interface Environment
Parameters:
factor - the eco factor, whose identifier will be used as the key.
Returns:
the previous eco factor with the same identifier (if any), otherwise null.
See Also:
Environment.addFactor(com.rubecula.darwin.domain.helper.EcoFactor)

addListener

public boolean addListener(EnvironmentListener listener)
Description copied from interface: Environment
Mutating method to add a listener to changes in this Environment.

Specified by:
addListener in interface Environment
Parameters:
listener - an object which is interested in changes to the environment.
Returns:
true if the listener was successfully added.
See Also:
Collection.add(java.lang.Object)

censusMe

public boolean censusMe(Census census,
                        java.lang.Object context)
Description copied from interface: Censusible
Method to census this object.

Specified by:
censusMe in interface Censusible
Parameters:
census - the census object which will present the results of taking this census
context - an arbitrary object which can be used by the census object to provide appropriate context for this object.
Returns:
true if we should continue censusing this object at deeper levels. If the result is false, then we do not call Censusible.getCensusibleChildren().
See Also:
Censusible.censusMe(com.rubecula.darwin.domain.helper.Census, java.lang.Object)

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException
See Also:
Object.clone()

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

factorKeys

public java.util.Set<java.lang.String> factorKeys()
Specified by:
factorKeys in interface Environment
Returns:
the set of eco factor identifiers
See Also:
Environment.factorKeys()

fireEnvironmentChanged

public void fireEnvironmentChanged()
XXX

Specified by:
fireEnvironmentChanged in interface Environment
See Also:
Environment.fireEnvironmentChanged()

getCensusibleChildren

public java.util.Collection<? extends Censusible> getCensusibleChildren()
Description copied from interface: Censusible
Method to return a list of censusible children of this object.

Specified by:
getCensusibleChildren in interface Censusible
Returns:
either null or an ArrayList of censusible objects.
See Also:
Censusible.getCensusibleChildren()

getCount

public int getCount()
Specified by:
getCount in interface Countable
Returns:
the number of members of this group.
See Also:
Countable.getCount()

getEcoFactorValue

public double getEcoFactorValue(java.lang.String name)
Description copied from interface: Environment
Method to retrieve the value of the eco factor defined by name.

Specified by:
getEcoFactorValue in interface Environment
Parameters:
name - the name (identifier, key) of the eco factor.
Returns:
the eco factor value, as a double. If the value cannot be rendered as double, the result is undefined. XXX consider eliminating this method.
See Also:
Environment.getEcoFactorValue(java.lang.String)

getEcoSystem

public java.util.Collection<EcoFactor> getEcoSystem()
Specified by:
getEcoSystem in interface Environment
Returns:
the eco factors for the eco system of this environment
See Also:
Environment.getEcoSystem()

getFactor

public EcoFactor getFactor(java.lang.String name)
Description copied from interface: Environment
Method to retrieve the eco factor defined by name.

Specified by:
getFactor in interface Environment
Parameters:
name - the name (identifier, key) of the eco factor.
Returns:
the eco factor value itself.
See Also:
Environment.getFactor(java.lang.String)

getIdealPopulation

public long getIdealPopulation()
XXX

Specified by:
getIdealPopulation in interface Environment
Returns:
the ideal population
See Also:
Environment.getIdealPopulation()

getIdentifier

public java.lang.String getIdentifier()
Specified by:
getIdentifier in interface net.sf.tostring0.Identifiable
See Also:
Identifiable.getIdentifier()

getIndividuals

public java.util.Collection<Individual> getIndividuals()
Specified by:
getIndividuals in interface Visualizable
Returns:
a collection of individuals which make up this Visualizable
See Also:
Visualizable.getIndividuals()

getListeners

public java.util.Collection<EnvironmentListener> getListeners()
Specified by:
getListeners in interface Environment
Returns:
the current set of environment listeners.

getRealm

public Realm getRealm()
Specified by:
getRealm in interface Visualizable
Returns:
the realm in which this environment acts.
See Also:
Visualizable.getRealm()

getSignature

public java.lang.String getSignature()
Specified by:
getSignature in interface CacheSignature
Returns:
a "signature" for this object which can be used to form part of a cache key. The signature is similar in a sense to the hash code but typically, it is based more on mutable components of an object than is the hash code.
See Also:
CacheSignature.getSignature()

getSink

public Sink getSink()
Specified by:
getSink in interface Visualizable
Returns:
an output destination for informational messages
See Also:
Visualizable.getSink()

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

setEcoSystem

public void setEcoSystem(java.util.Collection<EcoFactor> ecoFactors)
Set the ecoFactors for this environment to the collection provided. Any prior ecoFactors are forgotten.

Specified by:
setEcoSystem in interface Environment
Parameters:
ecoFactors -

setIdealPopulation

public void setIdealPopulation(long idealPopulation)
Specified by:
setIdealPopulation in interface Environment
See Also:
Environment.setIdealPopulation(long)

setListeners

public void setListeners(java.util.Collection<EnvironmentListener> listeners)
Add the given set of environment listeners according to the collection provided. Any prior listeners will remain.

Specified by:
setListeners in interface Environment
Parameters:
listeners -

setSink

public void setSink(Sink sink)
Parameters:
sink -

update

public boolean update(java.lang.String factorKey,
                      java.lang.Object factorValue)
Find and set the eco factor to have the factor value, then, if successful, invoke fireEnvironmentChanged().

Specified by:
update in interface Environment
Parameters:
factorKey -
factorValue -
Returns:
true if the environment was updated.

environmentChanged

protected void environmentChanged()
This method should be called whenever the environment has changed.



Copyright © 2010 Rubecula Software, LLC. All Rights Reserved.