etomica.atom
Class AtomLeafAgentManager

java.lang.Object
  extended by etomica.box.BoxListenerAdapter
      extended by etomica.atom.AtomLeafAgentManager
All Implemented Interfaces:
IBoxListener, Serializable

public class AtomLeafAgentManager
extends BoxListenerAdapter
implements Serializable

AtomAgentManager acts on behalf of client classes (an AgentSource) to manage agents for every leaf Atom in a box. When leaf atoms are added or removed from the box, the agents array (indexed by the atom's global index) is updated. The client can access and modify the agents via getAgent and setAgent.

See Also:
Serialized Form

Nested Class Summary
static class AtomLeafAgentManager.AgentIterator
          Iterator that loops over the agents, skipping null elements
static interface AtomLeafAgentManager.AgentSource
          Interface for an object that wants an agent associated with each Atom in a Box.
 
Field Summary
protected  Object[] agents
           
protected  AtomLeafAgentManager.AgentSource agentSource
           
protected  IBox box
           
protected  int reservoirSize
           
 
Constructor Summary
AtomLeafAgentManager(AtomLeafAgentManager.AgentSource source, IBox box)
           
 
Method Summary
protected  void addAgent(IAtom a)
          Adds an agent for the given leaf atom to the agents array.
protected  void addAgent(IAtom a, int index)
          Adds an agent for the given leaf atom to the agents array at the given index.
 void boxAtomLeafIndexChanged(IBoxAtomIndexEvent e)
           
 void boxGlobalAtomLeafIndexChanged(IBoxIndexEvent e)
           
 void boxMoleculeAdded(IBoxMoleculeEvent e)
           
 void boxMoleculeRemoved(IBoxMoleculeEvent e)
           
 void dispose()
          Notifies the AtomAgentManager it should disconnect itself as a listener.
 Object getAgent(IAtom a)
          Returns the agent associated with the given IAtom.
 IBox getBox()
          Convenience method to return the box the Manager is tracking.
 int getReservoirSize()
           
 AtomLeafAgentManager.AgentIterator makeIterator()
          Returns an iterator that returns each non-null agent
 void setAgent(IAtom a, Object newAgent)
          Sets the agent associated with the given atom to be the given agent.
 void setReservoirSize(int newReservoirSize)
          Sets the size of the manager's "reservoir".
protected  void setupBox()
          Sets the Box in which this AtomAgentManager will manage Atom agents.
 
Methods inherited from class etomica.box.BoxListenerAdapter
boxAtomAdded, boxAtomRemoved, boxGlobalAtomIndexChanged, boxMoleculeIndexChanged, boxNeighborsUpdated, boxNumberMolecules
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

agentSource

protected final AtomLeafAgentManager.AgentSource agentSource

agents

protected Object[] agents

box

protected final IBox box

reservoirSize

protected int reservoirSize
Constructor Detail

AtomLeafAgentManager

public AtomLeafAgentManager(AtomLeafAgentManager.AgentSource source,
                            IBox box)
Method Detail

setReservoirSize

public void setReservoirSize(int newReservoirSize)
Sets the size of the manager's "reservoir". When an atom is removed, the agents array will only be trimmed if the number of holes in the array exceeds the reservoir size. Also, when the array has no holes and another atom is added, the array will resized to be numAtoms+reservoirSize to avoid reallocating a new array every time an atom is added. reservoirSize=0 means the array will always be the same size as the number of atoms (no holes). The default reservoir size is 30.


getReservoirSize

public int getReservoirSize()

makeIterator

public AtomLeafAgentManager.AgentIterator makeIterator()
Returns an iterator that returns each non-null agent


getAgent

public Object getAgent(IAtom a)
Returns the agent associated with the given IAtom. The IAtom must be from the Box associated with this instance.


setAgent

public void setAgent(IAtom a,
                     Object newAgent)
Sets the agent associated with the given atom to be the given agent. The IAtom must be from the Box associated with this instance. The IAtom's old agent is not released. This should be done manually if needed.


getBox

public IBox getBox()
Convenience method to return the box the Manager is tracking.


dispose

public void dispose()
Notifies the AtomAgentManager it should disconnect itself as a listener.


setupBox

protected void setupBox()
Sets the Box in which this AtomAgentManager will manage Atom agents.


boxMoleculeAdded

public void boxMoleculeAdded(IBoxMoleculeEvent e)
Specified by:
boxMoleculeAdded in interface IBoxListener
Overrides:
boxMoleculeAdded in class BoxListenerAdapter

boxMoleculeRemoved

public void boxMoleculeRemoved(IBoxMoleculeEvent e)
Specified by:
boxMoleculeRemoved in interface IBoxListener
Overrides:
boxMoleculeRemoved in class BoxListenerAdapter

boxAtomLeafIndexChanged

public void boxAtomLeafIndexChanged(IBoxAtomIndexEvent e)
Specified by:
boxAtomLeafIndexChanged in interface IBoxListener
Overrides:
boxAtomLeafIndexChanged in class BoxListenerAdapter

boxGlobalAtomLeafIndexChanged

public void boxGlobalAtomLeafIndexChanged(IBoxIndexEvent e)
Specified by:
boxGlobalAtomLeafIndexChanged in interface IBoxListener
Overrides:
boxGlobalAtomLeafIndexChanged in class BoxListenerAdapter

addAgent

protected void addAgent(IAtom a)
Adds an agent for the given leaf atom to the agents array.


addAgent

protected void addAgent(IAtom a,
                        int index)
Adds an agent for the given leaf atom to the agents array at the given index.