added unit test for IterableQueue and improve javadoc

This commit is contained in:
Sebastian Sdorra
2013-03-01 18:27:04 +01:00
parent 79722fee6d
commit 15906a7e62
3 changed files with 286 additions and 15 deletions

View File

@@ -47,11 +47,12 @@ import java.util.Iterator;
import java.util.List;
/**
* A iterable queue. The queue can have multiple consumer {@link Iterator},
* which can iterate over all items of the queue until the end of the queue is
* reached. The end of the queue if reached, if a producer call the method
* {@link #endReached()} and the iterator has consumed all items of the backend
* list.
* A iterable queue. The queue can have multiple parallel consumer
* {@link Iterator}s, which can iterate over all items of the queue until the
* end of the queue is reached. The end of the queue if reached, if a producer
* call the method {@link #endReached()} and the iterator has consumed all items
* of the backend list. <strong>Warning: </strong> The queue iterator blocks
* forever if the producer never call {@link #endReached()}.
*
* @author Sebastian Sdorra
*

View File

@@ -33,15 +33,18 @@
package sonia.scm.collect;
//~--- JDK imports ------------------------------------------------------------
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.collect.UnmodifiableIterator;
//~--- JDK imports ------------------------------------------------------------
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
/**
* Iterator for the {@link IterableQueue}. The {@link QueueIterator} should
* only be created from the {@link IterableQueue} by calling the
* Iterator for the {@link IterableQueue}. The {@link QueueIterator} should
* only be created from the {@link IterableQueue} by calling the
* {@link IterableQueue#iterator()}.
*
* @author Sebastian Sdorra
@@ -67,28 +70,30 @@ public final class QueueIterator<T> extends UnmodifiableIterator<T>
/**
* Returns the next item in the queue. This method will block until the next
* item is pushed to the queue, if the queue is empty and the end is not
* item is pushed to the queue, if the queue is empty and the end is not
* reached.
*
* @throws NoSuchElementException if the iteration has no more elements
*
*
* @return the next item in the queue
*/
@Override
public T next()
{
if ( ! hasNext() ){
if (!hasNext())
{
throw new NoSuchElementException("no more items in the queue");
}
return queue.get(index++);
}
//~--- get methods ----------------------------------------------------------
/**
* Returns {@code true} {@code true} if the queue has more items.
* This method will block until the next item is pushed to the queue, if the
* queue is empty and the end is not
* Returns {@code true} {@code true} if the queue has more items.
* This method will block until the next item is pushed to the queue, if the
* queue is empty and the end is not
* reached.
*
*
@@ -122,7 +127,6 @@ public final class QueueIterator<T> extends UnmodifiableIterator<T>
return result;
}
//~--- fields ---------------------------------------------------------------
/** queue for the iterator */