net.sourceforge.cilib.cooperative.algorithmiterators
Class SequentialAlgorithmIterator<E extends Algorithm>

java.lang.Object
  extended by net.sourceforge.cilib.cooperative.algorithmiterators.SequentialAlgorithmIterator<E>
Type Parameters:
E - The Algorithm type.
All Implemented Interfaces:
Serializable, Iterator<E>, ListIterator<E>, AlgorithmIterator<E>, Cloneable
Direct Known Subclasses:
RandomAlgorithmIterator

public class SequentialAlgorithmIterator<E extends Algorithm>
extends Object
implements AlgorithmIterator<E>

Iterate through a list of Algorithms in a sequential order.

See Also:
Serialized Form

Field Summary
protected  List<E> algorithms
           
protected  int index
           
 
Constructor Summary
SequentialAlgorithmIterator()
          Construct a new SequentialAlgorithmIterator.
SequentialAlgorithmIterator(List<E> a)
          Construct a new SequentialAlgorithmIterator for the supplied list.
SequentialAlgorithmIterator(SequentialAlgorithmIterator rhs)
          Construct a new SequentialAlgorithmIterator from the supplied one.
 
Method Summary
 void add(E algorithm)
          Inserts the specified element into the list.
 E current()
          Returns the element at the current index.
 SequentialAlgorithmIterator<E> getClone()
          Clone this list iterator and return it.
 boolean hasNext()
          Returns true if this list iterator has more elements when traversing the list in the forward direction.
 boolean hasPrevious()
          Returns true if this list iterator has more elements when traversing the list in the reverse direction.
 E next()
          Gets the next element in the list.
 int nextIndex()
          Returns the index of the element that would be returned by a subsequent call to next.
 E previous()
          Gets the previous element in the list.
 int previousIndex()
          Returns the index of the element that would be returned by a subsequent call to previous.
 void remove()
          Removes from the list the last element that was returned by next or previous.
 void set(E algorithm)
          Replaces the last element returned by next or previous with the specified element.
 void setAlgorithms(List<E> a)
          Sets the list that will be iterated through.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

algorithms

protected List<E extends Algorithm> algorithms

index

protected int index
Constructor Detail

SequentialAlgorithmIterator

public SequentialAlgorithmIterator()
Construct a new SequentialAlgorithmIterator.


SequentialAlgorithmIterator

public SequentialAlgorithmIterator(List<E> a)
Construct a new SequentialAlgorithmIterator for the supplied list.

Parameters:
a - the list that will be iterated through sequentially.

SequentialAlgorithmIterator

public SequentialAlgorithmIterator(SequentialAlgorithmIterator rhs)
Construct a new SequentialAlgorithmIterator from the supplied one.

Parameters:
rhs - the SequentialAlgorithmIterator that should be copied.
Method Detail

getClone

public SequentialAlgorithmIterator<E> getClone()
Clone this list iterator and return it.

Specified by:
getClone in interface AlgorithmIterator<E extends Algorithm>
Specified by:
getClone in interface Cloneable
Returns:
a clone of this list iterator.
See Also:
Object.clone()

next

public E next()
Gets the next element in the list. This method may be called repeatedly to iterate through the list, or intermixed with calls to previous to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.)

Specified by:
next in interface Iterator<E extends Algorithm>
Specified by:
next in interface ListIterator<E extends Algorithm>
Returns:
the next element in the list.
Throws:
NoSuchElementException - when the current index is already at the end of the list.

previous

public E previous()
Gets the previous element in the list. This method may be called repeatedly to iterate through the list backwards, or intermixed with calls to next to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.)

Specified by:
previous in interface ListIterator<E extends Algorithm>
Returns:
the previous element in the list.
Throws:
NoSuchElementException - when the current index is already at the beginning of the list.

hasNext

public boolean hasNext()
Returns true if this list iterator has more elements when traversing the list in the forward direction. (In other words, returns true if next would return an element rather than throwing an exception.)

Specified by:
hasNext in interface Iterator<E extends Algorithm>
Specified by:
hasNext in interface ListIterator<E extends Algorithm>
Returns:
true if this list iterator has more elements when traversing the list in the forward direction; otherwise it returns false.

hasPrevious

public boolean hasPrevious()
Returns true if this list iterator has more elements when traversing the list in the reverse direction. (In other words, returns true if previous would return an element rather than throwing an exception.)

Specified by:
hasPrevious in interface ListIterator<E extends Algorithm>
Returns:
true if this list iterator has more elements when traversing the list in the reverse direction; otherwise it returns false.

nextIndex

public int nextIndex()
Returns the index of the element that would be returned by a subsequent call to next.

Specified by:
nextIndex in interface ListIterator<E extends Algorithm>
Returns:
The index of the element that would be returned by a subsequent call to next.

previousIndex

public int previousIndex()
Returns the index of the element that would be returned by a subsequent call to previous.

Specified by:
previousIndex in interface ListIterator<E extends Algorithm>
Returns:
The index of the element that would be returned by a subsequent call to previous.

add

public void add(E algorithm)
Inserts the specified element into the list. The element is inserted immediately before the next element that would be returned by next, if any, and after the next element that would be returned by previous, if any. (If the list contains no elements, the new element becomes the sole element on the list.) The new element is inserted before the implicit cursor: a subsequent call to next would be unaffected, and a subsequent call to previous would return the new element. (This call increases by one the value that would be returned by a call to nextIndex or previousIndex.)

Specified by:
add in interface ListIterator<E extends Algorithm>
Parameters:
algorithm - The Algorithm to add.

remove

public void remove()
Removes from the list the last element that was returned by next or previous. The index of the current element is also repositioned to prevent the iteration from skipping elements (due to the manner in which the .next() and .previous() methods work).

Specified by:
remove in interface Iterator<E extends Algorithm>
Specified by:
remove in interface ListIterator<E extends Algorithm>
Throws:
IndexOutOfBoundsException - when the current element index is past the beginning or end of the list.

set

public void set(E algorithm)
Replaces the last element returned by next or previous with the specified element.

Specified by:
set in interface ListIterator<E extends Algorithm>
Parameters:
algorithm - The element with which to replace the last element returned by next or previous.

setAlgorithms

public void setAlgorithms(List<E> a)
Sets the list that will be iterated through. Sets the current iteration position to -1, i.e. iteration hasn't started yet.

Specified by:
setAlgorithms in interface AlgorithmIterator<E extends Algorithm>
Parameters:
a - The list of Algorithms to set.

current

public E current()
Returns the element at the current index.

Specified by:
current in interface AlgorithmIterator<E extends Algorithm>
Returns:
The element at the current index.


Copyright © 2009 CIRG. All Rights Reserved.