gov.sandia.cognition.math.matrix
Class MatrixUnionIterator

java.lang.Object
  extended by gov.sandia.cognition.math.matrix.MatrixUnionIterator
All Implemented Interfaces:
Iterator<TwoMatrixEntry>
Direct Known Subclasses:
MatrixUnionIteratorMTJ

@CodeReview(reviewer="Jonathan McClain",
            date="2006-05-16",
            changesNeeded=false,
            comments="A few comments, marked with triple slashes",
            response=@CodeReviewResponse(respondent="Kevin R. Dixon",date="2006-05-18",moreChangesNeeded=false,comments="Fixes from J.T.\'s code review"))
public class MatrixUnionIterator
extends Object
implements Iterator<TwoMatrixEntry>

Iterator that stops at all nonzero entries for EITHER underlying matrix

Since:
1.0
Author:
Kevin R. Dixon

Constructor Summary
MatrixUnionIterator(Iterator<MatrixEntry> firstIterator, Iterator<MatrixEntry> secondIterator, TwoMatrixEntry internalEntry, EntryIndexComparator<MatrixEntry> indexComparator)
          Creates a new instance of MatrixUnionIterator
 
Method Summary
protected  void advanceInternalIterators()
          Internal routine for advancing the internal iterators
 MatrixEntry getFirstInternalEntry()
          getter for firstInternalEntry
 Iterator<MatrixEntry> getFirstIterator()
          getter for firstInterator
 EntryIndexComparator<MatrixEntry> getIndexComparator()
          Gets the index comparator.
 TwoMatrixEntry getInternalEntry()
          getter for internalEntry
 MatrixEntry getSecondInternalEntry()
          getter for secondInternalEntry
 Iterator<MatrixEntry> getSecondIterator()
          getter for secondIterator
 boolean hasNext()
          
 TwoMatrixEntry next()
          
 void remove()
          
 boolean safeFirstNext()
          Try to advance the first entry...
 boolean safeSecondNext()
          Try to advance the second entry...
 void setFirstInternalEntry(MatrixEntry firstInternalEntry)
          setter for firstInternalEntry
 void setFirstIterator(Iterator<MatrixEntry> firstIterator)
          setter for firstInterator
protected  void setIndexComparator(EntryIndexComparator<MatrixEntry> indexComparator)
          Sets the index comparator.
 void setInternalEntry(TwoMatrixEntry internalEntry)
          setter for internalEntry
 void setSecondInternalEntry(MatrixEntry secondInternalEntry)
          setter for secondInternalEntry
 void setSecondIterator(Iterator<MatrixEntry> secondIterator)
          setter for secondIterator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatrixUnionIterator

public MatrixUnionIterator(Iterator<MatrixEntry> firstIterator,
                           Iterator<MatrixEntry> secondIterator,
                           TwoMatrixEntry internalEntry,
                           EntryIndexComparator<MatrixEntry> indexComparator)
Creates a new instance of MatrixUnionIterator

Parameters:
firstIterator - Iterator from the first Matrix
secondIterator - Iterator from the second Matrix
internalEntry - TwoMatrixEntry for this
indexComparator - The index comparator for the matrices.
Method Detail

getFirstIterator

public Iterator<MatrixEntry> getFirstIterator()
getter for firstInterator

Returns:
Iterator from the first Matrix

setFirstIterator

public void setFirstIterator(Iterator<MatrixEntry> firstIterator)
setter for firstInterator

Parameters:
firstIterator - Iterator from the first Matrix

getSecondIterator

public Iterator<MatrixEntry> getSecondIterator()
getter for secondIterator

Returns:
Iterator from the second matrix

setSecondIterator

public void setSecondIterator(Iterator<MatrixEntry> secondIterator)
setter for secondIterator

Parameters:
secondIterator - Iterator from the second Matrix

getFirstInternalEntry

public MatrixEntry getFirstInternalEntry()
getter for firstInternalEntry

Returns:
MatrixEntry into the first Matrix

setFirstInternalEntry

public void setFirstInternalEntry(MatrixEntry firstInternalEntry)
setter for firstInternalEntry

Parameters:
firstInternalEntry - MatrixEntry for the first Matrix

getSecondInternalEntry

public MatrixEntry getSecondInternalEntry()
getter for secondInternalEntry

Returns:
MatrixEntry from the second Matrix

setSecondInternalEntry

public void setSecondInternalEntry(MatrixEntry secondInternalEntry)
setter for secondInternalEntry

Parameters:
secondInternalEntry - MatrixEntry from the second Matrix

getInternalEntry

public TwoMatrixEntry getInternalEntry()
getter for internalEntry

Returns:
TwoMatrixEntry that represents the entries of both matrices

setInternalEntry

public void setInternalEntry(TwoMatrixEntry internalEntry)
setter for internalEntry

Parameters:
internalEntry - TwoMatrixEntry that contains the entries for both matrices

getIndexComparator

public EntryIndexComparator<MatrixEntry> getIndexComparator()
Gets the index comparator.

Returns:
The index comparator.

setIndexComparator

protected void setIndexComparator(EntryIndexComparator<MatrixEntry> indexComparator)
Sets the index comparator.

Parameters:
indexComparator - The index comparator.

safeFirstNext

public boolean safeFirstNext()
Try to advance the first entry... if the iterator throws an exception, then there are no more elements in the matrix, so just null out the entry

Returns:
true if next was valid, false otherwise

safeSecondNext

public boolean safeSecondNext()
Try to advance the second entry... if the iterator throws an exception, then there are no more elements in the vector, so just null out the entry

Returns:
true if next was valid, false otherwise

advanceInternalIterators

protected void advanceInternalIterators()
Internal routine for advancing the internal iterators


hasNext

public boolean hasNext()

Specified by:
hasNext in interface Iterator<TwoMatrixEntry>
Returns:

next

public TwoMatrixEntry next()

Specified by:
next in interface Iterator<TwoMatrixEntry>
Returns:

remove

public void remove()
            throws UnsupportedOperationException,
                   NoSuchElementException

Specified by:
remove in interface Iterator<TwoMatrixEntry>
Throws:
UnsupportedOperationException - Always.
NoSuchElementException - If there is no element to remove.