diff options
Diffstat (limited to 'base/src/main/java/bjc/utils/patterns/SimplePatttern.java')
| -rw-r--r-- | base/src/main/java/bjc/utils/patterns/SimplePatttern.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/base/src/main/java/bjc/utils/patterns/SimplePatttern.java b/base/src/main/java/bjc/utils/patterns/SimplePatttern.java new file mode 100644 index 0000000..1601894 --- /dev/null +++ b/base/src/main/java/bjc/utils/patterns/SimplePatttern.java @@ -0,0 +1,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); + } +}
\ No newline at end of file |
