Skip to content

Commit

Permalink
Fix some IntelliJ findings
Browse files Browse the repository at this point in the history
- Fix bug in TagBar (added itself instead of newTags)
- Wrong number of LOGGER paramters
- Inner class may be static
- Fix comment typo
- Bulk operation can be used instead of iteration
- Arrays.asList with only one element
- Optimized count by using numbers earlier
- Chained append for StringBuilder
- Initialize ArrayList by passing the initial contents in the constructor
  • Loading branch information
koppor committed Mar 29, 2020
1 parent 7541acd commit 167558d
Show file tree
Hide file tree
Showing 25 changed files with 41 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/JabRefExecutorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void shutdownEverything() {
timer.cancel();
}

private class NamedRunnable implements Runnable {
private static class NamedRunnable implements Runnable {

private final String name;

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ private void debugLogWindowState(Stage mainStage) {
if (LOGGER.isDebugEnabled()) {
StringBuilder debugLogString = new StringBuilder();
debugLogString.append("SCREEN DATA:");
debugLogString.append("mainStage.WINDOW_MAXIMISED: " + mainStage.isMaximized() + "\n");
debugLogString.append("mainStage.POS_X: " + mainStage.getX() + "\n");
debugLogString.append("mainStage.POS_Y: " + mainStage.getY() + "\n");
debugLogString.append("mainStage.SIZE_X: " + mainStage.getWidth() + "\n");
debugLogString.append("mainStages.SIZE_Y: " + mainStage.getHeight() + "\n");
debugLogString.append("mainStage.WINDOW_MAXIMISED: ").append(mainStage.isMaximized()).append("\n");
debugLogString.append("mainStage.POS_X: ").append(mainStage.getX()).append("\n");
debugLogString.append("mainStage.POS_Y: ").append(mainStage.getY()).append("\n");
debugLogString.append("mainStage.SIZE_X: ").append(mainStage.getWidth()).append("\n");
debugLogString.append("mainStages.SIZE_Y: ").append(mainStage.getHeight()).append("\n");
LOGGER.debug(debugLogString.toString());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public String getTabTitle() {
}
}
} else if (databaseLocation == DatabaseLocation.SHARED) {
title.append(this.bibDatabaseContext.getDBMSSynchronizer().getDBName() + " [" + Localization.lang("shared") + "]");
title.append(this.bibDatabaseContext.getDBMSSynchronizer().getDBName()).append(" [").append(Localization.lang("shared")).append("]");
}

return title.toString();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/SidePaneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private void updateView() {
/**
* Helper class for sorting visible components based on their preferred position.
*/
private class PreferredIndexSort implements Comparator<SidePaneComponent> {
private static class PreferredIndexSort implements Comparator<SidePaneComponent> {

private final Map<SidePaneType, Integer> preferredPositions;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/copyfiles/CopyFilesTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public CopyFilesTask(BibDatabaseContext databaseContext, List<BibEntry> entries,
this.databaseContext = databaseContext;
this.entries = entries;
this.exportPath = path;
totalFilesCount = entries.stream().flatMap(entry -> entry.getFiles().stream()).count();
totalFilesCount = entries.stream().mapToLong(entry -> entry.getFiles().size()).sum();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private void handleDuplicates(DuplicateSearchResult result) {
* Uses {@link System#identityHashCode(Object)} for identifying objects for removal, as completely identical
* {@link BibEntry BibEntries} are equal to each other.
*/
class DuplicateSearchResult {
static class DuplicateSearchResult {

private final Map<Integer, BibEntry> toRemove = new HashMap<>();
private final List<BibEntry> toAdd = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private String readFileToString(Path tmp) throws IOException {
}
}

private class ExportResult {
private static class ExportResult {
final String content;
final FileType fileType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public CaseChangeMenu(final StringProperty text) {
Objects.requireNonNull(text);

// create menu items, one for each case changer
List<Formatter> caseChangers = new ArrayList<>();
caseChangers.addAll(Formatters.getCaseChangers());
List<Formatter> caseChangers = new ArrayList<>(Formatters.getCaseChangers());
caseChangers.add(new ProtectTermsFormatter(Globals.protectedTermsLoader));
for (final Formatter caseChanger : caseChangers) {
CustomMenuItem menuItem = new CustomMenuItem(new Label(caseChanger.getName()));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/groups/GroupTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ private void setupClearButtonField(CustomTextField customTextField) {
}
}

private class DragExpansionHandler {
private static class DragExpansionHandler {
private static final long DRAG_TIME_BEFORE_EXPANDING_MS = 1000;
private TreeItem<GroupNodeViewModel> draggedItem;
private long dragStarted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public void undo() {
m_modifiedSubtree.clear();
// get node to edit
final GroupTreeNode subtreeRoot = m_groupRoot.getDescendant(m_subtreeRootPath).get(); //TODO: NULL
for (GroupTreeNode child : subtreeRoot.getChildren()) {
m_modifiedSubtree.add(child);
}
m_modifiedSubtree.addAll(subtreeRoot.getChildren());
// keep subtree handle, but restore everything else from backup
subtreeRoot.removeAllChildren();
for (GroupTreeNode child : m_subtreeBackup.getChildren()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/util/BackgroundTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public BackgroundTask<V> withInitialMessage(String message) {
return this;
}

class BackgroundProgress {
static class BackgroundProgress {

private final double workDone;
private final double max;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public DelayTaskThrottler createThrottler(int delay) {
return throttler;
}

private class FailedFuture<T> implements Future<T> {
private static class FailedFuture<T> implements Future<T> {
private final Throwable exception;

FailedFuture(Throwable exception) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jabref.gui.util;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import javafx.geometry.Pos;
import javafx.scene.Node;
Expand Down Expand Up @@ -61,6 +61,6 @@ protected Tooltip createTooltip(ValidationMessage message) {

@Override
protected Collection<Decoration> createValidationDecorations(ValidationMessage message) {
return Arrays.asList(new GraphicDecoration(createDecorationNode(message), position));
return Collections.singletonList(new GraphicDecoration(createDecorationNode(message), position));
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/util/component/TagBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ObservableList<T> getTags() {
}

public void setTags(Collection<T> newTags) {
this.tags.setAll(tags);
this.tags.setAll(newTags);
}

public ListProperty<T> tagsProperty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ public int compare(BibEntry e1, BibEntry e2) {
// Ok, parsing was successful. Update f1 and f2:
return i1.get().compareTo(i2.get()) * multiplier;
} else if (i1.isPresent()) {
// The first one was parseable, but not the second one.
// The first one was parsable, but not the second one.
// This means we consider one < two
return -1 * multiplier;
} else if (i2.isPresent()) {
// The second one was parseable, but not the first one.
// The second one was parsable, but not the first one.
// This means we consider one > two
return 1 * multiplier;
return multiplier;
}
// Else none of them were parseable, and we can fall back on comparing strings.
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/logic/bst/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ private VM(CommonTree tree) {
*/
buildInFunctions.put("stack$", context -> {
while (!stack.empty()) {
LOGGER.debug("Stack entry", stack.pop());
LOGGER.debug("Stack entry {}", stack.pop());
}
});

Expand Down Expand Up @@ -574,7 +574,7 @@ private VM(CommonTree tree) {
/*
* Pops and prints the top of the stack to the log file. It's useful for debugging.
*/
buildInFunctions.put("top$", context -> LOGGER.debug("Stack entry", stack.pop()));
buildInFunctions.put("top$", context -> LOGGER.debug("Stack entry {}", stack.pop()));

/*
* Pushes the current entry's type (book, article, etc.), but pushes
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/org/jabref/logic/cleanup/Cleanups.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ public class Cleanups {
defaultFormatters.add(new FieldFormatterCleanup(InternalField.INTERNAL_ALL_TEXT_FIELDS_FIELD, new ReplaceUnicodeLigaturesFormatter()));
DEFAULT_SAVE_ACTIONS = new FieldFormatterCleanups(false, defaultFormatters);

List<FieldFormatterCleanup> recommendedBibTeXFormatters = new ArrayList<>();
recommendedBibTeXFormatters.addAll(defaultFormatters);
List<FieldFormatterCleanup> recommendedBibTeXFormatters = new ArrayList<>(defaultFormatters);
recommendedBibTeXFormatters.add(new FieldFormatterCleanup(InternalField.INTERNAL_ALL_TEXT_FIELDS_FIELD, new HtmlToLatexFormatter()));
recommendedBibTeXFormatters.add(new FieldFormatterCleanup(InternalField.INTERNAL_ALL_TEXT_FIELDS_FIELD, new UnicodeToLatexFormatter()));
recommendedBibTeXFormatters.add(new FieldFormatterCleanup(InternalField.INTERNAL_ALL_TEXT_FIELDS_FIELD, new OrdinalsToSuperscriptFormatter()));
RECOMMEND_BIBTEX_ACTIONS = new FieldFormatterCleanups(false, recommendedBibTeXFormatters);

List<FieldFormatterCleanup> recommendedBiblatexFormatters = new ArrayList<>();
recommendedBiblatexFormatters.addAll(defaultFormatters);
List<FieldFormatterCleanup> recommendedBiblatexFormatters = new ArrayList<>(defaultFormatters);
recommendedBiblatexFormatters.add(new FieldFormatterCleanup(StandardField.TITLE, new HtmlToUnicodeFormatter()));
recommendedBiblatexFormatters.add(new FieldFormatterCleanup(InternalField.INTERNAL_ALL_TEXT_FIELDS_FIELD, new LatexToUnicodeFormatter()));
// DO NOT ADD OrdinalsToSuperscriptFormatter here, because this causes issues. See https://github.com/JabRef/jabref/issues/2596.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private <T> void parse(T entryType, BibEntry bibEntry, Entry entry) {
try {
method.invoke(entryType, new BigInteger(value));
} catch (NumberFormatException exception) {
LOGGER.warn("The value %s of the 'number' field is not an integer and thus is ignored for the export", value);
LOGGER.warn("The value {} of the 'number' field is not an integer and thus is ignored for the export", value);
}
break;
} else if (StandardField.MONTH.equals(key)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static Map<String, String> getSerializedStringMap(MetaData metaData,
StringBuilder value = new StringBuilder();
value.append(OS.NEWLINE);
for (String line: entry.getValue()) {
value.append(line.replaceAll(";", "\\\\;") + MetaData.SEPARATOR_STRING + OS.NEWLINE);
value.append(line.replaceAll(";", "\\\\;")).append(MetaData.SEPARATOR_STRING).append(OS.NEWLINE);
}
serializedMetaData.put(entry.getKey(), value.toString());
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/jabref/logic/exporter/TemplateExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.StringJoiner;
import java.util.regex.Pattern;

import org.jabref.logic.layout.Layout;
Expand Down Expand Up @@ -247,7 +248,7 @@ public void export(final BibDatabaseContext databaseContext, final Path file,
if (defLayout != null) {
missingFormatters.addAll(defLayout.getMissingFormatters());
if (!missingFormatters.isEmpty()) {
LOGGER.warn("Missing formatters found ", missingFormatters);
LOGGER.warn("Missing formatters found: {}", missingFormatters);
}
}
Map<EntryType, Layout> layouts = new HashMap<>();
Expand Down Expand Up @@ -310,10 +311,10 @@ public void export(final BibDatabaseContext databaseContext, final Path file,
// Clear custom name formatters:
layoutPreferences.clearCustomExportNameFormatters();

if (!missingFormatters.isEmpty()) {
if (!missingFormatters.isEmpty() && LOGGER.isWarnEnabled()) {
StringBuilder sb = new StringBuilder("The following formatters could not be found: ");
sb.append(String.join(", ", missingFormatters));
LOGGER.warn("Formatters not found", sb);
LOGGER.warn("Formatters {} not found", sb.toString());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ public void resetImportFormats(ImportFormatPreferences newImportFormatPreference
formats.add(new SilverPlatterImporter());

// Get custom import formats
for (CustomImporter importer : importFormatPreferences.getCustomImportList()) {
formats.add(importer);
}
formats.addAll(importFormatPreferences.getCustomImportList());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private String convertToString(BufferedReader input) throws IOException {
/**
* Small pair-class to ensure the right order of the recommendations.
*/
private class RankedBibEntry {
private static class RankedBibEntry {

public BibEntry entry;
public Integer rank;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/logic/layout/format/RTFChars.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* 1.) Remove LaTeX-Command sequences.
*
* 2.) Replace LaTeX-Special chars with RTF aquivalents.
* 2.) Replace LaTeX-Special chars with RTF equivalents.
*
* 3.) Replace emph and textit and textbf with their RTF replacements.
*
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/jabref/logic/msbib/MSBibConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public static MSBibEntry convert(BibEntry entry) {
entry.getLatexFreeField(StandardField.LANGUAGE)
.ifPresent(lang -> result.fields.put("LCID", String.valueOf(MSBibMapping.getLCID(lang))));
StringBuilder sbNumber = new StringBuilder();
entry.getLatexFreeField(StandardField.ISBN).ifPresent(isbn -> sbNumber.append(" ISBN: " + isbn));
entry.getLatexFreeField(StandardField.ISSN).ifPresent(issn -> sbNumber.append(" ISSN: " + issn));
entry.getLatexFreeField(new UnknownField("lccn")).ifPresent(lccn -> sbNumber.append("LCCN: " + lccn));
entry.getLatexFreeField(StandardField.MR_NUMBER).ifPresent(mrnumber -> sbNumber.append(" MRN: " + mrnumber));
entry.getLatexFreeField(StandardField.ISBN).ifPresent(isbn -> sbNumber.append(" ISBN: ").append(isbn));
entry.getLatexFreeField(StandardField.ISSN).ifPresent(issn -> sbNumber.append(" ISSN: ").append(issn));
entry.getLatexFreeField(new UnknownField("lccn")).ifPresent(lccn -> sbNumber.append("LCCN: ").append(lccn));
entry.getLatexFreeField(StandardField.MR_NUMBER).ifPresent(mrnumber -> sbNumber.append(" MRN: ").append(mrnumber));

result.standardNumber = sbNumber.toString();
if (result.standardNumber.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -67,7 +68,7 @@ private static List<Path> findWindowsOpenOfficeDirs() {
}

private static List<Path> findOSXOpenOfficeDirs() {
List<Path> sourceList = Arrays.asList(Paths.get("/Applications"));
List<Path> sourceList = Collections.singletonList(Paths.get("/Applications"));

return findOpenOfficeDirectories(sourceList);
}
Expand Down

0 comments on commit 167558d

Please sign in to comment.