dnet40/modules/dnet-openaireplus-workflows/trunk/src/main/java/eu/dnetlib/msro/openaireplus/workflows/nodes/datacite/IteratorOnQueue.java @ 46100
1 |
package eu.dnetlib.msro.openaireplus.workflows.nodes.datacite; |
---|---|
2 |
|
3 |
import java.util.Iterator; |
4 |
import java.util.concurrent.BlockingQueue; |
5 |
|
6 |
import org.apache.commons.logging.Log; |
7 |
import org.apache.commons.logging.LogFactory; |
8 |
|
9 |
/**
|
10 |
* The Class IteratorOnQueue.
|
11 |
*
|
12 |
* @param <T>
|
13 |
* the generic type
|
14 |
*/
|
15 |
public class IteratorOnQueue<T> implements Iterator<T> { |
16 |
|
17 |
/** The Constant log. */
|
18 |
private static final Log log = LogFactory.getLog(IteratorOnQueue.class); |
19 |
|
20 |
/** The input queue. */
|
21 |
private final BlockingQueue<T> inputQueue; |
22 |
|
23 |
/** The current item. */
|
24 |
private T currentItem; |
25 |
|
26 |
/** The end queue. */
|
27 |
private T endQueue; |
28 |
|
29 |
/**
|
30 |
* Instantiates a new iterator on queue.
|
31 |
*
|
32 |
* @param inputQueue
|
33 |
* the input queue
|
34 |
* @param endQueue
|
35 |
* the end queue
|
36 |
*/
|
37 |
public IteratorOnQueue(final BlockingQueue<T> inputQueue, final T endQueue) { |
38 |
this.inputQueue = inputQueue; |
39 |
this.endQueue = endQueue; |
40 |
|
41 |
try { |
42 |
currentItem = this.inputQueue.take(); |
43 |
} catch (InterruptedException e) { |
44 |
log.error(e); |
45 |
}
|
46 |
}
|
47 |
|
48 |
/**
|
49 |
* Checks for next.
|
50 |
*
|
51 |
* @return true, if successful
|
52 |
*/
|
53 |
@Override
|
54 |
public boolean hasNext() { |
55 |
|
56 |
return currentItem != this.endQueue; |
57 |
}
|
58 |
|
59 |
/**
|
60 |
* Next.
|
61 |
*
|
62 |
* @return the t
|
63 |
*/
|
64 |
@Override
|
65 |
public T next() { |
66 |
|
67 |
T previous = currentItem; |
68 |
try { |
69 |
currentItem = this.inputQueue.take(); |
70 |
} catch (Exception e) { |
71 |
log.error(e); |
72 |
}
|
73 |
return previous; |
74 |
}
|
75 |
|
76 |
/**
|
77 |
* Removes the.
|
78 |
*/
|
79 |
@Override
|
80 |
public void remove() { |
81 |
// TODO Auto-generated method stub
|
82 |
|
83 |
}
|
84 |
|
85 |
}
|