ORG.hd.d.par
Class ParTasks.RepeatingIteratorCollection

java.lang.Object
  |
  +--ORG.hd.d.par.ParTasks.RepeatingIteratorCollection

public static class ParTasks.RepeatingIteratorCollection
extends java.lang.Object
implements java.util.Collection

Wraps a Collection to return a repeating iterator. A call to iterator() on the wrapper will result in an iterator which resets whenever it reaches the end of the collection, thus repeating indefinitely. Each run through will provide the ordering that the underlying iterator produces, with each iterator being used to completion.

Use this to run some repeating parallel task, to help overlap the end of one run with the start of the next. This in principle could allow two threads to run a functor on two copies of the underlying task at the same time, but limiting parallelism to the size of the (underlying) Collection can avoid this.

Note that if immediately after starting such a sequence the underlying iterator's hasNext() returns false, so will the wrapper's iterator, so empty collections don't cause an infinite loop.

It is possible to have the repeating stop when a condition is met by deriving from this class and override the willRepeat() method. If this is false when an iterator would reset, the iterator will not reset. Note that this has no effect until the underlying iterator completes.


Constructor Summary
ParTasks.RepeatingIteratorCollection(java.util.Collection c)
          Wrap an existing Collection to make its Iterator repeat.
 
Method Summary
 boolean add(java.lang.Object o)
           
 boolean addAll(java.util.Collection c)
           
 void clear()
           
 boolean contains(java.lang.Object o)
           
 boolean containsAll(java.util.Collection c)
           
 boolean equals(java.lang.Object o)
           
 int hashCode()
           
 boolean isEmpty()
           
 java.util.Iterator iterator()
          Get a (repeating) iterator.
 boolean remove(java.lang.Object o)
           
 boolean removeAll(java.util.Collection c)
           
 boolean retainAll(java.util.Collection c)
           
 int size()
           
 java.lang.Object[] toArray()
           
 java.lang.Object[] toArray(java.lang.Object[] a)
           
 boolean willRepeat()
          If true (the default), the iterators produced will repeat.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParTasks.RepeatingIteratorCollection

public ParTasks.RepeatingIteratorCollection(java.util.Collection c)
Wrap an existing Collection to make its Iterator repeat.
Method Detail

willRepeat

public boolean willRepeat()
If true (the default), the iterators produced will repeat.

iterator

public final java.util.Iterator iterator()
Get a (repeating) iterator. This iterator is not thread-safe; synchronize on the wrapped collection to make it so.
Specified by:
iterator in interface java.util.Collection

add

public boolean add(java.lang.Object o)
Specified by:
add in interface java.util.Collection

addAll

public boolean addAll(java.util.Collection c)
Specified by:
addAll in interface java.util.Collection

clear

public void clear()
Specified by:
clear in interface java.util.Collection

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection

containsAll

public boolean containsAll(java.util.Collection c)
Specified by:
containsAll in interface java.util.Collection

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Collection
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Collection
Overrides:
hashCode in class java.lang.Object

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection

remove

public boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection

removeAll

public boolean removeAll(java.util.Collection c)
Specified by:
removeAll in interface java.util.Collection

retainAll

public boolean retainAll(java.util.Collection c)
Specified by:
retainAll in interface java.util.Collection

size

public int size()
Specified by:
size in interface java.util.Collection

toArray

public java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection

toArray

public java.lang.Object[] toArray(java.lang.Object[] a)
Specified by:
toArray in interface java.util.Collection

(c) Damon Hart-Davis 1999--2000