summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/parserutils/splitter/TokenSplitters.java
blob: 4aed8f622722d8a2e9d3d7bdc95e776b2c7649fd (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
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 identity token splitter, which doesn't actually do any splitting.
	 * 
	 * @return A new identity splitter.
	 */
	public static TokenSplitter identitySplitter() {
		return new IdentityTokenSplitter();
	}
	
	/**
	 * 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);
	}
}