etomica.atom.iterator
Class ApiInnerVariable

java.lang.Object
  extended by etomica.atom.iterator.ApiInnerVariable
All Implemented Interfaces:
AtomLeafsetIterator, AtomsetIterator, Serializable

public class ApiInnerVariable
extends Object
implements AtomLeafsetIterator, Serializable

Pair iterator synthesized from two atom iterators, such that the inner-loop iteration depends on the outer-loop atom. Pairs are formed from the atoms yielded by the two atom iterators. The inner-loop iterator must implement AtomIteratorAtomDependent, and its set(Atom) method will be invoked with the current outer-loop atom at the start of each inner-loop iteration. All pairs returned by iterator are the same Atom[] instance, and differ only in the Atom instances held by it.

Iterator can be condition to put the atoms in either order in the AtomPair that it returns. Thus the inner-loop Atom may be atom0 of the returned AtomPair, or it may be atom1. This behavior is set at construction, and cannot be changed afterwards. Default behavior has outer loop atoms as atom0, and inner loop atoms as atom1.

See Also:
Serialized Form

Field Summary
protected  AtomIteratorAtomDependent aiInner
          The iterators used to generate the sets of atoms.
protected  AtomIterator aiOuter
           
protected  boolean doSwap
           
protected  AtomPair pair
           
 
Constructor Summary
ApiInnerVariable(AtomIterator aiOuter, AtomIteratorAtomDependent aiInner)
          Construct a pair iterator using the given atom iterators.
ApiInnerVariable(AtomIterator aiOuter, AtomIteratorAtomDependent aiInner, boolean doSwap)
          Construct a pair iterator using the given atom iterators, indicating whether the atoms ordering in the AtomPair should be swapped from the default behavior.
 
Method Summary
 AtomIterator getInnerIterator()
          Accessor method for the inner-loop atom iterator.
 AtomIterator getOuterIterator()
          Accessor method for the outer-loop atom iterator.
 int nBody()
          Returns the number of atoms given in each iterate, i.e., the size of the atom array returned with each call to next().
 IAtomList next()
          Returns the next pair of atoms.
 void reset()
          Resets the iterator, so that it is ready to go through all of its pairs.
 int size()
          Returns the number of pairs given by this iterator.
 void unset()
          Sets the iterator such that hasNext is false.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pair

protected final AtomPair pair

aiInner

protected final AtomIteratorAtomDependent aiInner
The iterators used to generate the sets of atoms.


aiOuter

protected final AtomIterator aiOuter

doSwap

protected final boolean doSwap
Constructor Detail

ApiInnerVariable

public ApiInnerVariable(AtomIterator aiOuter,
                        AtomIteratorAtomDependent aiInner)
Construct a pair iterator using the given atom iterators. Requires call to reset() before beginning iteration.


ApiInnerVariable

public ApiInnerVariable(AtomIterator aiOuter,
                        AtomIteratorAtomDependent aiInner,
                        boolean doSwap)
Construct a pair iterator using the given atom iterators, indicating whether the atoms ordering in the AtomPair should be swapped from the default behavior.

Parameters:
aiOuter - outer-loop iterator
aiInner - inner-loop iterator
doSwap - if false (default), outer-loop atoms are given in atom0, and inner loop in atom1; if true outer-loop atoms are given in atom1, and inner loop in atom0
Method Detail

getOuterIterator

public AtomIterator getOuterIterator()
Accessor method for the outer-loop atom iterator.

Returns:
the current outer-loop iterator

getInnerIterator

public AtomIterator getInnerIterator()
Accessor method for the inner-loop atom iterator.

Returns:
the current inner-loop iterator

unset

public void unset()
Sets the iterator such that hasNext is false.

Specified by:
unset in interface AtomsetIterator

size

public int size()
Returns the number of pairs given by this iterator. Independent of state of hasNext. Clobbers the iteration state (i.e., status of hasNext/next) but does not recondition iterator (i.e., does not change set of iterates that would be given on iteration after reset). Must perform reset if attempting iteration after using size() method.

Specified by:
size in interface AtomsetIterator

reset

public void reset()
Resets the iterator, so that it is ready to go through all of its pairs.

Specified by:
reset in interface AtomsetIterator

next

public IAtomList next()
Returns the next pair of atoms. The same Atom[] instance is returned every time, but the Atoms it holds are (of course) different for each iterate.

Specified by:
next in interface AtomLeafsetIterator

nBody

public final int nBody()
Description copied from interface: AtomsetIterator
Returns the number of atoms given in each iterate, i.e., the size of the atom array returned with each call to next().

Specified by:
nBody in interface AtomsetIterator
Returns: