From 0511c58b13b0604baefefc3333997ddae946100c Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sun, 24 Sep 2017 00:12:25 -0700 Subject: [PATCH] Remove the Pattern's dependency on java.util.function --- .../org/nwapw/abacus/lexing/pattern/Pattern.java | 7 +++---- .../abacus/lexing/pattern/Transformation.java | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 core/src/main/java/org/nwapw/abacus/lexing/pattern/Transformation.java diff --git a/core/src/main/java/org/nwapw/abacus/lexing/pattern/Pattern.java b/core/src/main/java/org/nwapw/abacus/lexing/pattern/Pattern.java index b578d01..2090203 100644 --- a/core/src/main/java/org/nwapw/abacus/lexing/pattern/Pattern.java +++ b/core/src/main/java/org/nwapw/abacus/lexing/pattern/Pattern.java @@ -6,7 +6,6 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Stack; -import java.util.function.Function; /** * A pattern that can be compiled from a string and used in lexing. @@ -36,8 +35,8 @@ public class Pattern { * A map of regex operator to functions that modify a PatternChain * with the appropriate operation. */ - private Map, PatternChain>> operations = - new HashMap, PatternChain>>() {{ + private Map> operations = + new HashMap>() {{ put('+', Pattern.this::transformPlus); put('*', Pattern.this::transformStar); put('?', Pattern.this::transformQuestion); @@ -207,7 +206,7 @@ public class Pattern { if (operations.containsKey(currentChar)) { if (currentChain == null) return null; - currentChain = operations.get(currentChar).apply(currentChain); + currentChain = operations.get(currentChar).transform(currentChain); fullChain.append(currentChain); currentChain = null; index++; diff --git a/core/src/main/java/org/nwapw/abacus/lexing/pattern/Transformation.java b/core/src/main/java/org/nwapw/abacus/lexing/pattern/Transformation.java new file mode 100644 index 0000000..5bab0e8 --- /dev/null +++ b/core/src/main/java/org/nwapw/abacus/lexing/pattern/Transformation.java @@ -0,0 +1,16 @@ +package org.nwapw.abacus.lexing.pattern; + +/** + * An interface that transforms a pattern chain into a different pattern chain. + * @param the type used to identify the nodes in the pattern chain. + */ +public interface Transformation { + + /** + * Performs the actual transformation. + * @param from the original chain. + * @return the resulting chain. + */ + PatternChain transform(PatternChain from); + +}