blob: 47363105f687074ba76c37cddc886cdf5cf705ba (
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
|
package bjc.utils.parserutils.splitter;
import bjc.utils.funcdata.FunctionalList;
import bjc.utils.funcdata.IList;
/**
* A token splitter that chains several other splitters together.
*
* @author EVE
*
*/
public class ChainTokenSplitter implements TokenSplitter {
private final IList<TokenSplitter> spliters;
/**
* Create a new chain token splitter.
*/
public ChainTokenSplitter() {
spliters = new FunctionalList<>();
}
/**
* Append a series of splitters to the chain.
*
* @param splitters
* The splitters to append to the chain.
*/
public void appendSplitters(final TokenSplitter... splitters) {
spliters.addAll(splitters);
}
/**
* Prepend a series of splitters to the chain.
*
* @param splitters
* The splitters to append to the chain.
*/
public void prependSplitters(final TokenSplitter... splitters) {
spliters.prependAll(splitters);
}
@Override
public IList<String> split(final String input) {
final IList<String> initList = new FunctionalList<>(input);
return spliters.reduceAux(initList, (splitter, strangs) -> {
return strangs.flatMap(splitter::split);
});
}
}
|