blob: db53287bf7b6cb9efc6a6cd629252241f19d5fc9 (
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 Pair<Boolean, Void> matches(Object input) {
return new SimplePair<>(doesMatch(input), null);
}
}
|