1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2009 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.io.dwca.in;
|
11
|
|
12
|
import java.util.Set;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
|
16
|
import eu.etaxonomy.cdm.io.common.events.IIoObserver;
|
17
|
import eu.etaxonomy.cdm.io.dwca.TermUri;
|
18
|
import eu.etaxonomy.cdm.io.stream.IItemStream;
|
19
|
import eu.etaxonomy.cdm.io.stream.StreamItem;
|
20
|
|
21
|
/**
|
22
|
* FilteredReader filters a stream. Only a substream of the input items
|
23
|
* is in the output stream.
|
24
|
* @author a.mueller
|
25
|
* @date 23.11.2011
|
26
|
*
|
27
|
*/
|
28
|
public class FilteredStream implements IItemStream {
|
29
|
@SuppressWarnings("unused")
|
30
|
private static Logger logger = Logger.getLogger(FilteredStream.class);
|
31
|
|
32
|
private final IItemStream reader;
|
33
|
private final ItemFilter<StreamItem> filter;
|
34
|
private StreamItem next;
|
35
|
|
36
|
/**
|
37
|
* @param list
|
38
|
*/
|
39
|
public FilteredStream(IItemStream reader, ItemFilter<StreamItem> filter) {
|
40
|
this.reader = reader;
|
41
|
this.filter = filter;
|
42
|
}
|
43
|
|
44
|
@Override
|
45
|
public StreamItem read() {
|
46
|
StreamItem result;
|
47
|
if (hasNext()){
|
48
|
result = next;
|
49
|
next = null;
|
50
|
}else{
|
51
|
result = null;
|
52
|
}
|
53
|
return result;
|
54
|
}
|
55
|
|
56
|
@Override
|
57
|
public boolean hasNext(){
|
58
|
if (next != null){
|
59
|
return true;
|
60
|
}
|
61
|
while (reader.hasNext()){
|
62
|
next = reader.read();
|
63
|
if (filter == null || ! filter.toBeRemovedFromStream(next)){
|
64
|
return true;
|
65
|
}
|
66
|
}
|
67
|
return false;
|
68
|
}
|
69
|
|
70
|
@Override
|
71
|
public TermUri getTerm() {
|
72
|
return reader.getTerm();
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
public String getItemLocation() {
|
77
|
return reader.getItemLocation();
|
78
|
}
|
79
|
|
80
|
@Override
|
81
|
public String getStreamLocation() {
|
82
|
return reader.getStreamLocation();
|
83
|
}
|
84
|
|
85
|
@Override
|
86
|
public void addObservers(Set<IIoObserver> observers) {
|
87
|
reader.addObservers(observers);
|
88
|
}
|
89
|
|
90
|
}
|