gov.sandia.cognition.framework.lite
Class CogxelStateLite

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.framework.lite.CogxelStateLite
All Implemented Interfaces:
CogxelState, CloneableSerializable, Serializable, Cloneable, Iterable<Cogxel>

public class CogxelStateLite
extends AbstractCloneableSerializable
implements CogxelState

The CogxelStateLite class implements a CogxelState to be used with the CognitiveModelLite.

Since:
1.0
Author:
Justin Basilico
See Also:
Serialized Form

Constructor Summary
CogxelStateLite()
          Creates a new instance of CogxelStateLite
CogxelStateLite(CogxelState other)
          Creates a copy of a CogxelStateLite
CogxelStateLite(int initialCapacity)
          Creates a new instance of CogxelStateLite with an expected initial capacity for the number of cogxels contained in it.
 
Method Summary
 void addCogxel(Cogxel cogxel)
          Adds a Cogxel to the state, overriding the existing Cogxel, if it exists.
 void clear()
          Clears all of the Cogxels in this CogxelState.
 CogxelStateLite clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
 Cogxel getCogxel(SemanticIdentifier identifier)
          Gets a Cogxel from the state, if it has been previously added.
 double getCogxelActivation(SemanticIdentifier identifier)
          Gets the activation level of a Cogxel in the CogxelState.
 Collection<Cogxel> getCogxels()
          Gets the Cogxels that have been previously added to this CogxelState.
 int getNumCogxels()
          Gets the number of existing Cogxels in this CogxelState.
 Cogxel getOrCreateCogxel(SemanticIdentifier identifier, CogxelFactory factory)
          Attempts to get an existing Cogxel for a given SemanticIdentifier.
 boolean hasCogxel(SemanticIdentifier identifier)
          Returns true if there is an existing Cogxel for the given identifier and false otherwise.
 Iterator<Cogxel> iterator()
          
 boolean removeCogxel(Cogxel cogxel)
          Removes a Cogxel from the CogxelState, if it exists.
 boolean removeCogxel(SemanticIdentifier identifier)
          Removes a Cogxel from the state, if it exists.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CogxelStateLite

public CogxelStateLite()
Creates a new instance of CogxelStateLite


CogxelStateLite

public CogxelStateLite(int initialCapacity)
Creates a new instance of CogxelStateLite with an expected initial capacity for the number of cogxels contained in it.

Parameters:
initialCapacity - The initial maximum capacity, as defined as the maximum SemanticIdentifier expected.

CogxelStateLite

public CogxelStateLite(CogxelState other)
Creates a copy of a CogxelStateLite

Parameters:
other - The CogxelState to copy.
Method Detail

clone

public CogxelStateLite clone()
This makes public the clone method on the Object class and removes the exception that it throws. Its default behavior is to automatically create a clone of the exact type of object that the clone is called on and to copy all primitives but to keep all references, which means it is a shallow copy. Extensions of this class may want to override this method (but call super.clone() to implement a "smart copy". That is, to target the most common use case for creating a copy of the object. Because of the default behavior being a shallow copy, extending classes only need to handle fields that need to have a deeper copy (or those that need to be reset). Some of the methods in ObjectUtil may be helpful in implementing a custom clone method. Note: The contract of this method is that you must use super.clone() as the basis for your implementation.

Specified by:
clone in interface CogxelState
Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractCloneableSerializable
Returns:
A clone of this object.

clear

public void clear()
Clears all of the Cogxels in this CogxelState.


addCogxel

public void addCogxel(Cogxel cogxel)
Adds a Cogxel to the state, overriding the existing Cogxel, if it exists.

Specified by:
addCogxel in interface CogxelState
Parameters:
cogxel - The Cogxel to add.
Throws:
IllegalArgumentException - If an invalid Cogxel is given.

hasCogxel

public boolean hasCogxel(SemanticIdentifier identifier)
Returns true if there is an existing Cogxel for the given identifier and false otherwise.

Specified by:
hasCogxel in interface CogxelState
Parameters:
identifier - The identifier to look for the Cogxel.
Returns:
True if there is a Cogxel for the given identifier.

getCogxel

public Cogxel getCogxel(SemanticIdentifier identifier)
Gets a Cogxel from the state, if it has been previously added.

Specified by:
getCogxel in interface CogxelState
Parameters:
identifier - The SemanticIdentifier for the Cogxel.
Returns:
If the SemanticIdentifier exists in the CogxelState, then return the corresponding Cogxel. Otherwise, return null.
Throws:
IllegalArgumentException - If an invalid identifier is given.

getOrCreateCogxel

public Cogxel getOrCreateCogxel(SemanticIdentifier identifier,
                                CogxelFactory factory)
Attempts to get an existing Cogxel for a given SemanticIdentifier. If no such Cogxel exists, it uses the given CogxelFactory to create the Cogxel and adds it to the CogxelState. In either case, as long as a valid SemanticIdentifier is given, it will return a Cogxel.

Specified by:
getOrCreateCogxel in interface CogxelState
Parameters:
identifier - The identifier to get or create a Cogxel for.
factory - The factory to use to create the Cogxel is one does not already exist for the identifier.
Returns:
A Cogxel for the given identifier.
Throws:
IllegalArgumentException - If an invalid identifier is given.

removeCogxel

public boolean removeCogxel(SemanticIdentifier identifier)
Removes a Cogxel from the state, if it exists.

Specified by:
removeCogxel in interface CogxelState
Parameters:
identifier - The SemanticIdentifier of the Cogxel to remove.
Returns:
True if the Cogxel was sucessfully removed, false otherwise.
Throws:
IllegalArgumentException - If an invalid identifier is given.

removeCogxel

public boolean removeCogxel(Cogxel cogxel)
Removes a Cogxel from the CogxelState, if it exists.

Specified by:
removeCogxel in interface CogxelState
Parameters:
cogxel - The Cogxel to remove.
Returns:
True if the Cogxel was sucessfully removed, false otherwise.
Throws:
IllegalArgumentException - If an invalid Cogxel is given.

getCogxelActivation

public double getCogxelActivation(SemanticIdentifier identifier)
Gets the activation level of a Cogxel in the CogxelState. If the associated Cogxel is null then 0.0 is returned, otherwise the getActivation method is called on the underlying Cogxel.

Specified by:
getCogxelActivation in interface CogxelState
Parameters:
identifier - The SemanticIdentifier for the Cogxel to get the activation level of.
Returns:
The activation level of the underlying Cogxel, or 0.0 if the Cogxel doesn't exist in the CogxelState.
Throws:
IllegalArgumentException - If an invalid identifier is given.

getCogxels

public Collection<Cogxel> getCogxels()
Gets the Cogxels that have been previously added to this CogxelState.

Specified by:
getCogxels in interface CogxelState
Returns:
The previously added Cogxels.

getNumCogxels

public int getNumCogxels()
Gets the number of existing Cogxels in this CogxelState.

Specified by:
getNumCogxels in interface CogxelState
Returns:
The number of existing Cogxels in this CogxelState.

iterator

public Iterator<Cogxel> iterator()

Specified by:
iterator in interface Iterable<Cogxel>
Returns: