summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/parserutils/splitter/TokenSplitters.java
blob: 15d6b8bf60099d8218b44fa5551dafa7adc8eed0 (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
package bjc.utils.parserutils.splitter;

import java.util.function.UnaryOperator;

/**
 * Factory methods for producing token splitters.
 *
 * @author student
 *
 */
public class TokenSplitters {
	/**
	 * Create a new chained token splitter.
	 *
	 * @param splitters
	 *                  The series of splitters to chain together.
	 * @return A chained-together series of splitters.
	 */
	public static TokenSplitter chainSplitter(final TokenSplitter... splitters) {
		ChainTokenSplitter cts = new ChainTokenSplitter();

		cts.appendSplitters(splitters);

		return cts;
	}

	/**
	 * Create a new transforming token splitter.
	 *
	 * @param splitter
	 *                  The splitter to gain tokens from
	 *
	 * @param transform
	 *                  The transform to apply to the strings.
	 *
	 * @return A splitter that applies the chosen transform to the tokens.
	 */
	public static TokenSplitter transformSplitter(final TokenSplitter splitter,
			UnaryOperator<String> transform) {
		return new TransformTokenSplitter(splitter, transform);
	}
}