JGAP

org.jgap.distr
Class CultureMemoryCell

java.lang.Object
  extended by org.jgap.distr.CultureMemoryCell
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

public class CultureMemoryCell
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable

Represents a memory cell used within Culture, a special form of memory.

CultureMemoryCell also stores metadata along with the value-to-store, like date/time of setting a value, change history.

Since:
2.3
See Also:
Serialized Form

Constructor Summary
CultureMemoryCell()
          Default constructor.
CultureMemoryCell(java.lang.String a_name)
          Sets history size to 3.
CultureMemoryCell(java.lang.String a_name, int a_historySize)
          Allows to freely specify informative name of memory cell as well as size of history to keep.
 
Method Summary
 int compareTo(java.lang.Object a_other)
          The compareTo-method.
 boolean equals(java.lang.Object a_other)
          The equals-method.
 java.lang.Object getCurrentValue()
           
 double getCurrentValueAsDouble()
          Convenience method to retrieve a primitive double value from memory easily.
 java.util.List getHistory()
           
 int getHistorySize()
           
 java.lang.String getName()
           
protected  CultureMemoryCell getNewInstance(java.lang.Object a_value, int a_version, java.lang.String a_name)
          Creates a new instance of CultureMemoryCell preset with the given parameters.
 int getReadAccessed()
           
 int getReadAccessedCurrentVersion()
           
 int getVersion()
           
 long getVersionTimeMilliseconds()
           
protected  void incrementVersion()
          Increment version number and keep track of current time.
protected  void keepHistory(java.lang.Object a_value, int a_version, java.lang.String a_name)
          Puts an entry into history.
 void setDouble(double a_value)
          Convenience method to store a primitive double easily.
 void setHistorySize(int a_size)
          Sets the size of the history and scales down the history log it is larger than the given size.
 void setName(java.lang.String a_name)
          Sets the informative name of the memory cell.
 void setValue(java.lang.Object a_value)
          Sets a new memory value.
 java.lang.String toString()
           
protected  void toStringRecursive(java.lang.StringBuffer a_result, int a_historySize)
          Recursive part of toString().
protected  void trimHistory(int a_size)
          Trims the history to the given size.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CultureMemoryCell

public CultureMemoryCell()
Default constructor.

Since:
2.3

CultureMemoryCell

public CultureMemoryCell(java.lang.String a_name)
Sets history size to 3.

Parameters:
a_name - informative name of the memory cell
Since:
2.3

CultureMemoryCell

public CultureMemoryCell(java.lang.String a_name,
                         int a_historySize)
Allows to freely specify informative name of memory cell as well as size of history to keep.

Parameters:
a_name - informative name of the memory cell
a_historySize - size of history to keep. Use values less than 1 for turning history logging off
Since:
2.3
Method Detail

setName

public void setName(java.lang.String a_name)
Sets the informative name of the memory cell.

Parameters:
a_name - informative name
Since:
2.3

getName

public java.lang.String getName()
Returns:
informative name of the memory cell
Since:
2.3

setValue

public void setValue(java.lang.Object a_value)
Sets a new memory value.

Parameters:
a_value - the memory value to set
Since:
2.3

setDouble

public void setDouble(double a_value)
Convenience method to store a primitive double easily.

Parameters:
a_value - double value to store
Since:
2.3

getCurrentValueAsDouble

public double getCurrentValueAsDouble()
Convenience method to retrieve a primitive double value from memory easily. Here a ClassCastException could occur!

Returns:
double value representing current memory value
Since:
2.3

getCurrentValue

public java.lang.Object getCurrentValue()
Returns:
current memory value
Since:
2.3

getHistory

public java.util.List getHistory()
Returns:
list of most recent entries (except current entry). The item at index 0 is the oldest, the item at highest index is the youngest one.
Since:
2.3

getVersion

public int getVersion()
Returns:
version of memory value, read only
Since:
2.3

incrementVersion

protected void incrementVersion()
Increment version number and keep track of current time.

Since:
2.3

keepHistory

protected void keepHistory(java.lang.Object a_value,
                           int a_version,
                           java.lang.String a_name)
Puts an entry into history. Stores all information as a new CultureMemoryCell instance.

Parameters:
a_value - memory value to store
a_version - version of the value
a_name - name to store
Since:
2.3

getNewInstance

protected CultureMemoryCell getNewInstance(java.lang.Object a_value,
                                           int a_version,
                                           java.lang.String a_name)
Creates a new instance of CultureMemoryCell preset with the given parameters. Used for creating history entries.

Parameters:
a_value - memory value to store
a_version - version of the value
a_name - name to store
Returns:
new instance of CultureMemoryCell
Since:
2.3

getReadAccessed

public int getReadAccessed()
Returns:
number of times the memory cell has been read accessed
Since:
2.3

getReadAccessedCurrentVersion

public int getReadAccessedCurrentVersion()
Returns:
number of read accesses since current value has been set. Calculated by subtracting number of read accesses for prior version from total number of read accesses
Since:
2.3

setHistorySize

public void setHistorySize(int a_size)
Sets the size of the history and scales down the history log it is larger than the given size.

Parameters:
a_size - new size of the history log = how many entries to store
Since:
2.3

trimHistory

protected void trimHistory(int a_size)
Trims the history to the given size.

Parameters:
a_size - new size of history
Since:
2.3

getHistorySize

public int getHistorySize()
Returns:
size of the history
Since:
2.3

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
String representation of the cultural memory cell including all important information (also history log).
Since:
2.3

toStringRecursive

protected void toStringRecursive(java.lang.StringBuffer a_result,
                                 int a_historySize)
Recursive part of toString().

Parameters:
a_result - gathered result so far and modified here
a_historySize - history size just for information purpose
Since:
2.3

getVersionTimeMilliseconds

public long getVersionTimeMilliseconds()
Returns:
time in milliseconds when the current version has been created
Since:
3.0

equals

public boolean equals(java.lang.Object a_other)
The equals-method.

Overrides:
equals in class java.lang.Object
Parameters:
a_other - the other object to compare
Returns:
true if the objects are regarded as equal
Since:
3.0

compareTo

public int compareTo(java.lang.Object a_other)
The compareTo-method.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
a_other - the other object to compare
Returns:
-1, 0, 1
Since:
3.0

JGAP