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

import java.util.function.UnaryOperator;

import bjc.funcdata.IList;

/**
 * A token splitter that performs a transform on the tokens from another
 * splitter.
 *
 * @author bjculkin
 *
 */
public class TransformTokenSplitter implements TokenSplitter {
	private TokenSplitter source;

	private UnaryOperator<String> transform;

	/**
	 * Create a new transforming splitter.
	 *
	 * @param source
	 *                  The splitter to use as a source.
	 *
	 * @param transform
	 *                  The transform to apply to tokens.
	 */
	public TransformTokenSplitter(TokenSplitter source, UnaryOperator<String> transform) {
		this.source = source;
		this.transform = transform;
	}

	@Override
	public IList<String> split(String input) {
		return source.split(input).map(transform);
	}

}