From d88f6a05f9ede852009ca9637e029d96a1509ff5 Mon Sep 17 00:00:00 2001 From: Riccardo Azzolini Date: Fri, 5 Oct 2018 20:01:15 +0200 Subject: [PATCH] Define the Pattern interface and its core methods --- .../warppi/math/rules/dsl/Pattern.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 core/src/main/java/it/cavallium/warppi/math/rules/dsl/Pattern.java diff --git a/core/src/main/java/it/cavallium/warppi/math/rules/dsl/Pattern.java b/core/src/main/java/it/cavallium/warppi/math/rules/dsl/Pattern.java new file mode 100644 index 00000000..3e26439b --- /dev/null +++ b/core/src/main/java/it/cavallium/warppi/math/rules/dsl/Pattern.java @@ -0,0 +1,28 @@ +package it.cavallium.warppi.math.rules.dsl; + +import it.cavallium.warppi.math.Function; + +import java.util.Map; +import java.util.Optional; + +/** + * Recognizes and generates functions of some specific shape. + */ +public interface Pattern { + /** + * Tries to match this pattern against a function and capture sub-functions. + * + * @param function The function to test the pattern against. + * @return The captured sub-functions, or an empty Optional if + * the pattern doesn't match. + */ + Optional> match(Function function); + + /** + * Creates a new function by filling in sub-functions within this pattern. + * + * @param subFunctions A map of named sub-functions to be inserted into this pattern. + * @return The resulting function. + */ + Function replace(Map subFunctions); +}