blob: 72da16de26d04fb9fa7113ca695e52ba91cd4cd0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
package bjc.utils.ioutils.blocks;
import java.io.IOException;
import java.util.function.UnaryOperator;
/**
* A block reader that applies a transform to each block.
*
* @author EVE
*
*/
public class MappedBlockReader implements BlockReader {
private BlockReader reader;
private Block current;
private UnaryOperator<Block> transform;
private int blockNo;
/**
* Create a new mapped block reader.
*
* @param source
* The source for blocks
* @param trans
* The transform to apply.
*/
public MappedBlockReader(BlockReader source, UnaryOperator<Block> trans) {
reader = source;
transform = trans;
blockNo = 0;
}
@Override
public boolean hasNextBlock() {
return reader.hasNextBlock();
}
@Override
public Block getBlock() {
return current;
}
@Override
public boolean nextBlock() {
if(hasNextBlock()) {
current = transform.apply(reader.next());
blockNo += 1;
return true;
}
return false;
}
@Override
public int getBlockCount() {
return blockNo;
}
@Override
public void close() throws IOException {
reader.close();
}
}
|