From 9ec11128f53123fea3c7b465474600d067a50633 Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Thu, 28 Sep 2023 20:38:52 +0200 Subject: [PATCH] More "old tyle" Java --- .../logic/integrity/AmpersandChecker.java | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/jabref/logic/integrity/AmpersandChecker.java b/src/main/java/org/jabref/logic/integrity/AmpersandChecker.java index 0645c685c1a..9c08ad52e82 100644 --- a/src/main/java/org/jabref/logic/integrity/AmpersandChecker.java +++ b/src/main/java/org/jabref/logic/integrity/AmpersandChecker.java @@ -29,23 +29,21 @@ public List check(BibEntry entry) { return entry.getFieldMap().entrySet().stream() .filter(field -> !field.getKey().getProperties().contains(FieldProperty.VERBATIM)) // We use "flatMap" instead of filtering later, because we assume there won't be that much error messages - and construction of Stream.empty() is faster than construction of a new Tuple2 (including lifting long to Long) - .flatMap(getUnescapedAmpersandsWithCount()) - .map(tuple -> new IntegrityMessage(Localization.lang("Found %0 unescaped '&'", tuple.getValue()), entry, tuple.getKey())) + .flatMap(AmpersandChecker::getUnescapedAmpersandsWithCount) + .map(pair -> new IntegrityMessage(Localization.lang("Found %0 unescaped '&'", pair.getValue()), entry, pair.getKey())) .toList(); } - private static Function, Stream>> getUnescapedAmpersandsWithCount() { - return field -> { - // counts the number of even \ occurrences preceding an & - long unescapedAmpersands = BACKSLASH_PRECEDED_AMPERSAND.matcher(field.getValue()) - .results() - .map(MatchResult::group) - .filter(m -> CharMatcher.is('\\').countIn(m) % 2 == 0) - .count(); - if (unescapedAmpersands == 0) { - return Stream.empty(); - } - return Stream.of(new Pair<>(field.getKey(), unescapedAmpersands)); - }; + private static Stream> getUnescapedAmpersandsWithCount(Map.Entry entry) { + // counts the number of even \ occurrences preceding an & + long unescapedAmpersands = BACKSLASH_PRECEDED_AMPERSAND.matcher(entry.getValue()) + .results() + .map(MatchResult::group) + .filter(m -> CharMatcher.is('\\').countIn(m) % 2 == 0) + .count(); + if (unescapedAmpersands == 0) { + return Stream.empty(); + } + return Stream.of(new Pair<>(entry.getKey(), unescapedAmpersands)); } }