From 68ec56c3bed5b9ce5e6594c9a1d0bff04c25959b Mon Sep 17 00:00:00 2001 From: Oliver Kopp Date: Sun, 3 Sep 2023 15:50:30 +0200 Subject: [PATCH] Apply exit early pattern --- build.gradle | 4 +-- .../jabref/gui/journals/AbbreviateAction.java | 26 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index 4dc01ae8684..c5a92c9f959 100644 --- a/build.gradle +++ b/build.gradle @@ -292,10 +292,10 @@ tasks.register("generateBstGrammarSource", JavaExec) { } tasks.register("generateSearchGrammarSource", JavaExec) { - main = "org.antlr.v4.Tool" - classpath = configurations.antlr4 group = 'JabRef' description = "Generates java files for Search.g antlr4." + classpath = configurations.antlr4 + main = "org.antlr.v4.Tool" inputs.dir("src/main/antlr4/org/jabref/search/") outputs.dir("src-gen/main/java/org/jabref/search/") diff --git a/src/main/java/org/jabref/gui/journals/AbbreviateAction.java b/src/main/java/org/jabref/gui/journals/AbbreviateAction.java index bf531de51dd..93be6a06c39 100644 --- a/src/main/java/org/jabref/gui/journals/AbbreviateAction.java +++ b/src/main/java/org/jabref/gui/journals/AbbreviateAction.java @@ -110,13 +110,14 @@ private String abbreviate(BibDatabaseContext databaseContext, List ent } }).count(); - if (count > 0) { - ce.end(); - frame.getUndoManager().addEdit(ce); - frame.getCurrentLibraryTab().markBaseChanged(); - return Localization.lang("Abbreviated %0 journal names.", String.valueOf(count)); + if (count == 0) { + return Localization.lang("No journal names could be abbreviated."); } - return Localization.lang("No journal names could be abbreviated."); + + ce.end(); + frame.getUndoManager().addEdit(ce); + frame.getCurrentLibraryTab().markBaseChanged(); + return Localization.lang("Abbreviated %0 journal names.", String.valueOf(count)); } private String unabbreviate(BibDatabaseContext databaseContext, List entries) { @@ -126,12 +127,13 @@ private String unabbreviate(BibDatabaseContext databaseContext, List e int count = entries.stream().mapToInt(entry -> (int) FieldFactory.getJournalNameFields().stream().filter(journalField -> undoableAbbreviator.unabbreviate(databaseContext.getDatabase(), entry, journalField, ce)).count()).sum(); - if (count > 0) { - ce.end(); - frame.getUndoManager().addEdit(ce); - frame.getCurrentLibraryTab().markBaseChanged(); - return Localization.lang("Unabbreviated %0 journal names.", String.valueOf(count)); + if (count == 0) { + return Localization.lang("No journal names could be unabbreviated."); } - return Localization.lang("No journal names could be unabbreviated."); + + ce.end(); + frame.getUndoManager().addEdit(ce); + frame.getCurrentLibraryTab().markBaseChanged(); + return Localization.lang("Unabbreviated %0 journal names.", String.valueOf(count)); } }