From d0b9769c842a2547d84ceb6db199a1f2c9bb1a98 Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Tue, 23 Oct 2018 15:13:21 +0200 Subject: [PATCH 1/2] Always Use Braces --- .../gui/edit/ReplaceStringViewModel.java | 20 ++++----- .../gui/preferences/AppearancePrefsTab.java | 7 ++-- .../logic/integrity/IntegrityMessage.java | 9 ++-- .../org/jabref/model/entry/BibtexString.java | 41 ++++++++----------- .../model/entry/identifier/MathSciNetId.java | 8 +++- .../model/groups/AutomaticKeywordGroup.java | 8 +++- .../model/groups/AutomaticPersonsGroup.java | 8 +++- .../org/jabref/model/groups/TexGroup.java | 12 ++++-- .../model/metadata/ContentSelectors.java | 14 ++++--- .../gui/search/TextFlowEqualityHelper.java | 6 ++- 10 files changed, 75 insertions(+), 58 deletions(-) diff --git a/src/main/java/org/jabref/gui/edit/ReplaceStringViewModel.java b/src/main/java/org/jabref/gui/edit/ReplaceStringViewModel.java index 89fff7fa8b7..db5ce8b4b29 100644 --- a/src/main/java/org/jabref/gui/edit/ReplaceStringViewModel.java +++ b/src/main/java/org/jabref/gui/edit/ReplaceStringViewModel.java @@ -14,8 +14,7 @@ import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; -public class ReplaceStringViewModel extends AbstractViewModel -{ +public class ReplaceStringViewModel extends AbstractViewModel { private boolean allFieldReplace; private String findString; private String replaceString; @@ -29,8 +28,7 @@ public class ReplaceStringViewModel extends AbstractViewModel private BooleanProperty selectOnlyProperty = new SimpleBooleanProperty(); - public ReplaceStringViewModel(BasePanel basePanel) - { + public ReplaceStringViewModel(BasePanel basePanel) { Objects.requireNonNull(basePanel); this.panel = basePanel; } @@ -45,20 +43,20 @@ public int replace() { final NamedCompound compound = new NamedCompound(Localization.lang("Replace string")); int counter = 0; if (selOnly) { - for (BibEntry bibEntry: this.panel.getSelectedEntries()) + for (BibEntry bibEntry : this.panel.getSelectedEntries()) { counter += replaceItem(bibEntry, compound); - } - else { - for (BibEntry bibEntry: this.panel.getDatabase().getEntries()) + } + } else { + for (BibEntry bibEntry : this.panel.getDatabase().getEntries()) { counter += replaceItem(bibEntry, compound); + } } return counter; } /** - * Does the actual operation on a Bibtex entry based on the - * settings specified in this same dialog. Returns the number of - * occurrences replaced. + * Does the actual operation on a Bibtex entry based on the settings specified in this same dialog. Returns the + * number of occurrences replaced. */ private int replaceItem(BibEntry entry, NamedCompound compound) { int counter = 0; diff --git a/src/main/java/org/jabref/gui/preferences/AppearancePrefsTab.java b/src/main/java/org/jabref/gui/preferences/AppearancePrefsTab.java index 92c62d12864..3aae702b2b0 100644 --- a/src/main/java/org/jabref/gui/preferences/AppearancePrefsTab.java +++ b/src/main/java/org/jabref/gui/preferences/AppearancePrefsTab.java @@ -53,13 +53,12 @@ public AppearancePrefsTab(DialogService dialogService, JabRefPreferences prefs) darkTheme = new RadioButton("Dark theme"); darkTheme.setToggleGroup(themeGroup); - if (prefs.get(JabRefPreferences.FX_THEME).equals(BASE_CSS)) + if (prefs.get(JabRefPreferences.FX_THEME).equals(BASE_CSS)) { lightTheme.setSelected(true); - else if (prefs.get(JabRefPreferences.FX_THEME).equals(DARK_CSS)) + } else if (prefs.get(JabRefPreferences.FX_THEME).equals(DARK_CSS)) { darkTheme.setSelected(true); - + } container.getChildren().addAll(overrideFonts, fontSizeContainer, fontTweaksLAF, lightTheme, darkTheme); - } public Node getBuilder() { diff --git a/src/main/java/org/jabref/logic/integrity/IntegrityMessage.java b/src/main/java/org/jabref/logic/integrity/IntegrityMessage.java index c04a63f87fa..f11fa936187 100644 --- a/src/main/java/org/jabref/logic/integrity/IntegrityMessage.java +++ b/src/main/java/org/jabref/logic/integrity/IntegrityMessage.java @@ -41,8 +41,12 @@ public Object clone() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } IntegrityMessage that = (IntegrityMessage) o; return Objects.equals(entry, that.entry) && Objects.equals(fieldName, that.fieldName) && @@ -53,5 +57,4 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(entry, fieldName, message); } - } diff --git a/src/main/java/org/jabref/model/entry/BibtexString.java b/src/main/java/org/jabref/model/entry/BibtexString.java index b03d9ba08e7..1e8d0170d9a 100644 --- a/src/main/java/org/jabref/model/entry/BibtexString.java +++ b/src/main/java/org/jabref/model/entry/BibtexString.java @@ -12,32 +12,22 @@ public class BibtexString implements Cloneable { *

* Differentiate a \@String based on its usage: *

- * - {@link #AUTHOR}: prefix "a", for author and editor fields. - * - {@link #INSTITUTION}: prefix "i", for institution and organization - * field - * - {@link #PUBLISHER}: prefix "p", for publisher fields - * - {@link #OTHER}: no prefix, for any field + * - {@link #AUTHOR}: prefix "a", for author and editor fields. - {@link #INSTITUTION}: prefix "i", for institution + * and organization field - {@link #PUBLISHER}: prefix "p", for publisher fields - {@link #OTHER}: no prefix, for + * any field *

* Examples: *

- * \@String { aKahle = "Kahle, Brewster " } -> author - * \@String { aStallman = "Stallman, Richard" } -> author - * \@String { iMIT = "{Massachusetts Institute of Technology ({MIT})}" } -> institution - * \@String { pMIT = "{Massachusetts Institute of Technology ({MIT}) press}" } -> publisher - * \@String { anct = "Anecdote" } -> other - * \@String { eg = "for example" } -> other - * \@String { et = " and " } -> other - * \@String { lBigMac = "Big Mac" } -> other + * \@String { aKahle = "Kahle, Brewster " } -> author \@String { aStallman = "Stallman, Richard" } -> author + * \@String { iMIT = "{Massachusetts Institute of Technology ({MIT})}" } -> institution \@String { pMIT = + * "{Massachusetts Institute of Technology ({MIT}) press}" } -> publisher \@String { anct = "Anecdote" } -> + * other \@String { eg = "for example" } -> other \@String { et = " and " } -> other \@String { + * lBigMac = "Big Mac" } -> other *

* Usage: *

- * \@Misc { - * title = "The GNU Project" - * author = aStallman # et # aKahle - * institution = iMIT - * publisher = pMIT - * note = "Just " # eg - * } + * \@Misc { title = "The GNU Project" author = aStallman # et # aKahle institution = iMIT publisher = + * pMIT note = "Just " # eg } */ public enum Type { AUTHOR("a"), @@ -135,7 +125,7 @@ public boolean hasChanged() { } /* - * Returns user comments (arbitrary text before the string) if there are any. If not returns the empty string + * Returns user comments (arbitrary text before the string) if there are any. If not returns the empty string */ public String getUserComments() { if (parsedSerialization != null) { @@ -173,8 +163,12 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } BibtexString that = (BibtexString) o; return hasChanged == that.hasChanged && Objects.equals(name, that.name) && @@ -188,5 +182,4 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(name, content, id, type, parsedSerialization, hasChanged); } - } diff --git a/src/main/java/org/jabref/model/entry/identifier/MathSciNetId.java b/src/main/java/org/jabref/model/entry/identifier/MathSciNetId.java index c848e56025b..f07ec8be273 100644 --- a/src/main/java/org/jabref/model/entry/identifier/MathSciNetId.java +++ b/src/main/java/org/jabref/model/entry/identifier/MathSciNetId.java @@ -27,8 +27,12 @@ public static Optional parse(String mrNumberRaw) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } MathSciNetId that = (MathSciNetId) o; return Objects.equals(identifier, that.identifier); } diff --git a/src/main/java/org/jabref/model/groups/AutomaticKeywordGroup.java b/src/main/java/org/jabref/model/groups/AutomaticKeywordGroup.java index 062648d7f72..f4952a4f751 100644 --- a/src/main/java/org/jabref/model/groups/AutomaticKeywordGroup.java +++ b/src/main/java/org/jabref/model/groups/AutomaticKeywordGroup.java @@ -42,8 +42,12 @@ public AbstractGroup deepCopy() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } AutomaticKeywordGroup that = (AutomaticKeywordGroup) o; return Objects.equals(keywordDelimiter, that.keywordDelimiter) && Objects.equals(field, that.field); diff --git a/src/main/java/org/jabref/model/groups/AutomaticPersonsGroup.java b/src/main/java/org/jabref/model/groups/AutomaticPersonsGroup.java index 61992508ab9..58f11af3b4c 100644 --- a/src/main/java/org/jabref/model/groups/AutomaticPersonsGroup.java +++ b/src/main/java/org/jabref/model/groups/AutomaticPersonsGroup.java @@ -21,8 +21,12 @@ public AutomaticPersonsGroup(String name, GroupHierarchyType context, String fie @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } AutomaticPersonsGroup that = (AutomaticPersonsGroup) o; return Objects.equals(field, that.field); } diff --git a/src/main/java/org/jabref/model/groups/TexGroup.java b/src/main/java/org/jabref/model/groups/TexGroup.java index 3c0ef915db9..a9e7f82e006 100644 --- a/src/main/java/org/jabref/model/groups/TexGroup.java +++ b/src/main/java/org/jabref/model/groups/TexGroup.java @@ -59,9 +59,15 @@ public AbstractGroup deepCopy() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + if (!super.equals(o)) { + return false; + } TexGroup group = (TexGroup) o; return Objects.equals(filePath, group.filePath); } diff --git a/src/main/java/org/jabref/model/metadata/ContentSelectors.java b/src/main/java/org/jabref/model/metadata/ContentSelectors.java index 96269ff9349..7f841494bf2 100644 --- a/src/main/java/org/jabref/model/metadata/ContentSelectors.java +++ b/src/main/java/org/jabref/model/metadata/ContentSelectors.java @@ -21,7 +21,7 @@ public void addContentSelector(ContentSelector contentSelector) { } public List getSelectorValuesForField(String fieldName) { - for (ContentSelector selector: contentSelectors) { + for (ContentSelector selector : contentSelectors) { if (selector.getFieldName().equals(fieldName)) { return selector.getValues(); } @@ -33,7 +33,7 @@ public List getSelectorValuesForField(String fieldName) { public void removeSelector(String fieldName) { ContentSelector toRemove = null; - for (ContentSelector selector: contentSelectors) { + for (ContentSelector selector : contentSelectors) { if (selector.getFieldName().equals(fieldName)) { toRemove = selector; break; @@ -61,7 +61,7 @@ public static ContentSelector parse(String key, String values) { public List getFieldNamesWithSelectors() { List result = new ArrayList<>(contentSelectors.size()); - for (ContentSelector selector: contentSelectors) { + for (ContentSelector selector : contentSelectors) { result.add(selector.getFieldName()); } @@ -70,8 +70,12 @@ public List getFieldNamesWithSelectors() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } ContentSelectors that = (ContentSelectors) o; return Objects.equals(contentSelectors, that.contentSelectors); } diff --git a/src/test/java/org/jabref/gui/search/TextFlowEqualityHelper.java b/src/test/java/org/jabref/gui/search/TextFlowEqualityHelper.java index 0ac74f99233..15246db4681 100644 --- a/src/test/java/org/jabref/gui/search/TextFlowEqualityHelper.java +++ b/src/test/java/org/jabref/gui/search/TextFlowEqualityHelper.java @@ -28,16 +28,18 @@ public static void assertEquals(List expectedTexts, TextFlow description) } public static boolean checkIfTextsEqualsExpectedTexts(List texts, List expectedTexts) { - if (expectedTexts.size() != texts.size()) + if (expectedTexts.size() != texts.size()) { return false; + } Text expectedText; for (int i = 0; i < expectedTexts.size(); i++) { expectedText = expectedTexts.get(i); // the strings contain not only the text but also the font and other properties // so comparing them compares the Text object as a whole // the equals method is not implemented... - if (!expectedText.toString().equals(texts.get(i).toString())) + if (!expectedText.toString().equals(texts.get(i).toString())) { return false; + } } return true; } From 333e4313975e6f9e6664283e8893a68ec05ef06e Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Tue, 23 Oct 2018 15:25:44 +0200 Subject: [PATCH 2/2] undo some unwanted formatting --- .../org/jabref/model/entry/BibtexString.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/jabref/model/entry/BibtexString.java b/src/main/java/org/jabref/model/entry/BibtexString.java index 1e8d0170d9a..52268364cd3 100644 --- a/src/main/java/org/jabref/model/entry/BibtexString.java +++ b/src/main/java/org/jabref/model/entry/BibtexString.java @@ -12,22 +12,32 @@ public class BibtexString implements Cloneable { *

* Differentiate a \@String based on its usage: *

- * - {@link #AUTHOR}: prefix "a", for author and editor fields. - {@link #INSTITUTION}: prefix "i", for institution - * and organization field - {@link #PUBLISHER}: prefix "p", for publisher fields - {@link #OTHER}: no prefix, for - * any field + * - {@link #AUTHOR}: prefix "a", for author and editor fields. + * - {@link #INSTITUTION}: prefix "i", for institution and organization + * field + * - {@link #PUBLISHER}: prefix "p", for publisher fields + * - {@link #OTHER}: no prefix, for any field *

* Examples: *

- * \@String { aKahle = "Kahle, Brewster " } -> author \@String { aStallman = "Stallman, Richard" } -> author - * \@String { iMIT = "{Massachusetts Institute of Technology ({MIT})}" } -> institution \@String { pMIT = - * "{Massachusetts Institute of Technology ({MIT}) press}" } -> publisher \@String { anct = "Anecdote" } -> - * other \@String { eg = "for example" } -> other \@String { et = " and " } -> other \@String { - * lBigMac = "Big Mac" } -> other + * \@String { aKahle = "Kahle, Brewster " } -> author + * \@String { aStallman = "Stallman, Richard" } -> author + * \@String { iMIT = "{Massachusetts Institute of Technology ({MIT})}" } -> institution + * \@String { pMIT = "{Massachusetts Institute of Technology ({MIT}) press}" } -> publisher + * \@String { anct = "Anecdote" } -> other + * \@String { eg = "for example" } -> other + * \@String { et = " and " } -> other + * \@String { lBigMac = "Big Mac" } -> other *

* Usage: *

- * \@Misc { title = "The GNU Project" author = aStallman # et # aKahle institution = iMIT publisher = - * pMIT note = "Just " # eg } + * \@Misc { + * title = "The GNU Project" + * author = aStallman # et # aKahle + * institution = iMIT + * publisher = pMIT + * note = "Just " # eg + * } */ public enum Type { AUTHOR("a"),