diff options
| author | Ben Culkin <scorpress@gmail.com> | 2020-11-21 16:51:04 -0500 |
|---|---|---|
| committer | Ben Culkin <scorpress@gmail.com> | 2020-11-21 16:51:04 -0500 |
| commit | 4c0f972c4616eb549a098c3ef40d527eb542d7a6 (patch) | |
| tree | f791838e7477bb15fe2181bf673231e2e4ccda0a /base/src/main/java/bjc/utils/patterns/SimplePatttern.java | |
| parent | aaf35ffcea677d315aa24180f2742a45e2146ece (diff) | |
Add basic pattern matching
Adds a basic pattern matching implementation. Not perfect, but pretty
good, considering what we have to work with
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 |
