steffenvan commented on code in PR #1443:
URL: https://github.com/apache/jackrabbit-oak/pull/1443#discussion_r1599549435


##########
oak-lucene/src/main/java/org/apache/lucene/util/automaton/RegExp.java:
##########
@@ -872,23 +874,39 @@ private boolean check(int flag) {
   }
   
   final RegExp parseUnionExp() throws IllegalArgumentException {
-    RegExp e = parseInterExp();
-    if (match('|')) e = makeUnion(e, parseUnionExp());
-    return e;
+    return iterativeParseExp(this::parseInterExp, () -> match('|'), 
RegExp::makeUnion);
   }
   
   final RegExp parseInterExp() throws IllegalArgumentException {
-    RegExp e = parseConcatExp();
-    if (check(INTERSECTION) && match('&')) e = makeIntersection(e,
-        parseInterExp());
-    return e;
+    return iterativeParseExp(
+      this::parseConcatExp, () -> check(INTERSECTION) && match('&'), 
RegExp::makeIntersection);
   }
   
   final RegExp parseConcatExp() throws IllegalArgumentException {
-    RegExp e = parseRepeatExp();
-    if (more() && !peek(")|") && (!check(INTERSECTION) || !peek("&"))) e = 
makeConcatenation(
-        e, parseConcatExp());
-    return e;
+    return iterativeParseExp(
+      this::parseRepeatExp,
+        () -> (more() && !peek(")|") && (!check(INTERSECTION) || !peek("&"))),
+        RegExp::makeConcatenation);
+    }
+  
+  /**
+   * Custom Functional Interface for a Supplying methods with signature of 
RegExp(RegExp
+   * exp1, RegExp exp2)
+   */
+  @FunctionalInterface
+  private interface MakeRegexGroup {
+    RegExp get(RegExp exp1, RegExp exp2);
+  }
+
+  final RegExp iterativeParseExp(
+      Supplier<RegExp> gather, BooleanSupplier stop, MakeRegexGroup 
associativeReduce)
+      throws IllegalArgumentException {
+    RegExp result = gather.get();
+    while (stop.getAsBoolean() == true) {

Review Comment:
   Hmm okay fair makes sense.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to