Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup #278

Merged
merged 11 commits into from
May 4, 2024
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,15 @@ nexusStaging {
password = getOptionalProperty("ossrhPassword")
}

def launcher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(javaVersion)
}

sonarqube {
properties {
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.organization", "itsallcode"
property "sonar.java.jdkHome", launcher.map { it.metadata.installationPath }
}
}

Expand Down
2 changes: 1 addition & 1 deletion jfxui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ tasks.jpackage {

appName = "WhiteRabbit"
vendor = '"It\'s all code"'
copyright = '"Copyright (C) 2021 Christoph Pirkl <christoph at users.sourceforge.net>"'
copyright = '"Copyright (C) 2024 Christoph Pirkl <christoph at users.sourceforge.net>"'
licenseFile = "${rootProject.rootDir}/LICENSE"
appDescription = '"A time recording tool"'
icon = "${projectDir}/src/main/resources/icon.png"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void start(Stage primaryStage)
{
this.primaryStage = primaryStage;
state.setPrimaryStage(primaryStage);
LOG.info("Starting UI");
LOG.trace("Starting UI");
doStart(primaryStage);
notifyPreloaderProgress(Type.STARTUP_FINISHED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private List<MenuItem> createPresetMenuItems()
.mapToLong(Integer::longValue)
.mapToObj(Duration::ofMinutes)
.map(this::createMenuitem)
.collect(toList());
.toList();
}

private MenuItem createMenuitem(final Duration interruption)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ static List<ActivityPropertyAdapter> wrap(final EditListener<DayRecord> editList
{
return activities.stream()
.map(a -> wrap(editListener, a))
.collect(toList());
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public class DayRecordTable

private final ClockService clockService;

public DayRecordTable(SimpleObjectProperty<DayRecord> selectedDay,
ObjectProperty<MonthIndex> currentMonth, EditListener<DayRecord> editListener,
AppService appService)
public DayRecordTable(final SimpleObjectProperty<DayRecord> selectedDay,
final ObjectProperty<MonthIndex> currentMonth, final EditListener<DayRecord> editListener,
final AppService appService)
{
this.editListener = editListener;
this.formatterService = appService.formatter();
Expand All @@ -73,9 +73,9 @@ private void fillTableWith31EmptyRows()
}
}

private void currentMonthChanged(MonthIndex previousMonth, MonthIndex month)
private void currentMonthChanged(final MonthIndex previousMonth, final MonthIndex month)
{
final List<DayRecord> sortedDays = month.getSortedDays().collect(toList());
final List<DayRecord> sortedDays = month.getSortedDays().toList();
JavaFxUtil.runOnFxApplicationThread(() -> {
LOG.trace("Current month changed from {} to {}. Updating {} days.",
previousMonth != null ? previousMonth.getYearMonth() : null, month.getYearMonth(),
Expand Down Expand Up @@ -103,7 +103,7 @@ private void updateRows(final List<DayRecord> sortedDays)
}
}

private void updateSelectedRow(MonthIndex previousMonth, MonthIndex month)
private void updateSelectedRow(final MonthIndex previousMonth, final MonthIndex month)
{
final boolean isCurrentMonth = month.getYearMonth().equals(clockService.getCurrentYearMonth());
final boolean otherMonthSelected = previousMonth != null
Expand Down Expand Up @@ -147,7 +147,7 @@ public TableView<DayRecordPropertyAdapter> initTable()
table.setRowFactory(param -> new TableRow<DayRecordPropertyAdapter>()
{
@Override
public void updateIndex(int newIndex)
public void updateIndex(final int newIndex)
{
if (newIndex != getIndex() && newIndex >= 0 && newIndex < dayRecords.size())
{
Expand All @@ -160,7 +160,7 @@ public void updateIndex(int newIndex)
}

@Override
protected void updateItem(DayRecordPropertyAdapter item, boolean empty)
protected void updateItem(final DayRecordPropertyAdapter item, final boolean empty)
{
super.updateItem(item, empty);
if (item != null)
Expand All @@ -172,7 +172,7 @@ protected void updateItem(DayRecordPropertyAdapter item, boolean empty)
return table;
}

public void selectRow(LocalDate date)
public void selectRow(final LocalDate date)
{
Objects.requireNonNull(table, "Table not yet initialized");
final int row = date.getDayOfMonth() - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private TreeTableView<ReportRow> createTreeTable()

root.getChildren().addAll(report.getDays().stream()
.map(this::createDayTreeItem)
.collect(toList()));
.toList());

final TreeTableView<ReportRow> treeTable = new TreeTableView<>(root);
treeTable.getColumns().addAll(List.of(
Expand Down Expand Up @@ -134,7 +134,7 @@ private TreeItem<ReportRow> createDayTreeItem(final ProjectReportDay day)
day.getProjects().stream()
.map(project -> new ReportRow(day, project))
.map(TreeItem::new)
.collect(toList()));
.toList());
return treeItem;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MenuBarBuilder
private final AppService appService;
private final BooleanProperty stoppedWorkingForToday;

MenuBarBuilder(UiActions actions, AppService appService, BooleanProperty stoppedWorkingForToday)
MenuBarBuilder(final UiActions actions, final AppService appService, final BooleanProperty stoppedWorkingForToday)
{
this.actions = actions;
this.appService = appService;
Expand All @@ -32,7 +32,7 @@ class MenuBarBuilder

public MenuBar build()
{
LOG.info("Creating menu bar");
LOG.trace("Creating menu bar");
final MenuBar menuBar = new MenuBar();
final Menu menuFile = menu("_File", "menu_file");
final Menu menuCalculations = menu("_Working hours", "menu_working_hours");
Expand Down Expand Up @@ -73,7 +73,7 @@ private SeparatorMenuItem separatorItem()
return new SeparatorMenuItem();
}

private Menu menu(String label, String id)
private Menu menu(final String label, final String id)
{
final Menu menu = new Menu(label);
menu.setId(id);
Expand All @@ -91,12 +91,12 @@ private MenuItem createStopWorkingForTodayMenuItem()
return menuItem;
}

private MenuItem menuItem(String label, String id, Runnable action)
private MenuItem menuItem(final String label, final String id, final Runnable action)
{
return menuItem(label, id, event -> action.run());
}

private MenuItem menuItem(String label, String id, EventHandler<ActionEvent> action)
private MenuItem menuItem(final String label, final String id, final EventHandler<ActionEvent> action)
{
final MenuItem menuItem = new MenuItem(label);
menuItem.setId(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class PluginManagerViewer
private final UiStateService uiState;
private Stage stage;

public PluginManagerViewer(Stage primaryStage, UiStateService uiState, PluginManager pluginManager)
public PluginManagerViewer(final Stage primaryStage, final UiStateService uiState,
final PluginManager pluginManager)
{
this.primaryStage = primaryStage;
this.pluginManager = pluginManager;
Expand Down Expand Up @@ -65,10 +66,10 @@ private List<PluginTableEntry> getAllPlugins()
{
return pluginManager.getAllPlugins().stream()
.map(this::createTableEntry)
.collect(toList());
.toList();
}

private PluginTableEntry createTableEntry(AppPlugin plugin)
private PluginTableEntry createTableEntry(final AppPlugin plugin)
{
return new PluginTableEntry(plugin);
}
Expand Down Expand Up @@ -96,7 +97,7 @@ public static class PluginTableEntry
{
private final AppPlugin plugin;

PluginTableEntry(AppPlugin plugin)
PluginTableEntry(final AppPlugin plugin)
{
this.plugin = plugin;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private TableView<ReportRow> createTreeTable()
{
final ObservableList<ReportRow> rows = FXCollections.observableList(
report.getProjects().stream()
.map(project -> createRow(report.getMonth().getYear(), project)).collect(toList()));
.map(project -> createRow(report.getMonth().getYear(), project)).toList());
final TableView<ReportRow> treeTable = new TableView<>(rows);
treeTable.getColumns().addAll(List.of(
UiWidget.readOnlyColumn("year", "Year",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class AutoCompleteTextField extends TextField
private final AutocompleteEntrySupplier autocompleteEntriesSupplier;
private final ContextMenu entriesPopup;

public AutoCompleteTextField(AutocompleteEntrySupplier autocompleteEntriesSupplier)
public AutoCompleteTextField(final AutocompleteEntrySupplier autocompleteEntriesSupplier)
{
this.autocompleteEntriesSupplier = autocompleteEntriesSupplier;
entriesPopup = new ContextMenu();
Expand Down Expand Up @@ -68,11 +68,11 @@ private void showPopup()
entriesPopup.getSkin().getNode().requestFocus();
}

private void populatePopup(List<AutocompleteProposal> searchResult)
private void populatePopup(final List<AutocompleteProposal> searchResult)
{
final List<MenuItem> menuItems = searchResult.stream()
.map(this::createMenuItem)
.collect(toList());
.toList();
entriesPopup.getItems().setAll(menuItems);
}

Expand Down Expand Up @@ -111,4 +111,4 @@ private List<Text> highlightMatch(final AutocompleteProposal result)
}
return textParts;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
{
private final TreeTableView<T> table;

private JavaFxTreeTable(FxRobot robot, TreeTableView<T> table)
private JavaFxTreeTable(final FxRobot robot, final TreeTableView<T> table)
Fixed Show fixed Hide fixed
{
this.table = table;
}

@SuppressWarnings("unchecked")
static <T> JavaFxTreeTable<T> find(FxRobot robot, String query, Class<T> rowType)
static <T> JavaFxTreeTable<T> find(final FxRobot robot, final String query, final Class<T> rowType)
Fixed Show fixed Hide fixed
{
return new JavaFxTreeTable<>(robot, robot.lookup(query).queryAs(TreeTableView.class));
}
Expand All @@ -28,14 +28,14 @@
{
return table.getRoot().getChildren().stream()
.map(TreeItem::getValue)
.collect(toList());
.toList();
}

List<T> getChildNodes(int level1ChildIndex)
List<T> getChildNodes(final int level1ChildIndex)
{
return table.getRoot().getChildren().get(level1ChildIndex)
.getChildren().stream()
.map(TreeItem::getValue)
.collect(toList());
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private List<String> getDayComments()
.map(DayRecord::getComment)
.filter(Objects::nonNull)
.filter(comment -> !comment.isBlank())
.collect(toList());
.toList();
}

private List<String> getActivityComments()
Expand All @@ -72,7 +72,7 @@ private List<String> getActivityComments()
.map(Activity::getComment)
.filter(Objects::nonNull)
.filter(comment -> !comment.isBlank())
.collect(toList());
.toList();
}

private Stream<Activity> getActivities()
Expand All @@ -93,7 +93,7 @@ public Optional<ProjectImpl> getSuggestedProject()
{
final List<ProjectImpl> projects = getActivities().map(Activity::getProject)
.filter(Objects::nonNull)
.collect(toList());
.toList();
final Map<String, List<ProjectImpl>> groupedProjects = projects.stream()
.collect(groupingBy(ProjectImpl::getProjectId));
final Map<String, Long> frequencyMap = projects.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toList;

import java.util.Collection;
import java.util.List;
Expand All @@ -23,17 +22,17 @@ class TextIndex implements AutocompleteEntrySupplier
private final SortedSet<String> lowerCaseValues;
private final Map<String, Long> lowerCaseFrequency;

private TextIndex(Map<String, List<String>> lowerCaseIndex, SortedSet<String> lowerCaseValues,
Map<String, Long> lowerCaseFrequency)
private TextIndex(final Map<String, List<String>> lowerCaseIndex, final SortedSet<String> lowerCaseValues,
final Map<String, Long> lowerCaseFrequency)
{
this.lowerCaseIndex = lowerCaseIndex;
this.lowerCaseValues = lowerCaseValues;
this.lowerCaseFrequency = lowerCaseFrequency;
}

static TextIndex build(Collection<String> entries)
static TextIndex build(final Collection<String> entries)
{
final List<String> uniqueEntries = entries.stream().distinct().collect(toList());
final List<String> uniqueEntries = entries.stream().distinct().toList();

final Map<String, List<String>> lowerCaseIndex = uniqueEntries.stream()
.collect(groupingBy(String::toLowerCase));
Expand All @@ -47,7 +46,7 @@ static TextIndex build(Collection<String> entries)
}

@Override
public List<AutocompleteProposal> getEntries(String searchText)
public List<AutocompleteProposal> getEntries(final String searchText)
{
if (searchText == null)
{
Expand All @@ -62,18 +61,19 @@ public List<AutocompleteProposal> getEntries(String searchText)
return createProposals(lowerCaseMatches, searchText);
}

private List<AutocompleteProposal> createProposals(SortedSet<String> lowerCaseMatches, String searchText)
private List<AutocompleteProposal> createProposals(final SortedSet<String> lowerCaseMatches,
final String searchText)
{
return lowerCaseMatches.stream()
.map(lowerCaseIndex::get)
.flatMap(List::stream)
.map(proposedText -> createProposal(searchText, proposedText))
.sorted()
.limit(MAX_RESULTS)
.collect(toList());
.toList();
}

private AutocompleteProposal createProposal(String searchText, String proposedText)
private AutocompleteProposal createProposal(final String searchText, final String proposedText)
{
final int matchPositionStart = proposedText.toLowerCase().indexOf(searchText.toLowerCase());
final long priority = lowerCaseFrequency.getOrDefault(proposedText.toLowerCase(), 0L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public Activity add()

public List<Activity> getAll()
{
final List<ActivityData> jsonActivities = getActivities().collect(toList());
final List<ActivityData> jsonActivities = getActivities().toList();
return IntStream.range(0, jsonActivities.size())
.mapToObj(i -> wrapActivity(jsonActivities.get(i), i))
.collect(toList());
.toList();
}

public boolean isEmpty()
Expand Down Expand Up @@ -141,7 +141,7 @@ public boolean isValidAllocation()
{
final List<ActivityData> remainderActivities = getActivities()
.filter(a -> a.getDuration() == null)
.collect(toList());
.toList();
if (remainderActivities.size() > 1)
{
LOG.warn("Found {} remainder activities for day {}: {}", remainderActivities.size(), dayRecord.getDate(),
Expand All @@ -164,7 +164,7 @@ public boolean isValidAllocation()

private List<ActivityData> getRemainderActivities()
{
return getActivities().filter(a -> a.getDuration() == null).collect(toList());
return getActivities().filter(a -> a.getDuration() == null).toList();
}

public Duration getDuration(final Activity activity)
Expand Down
Loading
Loading