Define the Pattern interface and its core methods

This commit is contained in:
Riccardo Azzolini 2018-10-05 20:01:15 +02:00
parent 3808613a58
commit d88f6a05f9

View File

@ -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 <code>Optional</code> if
* the pattern doesn't match.
*/
Optional<Map<String, Function>> 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<String, Function> subFunctions);
}