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