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


##########
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:
   We could, but I wanted to minimize the amount of changes compared to the 
"official" Lucene patch. 
(https://github.com/apache/lucene/pull/12462/files#diff-93255512c837705492a154d5794b61f7132ae4264a292d224d5944de35f45847R1100)



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to