summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/patterns/SimplePatttern.java
blob: 1601894da2e75f8740f86e2b55b3279375cb1869 (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
package bjc.utils.patterns;

import bjc.data.*;

/**
 * A simpler form of a pattern.
 * 
 * @author Ben Culkin
 *
 * @param <ReturnType> The type returned by matching the pattern.
 */
public interface SimplePatttern<ReturnType> extends Pattern<ReturnType, Void> {
	/**
	 * Test if this pattern does match a given object.
	 * 
	 * @param input The object to test against.
	 * 
	 * @return Whether the object matches this pattern.
	 */
	boolean doesMatch(Object input);

	/**
	 * Applies this pattern to the input object.
	 * 
	 * @param input The object that passed the condition.
	 * 
	 * @return The result of applying this action to the input.
	 */
	ReturnType doApply(Object input);
	
	@Override
	default ReturnType apply(Object input, Void state) {
		return doApply(input);
	}
	
	@Override
	default IPair<Boolean, Void> matches(Object input) {
		return new Pair<>(doesMatch(input), null);
	}
}