org.micropsi.nodenet
Class InnerStateContainer

java.lang.Object
  extended byorg.micropsi.nodenet.InnerStateContainer
All Implemented Interfaces:
InnerStateInspectorIF

public final class InnerStateContainer
extends java.lang.Object
implements InnerStateInspectorIF

InnerStateContainers contain the published (and persistent) inner states of an native module implementation.
What "published" actually means is that the native module implementation uses its innerstate object for storing variables.


Constructor Summary
protected InnerStateContainer()
           
 
Method Summary
 boolean changeInnerState(java.lang.String key, java.lang.String value)
          Changes an inner state if, and only if, the module already created the state.
 void ensureStateExistence(java.lang.String key, java.lang.String defaultValue)
          This ensures that an inner state exists.
 java.lang.String getInnerState(java.lang.String key)
          Returns the value of an inner state by it's key.
 java.lang.String[] getInnerStates()
          Returns an array with the inner state's keys.
 java.lang.String getInspectionString()
          Returns a String that describes the inner state of the module, inculding the classname and all persistent states (key/value)
protected  java.util.HashMap getMap()
          Returns the map of inner states for saving them
 double getStateDouble(java.lang.String key)
          Returns a state as a double.
 int getStateInt(java.lang.String key)
          Returns a state as an int.
 long getStateLong(java.lang.String key)
          Returns a state as a long.
 java.lang.String getStateString(java.lang.String key)
          Returns a state as a String.
protected  void setMap(java.util.HashMap map)
          Sets the map of inner states after loading them from somewhere
 void setState(java.lang.String key, double value)
          Sets a state.
 void setState(java.lang.String key, int value)
          Sets a state.
 void setState(java.lang.String key, long value)
          Sets a state.
 void setState(java.lang.String key, java.lang.String value)
          Sets a state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InnerStateContainer

protected InnerStateContainer()
Method Detail

getMap

protected java.util.HashMap getMap()
Returns the map of inner states for saving them

Returns:
HashMap the inner states

setMap

protected void setMap(java.util.HashMap map)
Sets the map of inner states after loading them from somewhere

Parameters:
map - the inner states

setState

public void setState(java.lang.String key,
                     java.lang.String value)
Sets a state. If the state does not exist, it will be created

Parameters:
key - the state's key
value - the value

setState

public void setState(java.lang.String key,
                     long value)
Sets a state. If the state does not exist, it will be created

Parameters:
key - the state's key
value - the value

setState

public void setState(java.lang.String key,
                     double value)
Sets a state. If the state does not exist, it will be created

Parameters:
key - the state's key
value - the value

setState

public void setState(java.lang.String key,
                     int value)
Sets a state. If the state does not exist, it will be created

Parameters:
key - the state's key
value - the value

getStateString

public java.lang.String getStateString(java.lang.String key)
Returns a state as a String. This works for all states.

Parameters:
key - the key of the state to be retrieved
Returns:
String the value

getStateLong

public long getStateLong(java.lang.String key)
Returns a state as a long. If the value can't be interpreted as a long, zero will be returned. (Don't rely on this, it's more of a side effect than a feature and slow)

Parameters:
key - the key of the state to be retrieved
Returns:
long the value

getStateDouble

public double getStateDouble(java.lang.String key)
Returns a state as a double. If the value can't be interpreted as double, zero will be returned. (Don't rely on this, it's more of a side effect than a feature and slow)

Parameters:
key - the key of the state to be retrieved
Returns:
double the value

getStateInt

public int getStateInt(java.lang.String key)
Returns a state as an int. If the value can't be interpreted as int, zero will be returned. (Don't rely on this, it's more of a side effect than a feature and slow)

Parameters:
key - the key of the state to be retrieved
Returns:
int the value

getInnerStates

public java.lang.String[] getInnerStates()
Description copied from interface: InnerStateInspectorIF
Returns an array with the inner state's keys. You can safely use that array, it won't be null, but may of course have the size 0 if there are no published inner states,

Specified by:
getInnerStates in interface InnerStateInspectorIF
Returns:
String[] the keys of the published inner states
See Also:
InnerStateInspectorIF.getInnerStates()

getInspectionString

public java.lang.String getInspectionString()
Description copied from interface: InnerStateInspectorIF
Returns a String that describes the inner state of the module, inculding the classname and all persistent states (key/value)

Specified by:
getInspectionString in interface InnerStateInspectorIF
Returns:
String the description
See Also:
InnerStateInspectorIF.getInspectionString()

getInnerState

public java.lang.String getInnerState(java.lang.String key)
Description copied from interface: InnerStateInspectorIF
Returns the value of an inner state by it's key. The returned String can be null if there is no inner state with that key

Specified by:
getInnerState in interface InnerStateInspectorIF
Parameters:
key - the key
Returns:
String the value
See Also:
InnerStateInspectorIF.getInnerState(String)

changeInnerState

public boolean changeInnerState(java.lang.String key,
                                java.lang.String value)
Description copied from interface: InnerStateInspectorIF
Changes an inner state if, and only if, the module already created the state. You can not create a state with this method. If you call it with a key of an inexisting state, it will return false and do nothing

Specified by:
changeInnerState in interface InnerStateInspectorIF
Parameters:
key - the state's key
value - the new value
Returns:
boolean true if there was a state that could be modified
See Also:
InnerStateInspectorIF.changeInnerState(String, String)

ensureStateExistence

public void ensureStateExistence(java.lang.String key,
                                 java.lang.String defaultValue)
This ensures that an inner state exists. If it does not exist, it will be created with the defaultValue parameter as it's value. If the state exists, nothing will happen.

Parameters:
key - the key of the value
defaultValue - the default value

(c) by Micropsi Project: http://www.cognitive-agents.org

.