byucc.jhdl.synth.graph
Class SubsetIterator

java.lang.Object
  extended bybyucc.jhdl.synth.graph.SubsetIterator
All Implemented Interfaces:
GenericIterator
Direct Known Subclasses:
BlockIterator

public class SubsetIterator
extends java.lang.Object
implements GenericIterator

A class that supports iteration over a subset of elements in another iterator. The SubsetIterator class provides a convenient mechanism for accessing a set of elements in an iterator that meet some selection criteria. The contains method of a SubsetSelector is used to specify the selection criteria.

For example, if you had an iterator of objects with some numeric value associated with each element, and you were only interested in the elements with positive values you could do something like this:

 // elements is an iterator containing NumericValue objects of arbitrary values
 SubsetIterator positiveElements = new SubsetIterator(elements, new PositiveSelector);

 // where PositiveSelector could be defined as:
 class PositiveSelector implements SubsetSelector {
   public boolean contains(Object elt) {
     if (elt instanceof NumericValue) {
       return (((NumericValue) elt).getValue() > 0);
     else
       return false;
 }
 

See Also:
SubsetSelector

Field Summary
protected  GenericIterator iterator
           
protected  SubsetSelector selector
           
 
Constructor Summary
SubsetIterator(GenericIterator iterator, SubsetSelector selector)
          Construct a new SubsetIterator that will iterate over the items in iterator for which selector.contains() returns true.
 
Method Summary
 boolean deleteElt()
          Remove the current element from the series.
 GenericIterator first()
          Move this iterator's "pointer" to the first element in the subset.
 java.lang.Object getElt()
          Retrieves the object currently pointed at by the iterator.
 boolean isValid()
          Checks if the iterator currently points to a valid item in the series.
 GenericIterator last()
          Move this iterator's "pointer" to the last element in the subset.
 boolean moveTo(java.lang.Object elt)
          Moves the iterator to the specified element.
 GenericIterator next()
          Moves the iterator to the next element in the subset.
 GenericIterator prev()
          Moves the iterator to the previous element in the subset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

iterator

protected GenericIterator iterator

selector

protected SubsetSelector selector
Constructor Detail

SubsetIterator

public SubsetIterator(GenericIterator iterator,
                      SubsetSelector selector)
Construct a new SubsetIterator that will iterate over the items in iterator for which selector.contains() returns true.

Parameters:
iterator - An iterator that contains elements of interest.
selector - A SubsetSelector whose contains method identifies the elements of interest in iterator.
Method Detail

first

public GenericIterator first()
Move this iterator's "pointer" to the first element in the subset.

Specified by:
first in interface GenericIterator
Returns:
this SubsetIterator, (suitable for chaining)

last

public GenericIterator last()
Move this iterator's "pointer" to the last element in the subset.

Specified by:
last in interface GenericIterator
Returns:
this SubsetIterator, (suitable for chaining)

isValid

public boolean isValid()
Checks if the iterator currently points to a valid item in the series. This method will return false after calling next() when on the last item or after calling prev() when on the first item.

Specified by:
isValid in interface GenericIterator
Returns:
true if iterator points to a valid item, false otherwise.

next

public GenericIterator next()
Moves the iterator to the next element in the subset.

Specified by:
next in interface GenericIterator
Returns:
this SubsetIterator, (suitable for chaining)

prev

public GenericIterator prev()
Moves the iterator to the previous element in the subset.

Specified by:
prev in interface GenericIterator
Returns:
this SubsetIterator, (suitable for chaining)

moveTo

public boolean moveTo(java.lang.Object elt)
Moves the iterator to the specified element. The equality check to determine if elt is in the series uses the Object.equals() method which may be overriden.

Specified by:
moveTo in interface GenericIterator
Returns:
true if pointer was moved to elt, false if the given element is not in the subset. (If false then the current pointer's position is undefined. It may be invalid).

getElt

public java.lang.Object getElt()
Retrieves the object currently pointed at by the iterator.

Specified by:
getElt in interface GenericIterator
Returns:
the current object in the subset.

deleteElt

public boolean deleteElt()
Remove the current element from the series. After calling delete, this iterator's current "pointer" will be at an undefined position, (it may even be invalid). However, calling next() will move it to the element originally after the deleted element and calling prev() will move it to the element originally before element.

Also Note: Any modifications of the series of elements, (ie. deletes or modifications), other than through this iterator may cause undefined effects on the state of this iterator.

Specified by:
deleteElt in interface GenericIterator
Returns:
true if the object was deleted false if the current pointer is not valid.


Copyright ? 2006 Brigham Young University, Configurable Computing Laboratory. All Rights Reserved.