Skip to content

Commit

Permalink
Fix some IntelliJ findings (#6204)
Browse files Browse the repository at this point in the history
* Fix some IntelliJ findings

- 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

* Fix checkstyle

* Revert partially "Fix some IntelliJ findings"

This partially reverts commit 167558d.
  • Loading branch information
koppor authored Mar 30, 2020
1 parent b8c0b31 commit d1a83cd
Show file tree
Hide file tree
Showing 19 changed files with 26 additions and 30 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
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
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
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
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/logic/exporter/TemplateExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,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 +310,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 @@ -12,7 +12,6 @@
import org.jabref.logic.importer.fileformat.BiblioscapeImporter;
import org.jabref.logic.importer.fileformat.BibtexImporter;
import org.jabref.logic.importer.fileformat.CopacImporter;
import org.jabref.logic.importer.fileformat.CustomImporter;
import org.jabref.logic.importer.fileformat.EndnoteImporter;
import org.jabref.logic.importer.fileformat.EndnoteXmlImporter;
import org.jabref.logic.importer.fileformat.InspecImporter;
Expand Down Expand Up @@ -71,9 +70,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
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 d1a83cd

Please sign in to comment.