Holger's Java API

## com.antelmann.util
Class IteratorQueue<T>

    java.lang.Object
      com.antelmann.util.IteratorQueue<T>

All Implemented Interfaces:
  ValueRetriever<T>, Wrapped<Queue<T>>, Closeable, Iterable<T>, Enumeration<T>, Iterator<T>

    public class IteratorQueue<T>

extends Object
implements Iterator<T>, Closeable, ValueRetriever<T>, Wrapped<Queue<T>>, Iterable<T>, Enumeration<T>

a special iterator that supplies elements from an embedded blocking queue and blocks on calls to `hasNext()`. This class is particularly handy if you want to supply data through an iterator from a different thread than from where it is read. The `next()` method only returns false after the `close()` method is called and the queue is empty.

Since:
  20.05.2009, 13:50:08
Author:
  Holger Antelmann

Constructor Summary
`IteratorQueue(Collection<? extends T> collection)`
`IteratorQueue(T... elements)`

Method Summary
`void` `add(T element)`
`int` `available()` a non-blocking call to see how many elements are currently available in this queue
`void` `clearException()`
`void` `close()`
`int` `getCounter()`
`Throwable` `getException()`
`T` `getRelevantValue()` returns the relevant value for this instance at the time of calling
`boolean` `hasMoreElements()`
`boolean` `hasNext()`
`boolean` `isClosed()`
`Iterator<T>` `iterator()`
`T` `next()`
`T` `nextElement()`
`void` `remove()`
`void` `setException(String msg)` throws an exception to the caller of `hasNext()`
`void` `setException(Throwable exception)` throws an exception to the caller of `hasNext()`
`Queue<T>` `unwrap()` returns the embedded instance that this wrapper encloses

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### IteratorQueue

    public IteratorQueue(T... elements)

### IteratorQueue

    public IteratorQueue(Collection<? extends T> collection)

Method Detail

### unwrap

    public Queue<T> unwrap()

  Description copied from interface: `Wrapped`
  returns the embedded instance that this wrapper encloses

  Specified by:
    `unwrap` in interface `Wrapped<Queue<T>>`

### add

    public void add(T element)
             throws IllegalStateException

  Throws:
    `IllegalStateException`

### setException

    public void setException(String msg)

  throws an exception to the caller of `hasNext()`

### setException

    public void setException(Throwable exception)

  throws an exception to the caller of `hasNext()`

### getException

    public Throwable getException()

### clearException

    public void clearException()

### available

    public int available()

  a non-blocking call to see how many elements are currently available in this queue

### getCounter

    public int getCounter()

### getRelevantValue

    public T getRelevantValue()
                       throws IOException

  Description copied from interface: `ValueRetriever`
  returns the relevant value for this instance at the time of calling

  Specified by:
    `getRelevantValue` in interface `ValueRetriever<T>`
  Throws:
    `IOException` - if any resource to fulfill the request is not accessible

### hasNext

    public boolean hasNext()
                    throws IterationException

  Specified by:
    `hasNext` in interface `Iterator<T>`
  Throws:
    `IterationException`

### next

    public T next()

  Specified by:
    `next` in interface `Iterator<T>`

### remove

    public void remove()

  Specified by:
    `remove` in interface `Iterator<T>`

### iterator

    public Iterator<T> iterator()

  Specified by:
    `iterator` in interface `Iterable<T>`

### hasMoreElements

    public boolean hasMoreElements()

  Specified by:
    `hasMoreElements` in interface `Enumeration<T>`

### nextElement

    public T nextElement()

  Specified by:
    `nextElement` in interface `Enumeration<T>`

### isClosed

    public boolean isClosed()

### close

    public void close()

  Specified by:
    `close` in interface `Closeable`

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads