This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch feature/CAMEL-25532-lenient-input
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to
refs/heads/feature/CAMEL-25532-lenient-input by this push:
new e41d60e5e591 CAMEL-25532: camel-jbang - the line counts of the closest
match come from one pass, and the quoted-value pattern is a field (review)
e41d60e5e591 is described below
commit e41d60e5e591c4fc21013b113e39bc286c9d423a
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Oct 17 10:45:59 2026 +0200
CAMEL-25532: camel-jbang - the line counts of the closest match come from
one pass, and the quoted-value pattern is a field (review)
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
---
.../apache/camel/dsl/jbang/core/commands/ai/AuthoringTools.java | 8 ++++++--
.../apache/camel/dsl/jbang/core/commands/ai/LenientRepairs.java | 4 +++-
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/AuthoringTools.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/AuthoringTools.java
index 158dcd7d81e4..f5876f03ae4e 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/AuthoringTools.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/AuthoringTools.java
@@ -1012,8 +1012,12 @@ public final class AuthoringTools {
static int[] fuzzyWindow(String content, String find) {
String[] lines = content.split("\n", -1);
List<String> norm = new ArrayList<>(lines.length);
+ // how often each line occurs, so a line of find that is unique in the
content is known without a scan per line
+ Map<String, Integer> occurrences = new HashMap<>();
for (String l : lines) {
- norm.add(fuzzyLine(l));
+ String n = fuzzyLine(l);
+ norm.add(n);
+ occurrences.merge(n, 1, Integer::sum);
}
List<String> want =
find.lines().map(AuthoringTools::fuzzyLine).filter(l -> !l.isEmpty()).toList();
if (want.isEmpty()) {
@@ -1021,7 +1025,7 @@ public final class AuthoringTools {
}
Set<String> distinct = new LinkedHashSet<>();
for (String w : want) {
- if (w.length() > 6 && !BARE_KEY.matcher(w).matches() &&
norm.stream().filter(w::equals).count() == 1) {
+ if (w.length() > 6 && !BARE_KEY.matcher(w).matches() &&
occurrences.getOrDefault(w, 0) == 1) {
distinct.add(w);
}
}
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/LenientRepairs.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/LenientRepairs.java
index 7f38270e80cb..6d640fb0869a 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/LenientRepairs.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/LenientRepairs.java
@@ -61,6 +61,8 @@ final class LenientRepairs {
+ "
\\{(\\w+): \\{expression: \"(.*)\"\\}\\}");
private static final Pattern ENUM = Pattern.compile(
"^Line (\\d+): (\\w+): does not have a value in the enumeration
\\[([^\\]]*)\\]");
+ /** A value in double quotes, as the values of an enumeration are listed
in the validator's message. */
+ private static final Pattern QUOTED = Pattern.compile("\"([^\"]+)\"");
private static final Pattern LIST_FOR_MAP = Pattern.compile(
"^Line (\\d+): (otherwise|onFallback|doFinally): array found,
object expected");
private static final Pattern MAP_FOR_LIST = Pattern.compile(
@@ -171,7 +173,7 @@ final class LenientRepairs {
int line = Integer.parseInt(m.group(1));
String key = m.group(2);
List<String> choices = new ArrayList<>();
- Matcher q = Pattern.compile("\"([^\"]+)\"").matcher(m.group(3));
+ Matcher q = QUOTED.matcher(m.group(3));
while (q.find()) {
choices.add(q.group(1));
}