Skip to content

Commit 4d2fd15

Browse files
authored
Refactor: use strict types, toList, List.of, remove unused variables and exceptions, convert ifs to switch, etc. (#13178)
Signed-off-by: subhramit <[email protected]>
1 parent c884329 commit 4d2fd15

File tree

39 files changed

+181
-174
lines changed

39 files changed

+181
-174
lines changed

jabgui/src/main/java/org/jabref/gui/collab/DatabaseChangeMonitor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.util.ArrayList;
55
import java.util.List;
6+
import java.util.Optional;
67

78
import javax.swing.undo.UndoManager;
89

@@ -75,10 +76,10 @@ private void notifyOnChange(List<DatabaseChange> changes) {
7576
notificationPane.notify(
7677
IconTheme.JabRefIcons.SAVE.getGraphicNode(),
7778
Localization.lang("The library has been modified by another program."),
78-
List.of(new Action(Localization.lang("Dismiss changes"), event -> notificationPane.hide()),
79-
new Action(Localization.lang("Review changes"), event -> {
79+
List.of(new Action(Localization.lang("Dismiss changes"), _ -> notificationPane.hide()),
80+
new Action(Localization.lang("Review changes"), _ -> {
8081
DatabaseChangesResolverDialog databaseChangesResolverDialog = new DatabaseChangesResolverDialog(changes, database, Localization.lang("External Changes Resolver"));
81-
var areAllChangesResolved = dialogService.showCustomDialogAndWait(databaseChangesResolverDialog);
82+
Optional<Boolean> areAllChangesResolved = dialogService.showCustomDialogAndWait(databaseChangesResolverDialog);
8283
saveState = stateManager.activeTabProperty().get().get();
8384
final NamedCompound ce = new NamedCompound(Localization.lang("Merged external changes"));
8485
changes.stream().filter(DatabaseChange::isAccepted).forEach(change -> change.applyChange(ce));

jabgui/src/main/java/org/jabref/gui/dialogs/BackupUIManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static Optional<ParserResult> showRestoreBackupDialog(DialogService dialo
5050
FileUpdateMonitor fileUpdateMonitor,
5151
UndoManager undoManager,
5252
StateManager stateManager) {
53-
var actionOpt = showBackupResolverDialog(
53+
Optional<ButtonType> actionOpt = showBackupResolverDialog(
5454
dialogService,
5555
preferences.getExternalApplicationsPreferences(),
5656
originalPath,
@@ -100,7 +100,7 @@ private static Optional<ParserResult> showReviewBackupDialog(
100100
changes,
101101
originalDatabase, "Review Backup"
102102
);
103-
var allChangesResolved = dialogService.showCustomDialogAndWait(reviewBackupDialog);
103+
Optional<Boolean> allChangesResolved = dialogService.showCustomDialogAndWait(reviewBackupDialog);
104104
LibraryTab saveState = stateManager.activeTabProperty().get().get();
105105
final NamedCompound CE = new NamedCompound(Localization.lang("Merged external changes"));
106106
changes.stream().filter(DatabaseChange::isAccepted).forEach(change -> change.applyChange(CE));

jabgui/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public List<ImportFilesResultItemViewModel> call() {
169169
});
170170
}
171171
} else if (FileUtil.isBibFile(file)) {
172-
var bibtexParserResult = contentImporter.importFromBibFile(file, fileUpdateMonitor);
172+
ParserResult bibtexParserResult = contentImporter.importFromBibFile(file, fileUpdateMonitor);
173173
List<BibEntry> entries = bibtexParserResult.getDatabaseContext().getEntries();
174174
entriesToAdd.addAll(entries);
175175
boolean success = !bibtexParserResult.hasWarnings();
@@ -207,7 +207,7 @@ public List<ImportFilesResultItemViewModel> call() {
207207
}
208208

209209
private void addResultToList(Path newFile, boolean success, String logMessage) {
210-
var result = new ImportFilesResultItemViewModel(newFile, success, logMessage);
210+
ImportFilesResultItemViewModel result = new ImportFilesResultItemViewModel(newFile, success, logMessage);
211211
results.add(result);
212212
}
213213
};

jabgui/src/main/java/org/jabref/gui/groups/GroupNodeViewModel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public class GroupNodeViewModel {
7878
@SuppressWarnings("FieldCanBeLocal")
7979
private final ObservableList<BibEntry> entriesList;
8080
@SuppressWarnings("FieldCanBeLocal")
81-
private final InvalidationListener onInvalidatedGroup = listener -> refreshGroup();
81+
private final InvalidationListener onInvalidatedGroup = _ -> refreshGroup();
8282

8383
public GroupNodeViewModel(BibDatabaseContext databaseContext, StateManager stateManager, TaskExecutor taskExecutor, GroupTreeNode groupNode, CustomLocalDragboard localDragBoard, GuiPreferences preferences) {
8484
this.databaseContext = Objects.requireNonNull(databaseContext);
@@ -111,9 +111,9 @@ public GroupNodeViewModel(BibDatabaseContext databaseContext, StateManager state
111111

112112
hasChildren = new SimpleBooleanProperty();
113113
hasChildren.bind(Bindings.isNotEmpty(children));
114-
EasyBind.subscribe(preferences.getGroupsPreferences().displayGroupCountProperty(), shouldDisplay -> updateMatchedEntries());
114+
EasyBind.subscribe(preferences.getGroupsPreferences().displayGroupCountProperty(), _ -> updateMatchedEntries());
115115
expandedProperty.set(groupNode.getGroup().isExpanded());
116-
expandedProperty.addListener((observable, oldValue, newValue) -> groupNode.getGroup().setExpanded(newValue));
116+
expandedProperty.addListener((_, _, newValue) -> groupNode.getGroup().setExpanded(newValue));
117117

118118
// Register listener
119119
// The wrapper created by the FXCollections will set a weak listener on the wrapped list. This weak listener gets garbage collected. Hence, we need to maintain a reference to this list.
@@ -147,7 +147,7 @@ public List<FieldChange> addEntriesToGroup(List<BibEntry> entries) {
147147
// return; // user aborted operation
148148
// }
149149

150-
var changes = groupNode.addEntriesToGroup(entries);
150+
List<FieldChange> changes = groupNode.addEntriesToGroup(entries);
151151

152152
// Update appearance of group
153153
anySelectedEntriesMatched.invalidate();

jabgui/src/main/java/org/jabref/gui/libraryproperties/constants/ConstantsPropertiesView.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void initialize() {
6060
.install(labelColumn, new DefaultStringConverter());
6161
labelColumn.setOnEditCommit((TableColumn.CellEditEvent<ConstantsItemModel, String> cellEvent) -> {
6262

63-
var tableView = cellEvent.getTableView();
63+
TableView<ConstantsItemModel> tableView = cellEvent.getTableView();
6464
ConstantsItemModel cellItem = tableView.getItems()
6565
.get(cellEvent.getTablePosition().getRow());
6666

@@ -77,7 +77,7 @@ public void initialize() {
7777

7878
// Resort the entries based on the keys and set the focus to the newly-created entry
7979
viewModel.resortStrings();
80-
var selectionModel = tableView.getSelectionModel();
80+
TableView.TableViewSelectionModel<ConstantsItemModel> selectionModel = tableView.getSelectionModel();
8181
selectionModel.select(cellItem);
8282
selectionModel.focus(selectionModel.getSelectedIndex());
8383
tableView.refresh();
@@ -97,9 +97,9 @@ public void initialize() {
9797
actionsColumn.setReorderable(false);
9898
actionsColumn.setCellValueFactory(cellData -> cellData.getValue().labelProperty());
9999
new ValueTableCellFactory<ConstantsItemModel, String>()
100-
.withGraphic(label -> IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode())
100+
.withGraphic(_ -> IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode())
101101
.withTooltip(label -> Localization.lang("Remove string %0", label))
102-
.withOnMouseClickedEvent(item -> evt ->
102+
.withOnMouseClickedEvent(_ -> _ ->
103103
viewModel.removeString(stringsList.getFocusModel().getFocusedItem()))
104104
.install(actionsColumn);
105105

jabgui/src/main/java/org/jabref/gui/maintable/BibEntryTableViewModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public BibEntry getEntry() {
8888

8989
private static Binding<List<AbstractGroup>> createMatchedGroupsBinding(BibDatabaseContext database, BibEntry entry) {
9090
return new UiThreadBinding<>(EasyBind.combine(entry.getFieldBinding(StandardField.GROUPS), database.getMetaData().groupsBinding(),
91-
(a, b) ->
91+
(_, _) ->
9292
database.getMetaData().getGroups().map(groupTreeNode ->
9393
groupTreeNode.getMatchingGroups(entry).stream()
9494
.map(GroupTreeNode::getGroup)
@@ -119,7 +119,7 @@ public ObservableValue<Optional<SpecialFieldValueViewModel>> getSpecialField(Spe
119119
Optional<String> currentValue = this.entry.getField(field);
120120
if (value != null) {
121121
if (currentValue.isEmpty() && value.getValue().isEmpty()) {
122-
var zeroValue = getField(field).flatMapOpt(fieldValue -> field.parseValue("CLEAR_RANK").map(SpecialFieldValueViewModel::new));
122+
OptionalBinding<SpecialFieldValueViewModel> zeroValue = getField(field).flatMapOpt(_ -> field.parseValue("CLEAR_RANK").map(SpecialFieldValueViewModel::new));
123123
specialFieldValues.put(field, zeroValue);
124124
return zeroValue;
125125
} else if (value.getValue().isEmpty() || !value.getValue().get().getValue().getFieldValue().equals(currentValue)) {

jabgui/src/main/java/org/jabref/gui/mergeentries/newmergedialog/PersonsNameFieldRowView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public PersonsNameFieldRowView(Field field, BibEntry leftEntry, BibEntry rightEn
1818
super(field, leftEntry, rightEntry, mergedEntry, fieldMergerFactory, preferences, rowIndex);
1919
assert field.getProperties().contains(FieldProperty.PERSON_NAMES);
2020

21-
var authorsParser = new AuthorListParser();
21+
AuthorListParser authorsParser = new AuthorListParser();
2222
leftEntryNames = authorsParser.parse(viewModel.getLeftFieldValue());
2323
rightEntryNames = authorsParser.parse(viewModel.getRightFieldValue());
2424

jabgui/src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ protected List<Path> call() {
379379
}
380380
};
381381

382-
taskConnectIfInstalled.setOnSucceeded(evt -> {
382+
taskConnectIfInstalled.setOnSucceeded(_ -> {
383383
List<Path> installations = new ArrayList<>(taskConnectIfInstalled.getValue());
384384
if (installations.isEmpty()) {
385385
officeInstallation.selectInstallationPath().ifPresent(installations::add);
@@ -398,7 +398,7 @@ protected List<Path> call() {
398398
}
399399

400400
private void connectManually() {
401-
var fileDialogConfiguration = new DirectoryDialogConfiguration.Builder().withInitialDirectory(System.getProperty("user.home")).build();
401+
DirectoryDialogConfiguration fileDialogConfiguration = new DirectoryDialogConfiguration.Builder().withInitialDirectory(System.getProperty("user.home")).build();
402402
Optional<Path> selectedPath = dialogService.showDirectorySelectionDialog(fileDialogConfiguration);
403403

404404
DetectOpenOfficeInstallation officeInstallation = new DetectOpenOfficeInstallation(openOfficePreferences, dialogService);

jabgui/src/main/java/org/jabref/gui/preferences/customentrytypes/CustomEntryTypesTab.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private void setupEntryTypesTable() {
106106
entryTypeActionsColumn.setReorderable(false);
107107
entryTypeActionsColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().entryType().get().getType().getDisplayName()));
108108
new ValueTableCellFactory<EntryTypeViewModel, String>()
109-
.withGraphic((type, name) -> {
109+
.withGraphic((type, _) -> {
110110
if (type instanceof CustomEntryTypeViewModel) {
111111
return IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode();
112112
} else {
@@ -120,11 +120,11 @@ private void setupEntryTypesTable() {
120120
return null;
121121
}
122122
})
123-
.withOnMouseClickedEvent((type, name) -> {
123+
.withOnMouseClickedEvent((type, _) -> {
124124
if (type instanceof CustomEntryTypeViewModel) {
125-
return evt -> viewModel.removeEntryType(entryTypesTable.getSelectionModel().getSelectedItem());
125+
return _ -> viewModel.removeEntryType(entryTypesTable.getSelectionModel().getSelectedItem());
126126
} else {
127-
return evt -> {
127+
return _ -> {
128128
};
129129
}
130130
})
@@ -135,7 +135,7 @@ private void setupEntryTypesTable() {
135135

136136
EasyBind.subscribe(viewModel.selectedEntryTypeProperty(), type -> {
137137
if (type != null) {
138-
var items = type.fields();
138+
ObservableList<FieldViewModel> items = type.fields();
139139
fields.setItems(items);
140140
} else {
141141
fields.setItems(null);
@@ -185,9 +185,9 @@ private void setupFieldsTable() {
185185
fieldTypeActionColumn.setCellValueFactory(cellData -> cellData.getValue().displayNameProperty());
186186

187187
new ValueTableCellFactory<FieldViewModel, String>()
188-
.withGraphic(item -> IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode())
188+
.withGraphic(_ -> IconTheme.JabRefIcons.DELETE_ENTRY.getGraphicNode())
189189
.withTooltip(name -> Localization.lang("Remove field %0 from currently selected entry type", name))
190-
.withOnMouseClickedEvent(item -> evt -> viewModel.removeField(fields.getSelectionModel().getSelectedItem()))
190+
.withOnMouseClickedEvent(_ -> _ -> viewModel.removeField(fields.getSelectionModel().getSelectedItem()))
191191
.install(fieldTypeActionColumn);
192192

193193
new ViewModelTableRowFactory<FieldViewModel>()

jabgui/src/main/java/org/jabref/gui/preferences/customentrytypes/CustomEntryTypesTabViewModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public void storeSettings() {
125125
entryTypesManager.update(newType, bibDatabaseMode);
126126
}
127127

128-
for (var entryType : entryTypesToDelete) {
128+
for (BibEntryType entryType : entryTypesToDelete) {
129129
entryTypesManager.removeCustomOrModifiedEntryType(entryType, bibDatabaseMode);
130130
}
131131

0 commit comments

Comments
 (0)