From 4e5dd115daa19f2c93d1e2d0db26b9b72e70c56f Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Wed, 1 May 2024 15:57:34 +0200 Subject: [PATCH 01/11] Use stream.toList() --- .../whiterabbit/jfxui/JavaFxApp.java | 2 +- .../feature/InterruptionPresetFeature.java | 2 +- .../activities/ActivityPropertyAdapter.java | 2 +- .../jfxui/table/days/DayRecordTable.java | 18 +-- .../jfxui/ui/DailyProjectReportViewer.java | 4 +- .../whiterabbit/jfxui/ui/MenuBarBuilder.java | 10 +- .../jfxui/ui/PluginManagerViewer.java | 9 +- .../jfxui/ui/YearlyProjectReportViewer.java | 2 +- .../ui/widget/AutoCompleteTextField.java | 8 +- .../jfxui/testutil/model/JavaFxTreeTable.java | 10 +- .../autocomplete/AutocompleteService.java | 6 +- .../logic/autocomplete/TextIndex.java | 18 +-- .../logic/model/DayActivities.java | 8 +- .../whiterabbit/logic/model/MonthIndex.java | 4 +- .../project/ProjectReportGenerator.java | 103 +++++++++--------- .../vacation/VacationReportGenerator.java | 12 +- .../whiterabbit/logic/service/AppService.java | 2 +- .../logic/service/plugin/AppPluginImpl.java | 2 +- .../logic/service/plugin/PluginManager.java | 4 +- .../logic/service/plugin/PluginRegistry.java | 23 ++-- .../logic/storage/CachingStorageImpl.java | 2 +- .../whiterabbit/logic/storage/MonthCache.java | 2 +- .../logic/storage/MonthIndexStorage.java | 2 +- .../logic/storage/data/JsonFileStorage.java | 4 +- .../autocomplete/AutocompleteServiceTest.java | 8 +- .../vacation/VacationReportGeneratorTest.java | 2 +- 26 files changed, 134 insertions(+), 135 deletions(-) diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java index ef57213c..4e603002 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java @@ -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); } diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java index eaaae867..f3cea25e 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java @@ -50,7 +50,7 @@ private List createPresetMenuItems() .mapToLong(Integer::longValue) .mapToObj(Duration::ofMinutes) .map(this::createMenuitem) - .collect(toList()); + .toList(); } private MenuItem createMenuitem(final Duration interruption) diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/activities/ActivityPropertyAdapter.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/activities/ActivityPropertyAdapter.java index 8c382c1f..c87aaa62 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/activities/ActivityPropertyAdapter.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/activities/ActivityPropertyAdapter.java @@ -59,6 +59,6 @@ static List wrap(final EditListener editList { return activities.stream() .map(a -> wrap(editListener, a)) - .collect(toList()); + .toList(); } } diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java index 08789b43..0fa5c2af 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java @@ -52,9 +52,9 @@ public class DayRecordTable private final ClockService clockService; - public DayRecordTable(SimpleObjectProperty selectedDay, - ObjectProperty currentMonth, EditListener editListener, - AppService appService) + public DayRecordTable(final SimpleObjectProperty selectedDay, + final ObjectProperty currentMonth, final EditListener editListener, + final AppService appService) { this.editListener = editListener; this.formatterService = appService.formatter(); @@ -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 sortedDays = month.getSortedDays().collect(toList()); + final List sortedDays = month.getSortedDays().toList(); JavaFxUtil.runOnFxApplicationThread(() -> { LOG.trace("Current month changed from {} to {}. Updating {} days.", previousMonth != null ? previousMonth.getYearMonth() : null, month.getYearMonth(), @@ -103,7 +103,7 @@ private void updateRows(final List 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 @@ -147,7 +147,7 @@ public TableView initTable() table.setRowFactory(param -> new TableRow() { @Override - public void updateIndex(int newIndex) + public void updateIndex(final int newIndex) { if (newIndex != getIndex() && newIndex >= 0 && newIndex < dayRecords.size()) { @@ -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) @@ -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; diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/DailyProjectReportViewer.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/DailyProjectReportViewer.java index 3242b493..38fe30c1 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/DailyProjectReportViewer.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/DailyProjectReportViewer.java @@ -105,7 +105,7 @@ private TreeTableView createTreeTable() root.getChildren().addAll(report.getDays().stream() .map(this::createDayTreeItem) - .collect(toList())); + .toList()); final TreeTableView treeTable = new TreeTableView<>(root); treeTable.getColumns().addAll(List.of( @@ -134,7 +134,7 @@ private TreeItem createDayTreeItem(final ProjectReportDay day) day.getProjects().stream() .map(project -> new ReportRow(day, project)) .map(TreeItem::new) - .collect(toList())); + .toList()); return treeItem; } diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/MenuBarBuilder.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/MenuBarBuilder.java index 79537a72..9774befb 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/MenuBarBuilder.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/MenuBarBuilder.java @@ -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; @@ -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"); @@ -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); @@ -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 action) + private MenuItem menuItem(final String label, final String id, final EventHandler action) { final MenuItem menuItem = new MenuItem(label); menuItem.setId(id); diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/PluginManagerViewer.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/PluginManagerViewer.java index d8b072a4..d18c9174 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/PluginManagerViewer.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/PluginManagerViewer.java @@ -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; @@ -65,10 +66,10 @@ private List 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); } @@ -96,7 +97,7 @@ public static class PluginTableEntry { private final AppPlugin plugin; - PluginTableEntry(AppPlugin plugin) + PluginTableEntry(final AppPlugin plugin) { this.plugin = plugin; } diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java index 6acb616c..0ad1a07c 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java @@ -50,7 +50,7 @@ private TableView createTreeTable() { final ObservableList 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 treeTable = new TableView<>(rows); treeTable.getColumns().addAll(List.of( UiWidget.readOnlyColumn("year", "Year", diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/widget/AutoCompleteTextField.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/widget/AutoCompleteTextField.java index 1733266b..666e15b0 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/widget/AutoCompleteTextField.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/widget/AutoCompleteTextField.java @@ -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(); @@ -68,11 +68,11 @@ private void showPopup() entriesPopup.getSkin().getNode().requestFocus(); } - private void populatePopup(List searchResult) + private void populatePopup(final List searchResult) { final List menuItems = searchResult.stream() .map(this::createMenuItem) - .collect(toList()); + .toList(); entriesPopup.getItems().setAll(menuItems); } @@ -111,4 +111,4 @@ private List highlightMatch(final AutocompleteProposal result) } return textParts; } -} \ No newline at end of file +} diff --git a/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/testutil/model/JavaFxTreeTable.java b/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/testutil/model/JavaFxTreeTable.java index 383f847a..1cfd913d 100644 --- a/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/testutil/model/JavaFxTreeTable.java +++ b/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/testutil/model/JavaFxTreeTable.java @@ -13,13 +13,13 @@ public class JavaFxTreeTable { private final TreeTableView table; - private JavaFxTreeTable(FxRobot robot, TreeTableView table) + private JavaFxTreeTable(final FxRobot robot, final TreeTableView table) { this.table = table; } @SuppressWarnings("unchecked") - static JavaFxTreeTable find(FxRobot robot, String query, Class rowType) + static JavaFxTreeTable find(final FxRobot robot, final String query, final Class rowType) { return new JavaFxTreeTable<>(robot, robot.lookup(query).queryAs(TreeTableView.class)); } @@ -28,14 +28,14 @@ List getRootChildNodes() { return table.getRoot().getChildren().stream() .map(TreeItem::getValue) - .collect(toList()); + .toList(); } - List getChildNodes(int level1ChildIndex) + List getChildNodes(final int level1ChildIndex) { return table.getRoot().getChildren().get(level1ChildIndex) .getChildren().stream() .map(TreeItem::getValue) - .collect(toList()); + .toList(); } } diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteService.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteService.java index 9e03219c..995d89b7 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteService.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteService.java @@ -63,7 +63,7 @@ private List getDayComments() .map(DayRecord::getComment) .filter(Objects::nonNull) .filter(comment -> !comment.isBlank()) - .collect(toList()); + .toList(); } private List getActivityComments() @@ -72,7 +72,7 @@ private List getActivityComments() .map(Activity::getComment) .filter(Objects::nonNull) .filter(comment -> !comment.isBlank()) - .collect(toList()); + .toList(); } private Stream getActivities() @@ -93,7 +93,7 @@ public Optional getSuggestedProject() { final List projects = getActivities().map(Activity::getProject) .filter(Objects::nonNull) - .collect(toList()); + .toList(); final Map> groupedProjects = projects.stream() .collect(groupingBy(ProjectImpl::getProjectId)); final Map frequencyMap = projects.stream() diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/TextIndex.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/TextIndex.java index 26760661..b174a7f8 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/TextIndex.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/TextIndex.java @@ -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; @@ -23,17 +22,17 @@ class TextIndex implements AutocompleteEntrySupplier private final SortedSet lowerCaseValues; private final Map lowerCaseFrequency; - private TextIndex(Map> lowerCaseIndex, SortedSet lowerCaseValues, - Map lowerCaseFrequency) + private TextIndex(final Map> lowerCaseIndex, final SortedSet lowerCaseValues, + final Map lowerCaseFrequency) { this.lowerCaseIndex = lowerCaseIndex; this.lowerCaseValues = lowerCaseValues; this.lowerCaseFrequency = lowerCaseFrequency; } - static TextIndex build(Collection entries) + static TextIndex build(final Collection entries) { - final List uniqueEntries = entries.stream().distinct().collect(toList()); + final List uniqueEntries = entries.stream().distinct().toList(); final Map> lowerCaseIndex = uniqueEntries.stream() .collect(groupingBy(String::toLowerCase)); @@ -47,7 +46,7 @@ static TextIndex build(Collection entries) } @Override - public List getEntries(String searchText) + public List getEntries(final String searchText) { if (searchText == null) { @@ -62,7 +61,8 @@ public List getEntries(String searchText) return createProposals(lowerCaseMatches, searchText); } - private List createProposals(SortedSet lowerCaseMatches, String searchText) + private List createProposals(final SortedSet lowerCaseMatches, + final String searchText) { return lowerCaseMatches.stream() .map(lowerCaseIndex::get) @@ -70,10 +70,10 @@ private List createProposals(SortedSet lowerCaseMa .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); diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/DayActivities.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/DayActivities.java index 0bbd8651..4684e801 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/DayActivities.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/DayActivities.java @@ -56,10 +56,10 @@ public Activity add() public List getAll() { - final List jsonActivities = getActivities().collect(toList()); + final List jsonActivities = getActivities().toList(); return IntStream.range(0, jsonActivities.size()) .mapToObj(i -> wrapActivity(jsonActivities.get(i), i)) - .collect(toList()); + .toList(); } public boolean isEmpty() @@ -141,7 +141,7 @@ public boolean isValidAllocation() { final List 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(), @@ -164,7 +164,7 @@ public boolean isValidAllocation() private List getRemainderActivities() { - return getActivities().filter(a -> a.getDuration() == null).collect(toList()); + return getActivities().filter(a -> a.getDuration() == null).toList(); } public Duration getDuration(final Activity activity) diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/MonthIndex.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/MonthIndex.java index 43469de6..ac3b980e 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/MonthIndex.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/MonthIndex.java @@ -91,7 +91,7 @@ public MonthData getMonthRecord() final List sortedNonDummyJsonDays = getSortedDays() // .filter(d -> !d.isDummyDay()) // .map(DayRecord::getJsonDay) // - .collect(toList()); + .toList(); final MonthData month = modelFactory.createMonthData(); month.setOvertimePreviousMonth(monthRecord.getOvertimePreviousMonth()); @@ -139,6 +139,6 @@ public List getVacationDays() return monthRecord.getDays().stream() .filter(day -> day.getType() == DayType.VACATION) .map(DayData::getDate) - .collect(toList()); + .toList(); } } diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java index f06450e3..28fd3922 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java @@ -1,7 +1,6 @@ package org.itsallcode.whiterabbit.logic.report.project; import static java.util.stream.Collectors.groupingBy; -import static java.util.stream.Collectors.toList; import java.time.Duration; import java.time.YearMonth; @@ -20,64 +19,64 @@ public class ProjectReportGenerator { - private final Storage storage; + private final Storage storage; - public ProjectReportGenerator(final Storage storage) - { - this.storage = storage; - } + public ProjectReportGenerator(final Storage storage) + { + this.storage = storage; + } - public ProjectReport generateReport(final YearMonth month) - { - final List sortedDays = storage.loadMonth(month) - .map(MonthIndex::getSortedDays).orElse(Stream.empty()).collect(toList()); + public ProjectReport generateReport(final YearMonth month) + { + final List sortedDays = storage.loadMonth(month) + .map(MonthIndex::getSortedDays).orElse(Stream.empty()).toList(); - final List reportDays = sortedDays.stream() - .map(this::generateDayReport) - .toList(); + final List reportDays = sortedDays.stream() + .map(this::generateDayReport) + .toList(); - final List reportProjects = sortedDays.stream() - .flatMap(day -> day.activities().getAll().stream()) - .filter(activity -> activity.getProject() != null) - .collect(groupingBy(Activity::getProject)) - .values().stream() - .map(this::aggregateProject) - .collect(toList()); + final List reportProjects = sortedDays.stream() + .flatMap(day -> day.activities().getAll().stream()) + .filter(activity -> activity.getProject() != null) + .collect(groupingBy(Activity::getProject)) + .values().stream() + .map(this::aggregateProject) + .toList(); - return new ProjectReportImpl(month, reportDays, reportProjects); - } + return new ProjectReportImpl(month, reportDays, reportProjects); + } - private ProjectReportDay generateDayReport(final DayRecord dayRecord) - { - final List projects = dayRecord.activities() - .getAll().stream() - .filter(activity -> activity.getProject() != null) - .collect(groupingBy(this::activityProject)) - .values().stream() - .map(this::aggregateProject) - .collect(toList()); + private ProjectReportDay generateDayReport(final DayRecord dayRecord) + { + final List projects = dayRecord.activities() + .getAll().stream() + .filter(activity -> activity.getProject() != null) + .collect(groupingBy(this::activityProject)) + .values().stream() + .map(this::aggregateProject) + .toList(); - return new DayImpl(dayRecord.getDate(), dayRecord.getType(), dayRecord.getComment(), projects); - } + return new DayImpl(dayRecord.getDate(), dayRecord.getType(), dayRecord.getComment(), projects); + } - private String activityProject(final Activity activity) - { - return activity.getProject().getProjectId(); - } + private String activityProject(final Activity activity) + { + return activity.getProject().getProjectId(); + } - private ProjectReportImpl.ProjectActivityImpl aggregateProject(final List projectActivites) - { - final Duration totalWorkingTime = projectActivites.stream() - .filter(activity -> activity.getDuration() != null) - .map(Activity::getDuration).reduce(Duration::plus) - .orElse(Duration.ZERO); - final List comments = projectActivites.stream() - .map(Activity::getComment) - .filter(Objects::nonNull) - .filter(comment -> !comment.isBlank()) - .distinct() - .toList(); - return new ProjectReportImpl.ProjectActivityImpl(projectActivites.get(0).getProject(), totalWorkingTime, - comments); - } + private ProjectReportImpl.ProjectActivityImpl aggregateProject(final List projectActivites) + { + final Duration totalWorkingTime = projectActivites.stream() + .filter(activity -> activity.getDuration() != null) + .map(Activity::getDuration).reduce(Duration::plus) + .orElse(Duration.ZERO); + final List comments = projectActivites.stream() + .map(Activity::getComment) + .filter(Objects::nonNull) + .filter(comment -> !comment.isBlank()) + .distinct() + .toList(); + return new ProjectReportImpl.ProjectActivityImpl(projectActivites.get(0).getProject(), totalWorkingTime, + comments); + } } diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/vacation/VacationReportGenerator.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/vacation/VacationReportGenerator.java index eb0ee679..3a50acd3 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/vacation/VacationReportGenerator.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/vacation/VacationReportGenerator.java @@ -24,13 +24,13 @@ public class VacationReportGenerator private final Storage storage; private final AvailableVacationCalculator availableVacationCalculator; - VacationReportGenerator(Storage storage, AvailableVacationCalculator availableVacationCalculator) + VacationReportGenerator(final Storage storage, final AvailableVacationCalculator availableVacationCalculator) { this.storage = storage; this.availableVacationCalculator = availableVacationCalculator; } - public VacationReportGenerator(Storage storage) + public VacationReportGenerator(final Storage storage) { this(storage, new AvailableVacationCalculator()); } @@ -51,7 +51,7 @@ private class Calculator final Map workingMonthCountByYear = availableDataYearMonth.stream() // .map(Year::from) // .collect(groupingBy(Function.identity(), counting())); - final List years = workingMonthCountByYear.keySet().stream().sorted().collect(toList()); + final List years = workingMonthCountByYear.keySet().stream().sorted().toList(); private List vacationDaysPerYear() { @@ -66,7 +66,7 @@ private List vacationDaysPerYear() return vacationYears; } - private VacationYear calculateVacation(final Year year, VacationYear previousYear) + private VacationYear calculateVacation(final Year year, final VacationYear previousYear) { final int daysRemainingFromPreviousYear = previousYear != null ? previousYear.getDaysRemaining() : 0; return new VacationYear(year, vacationDaysCount(year), availableVacation(year), @@ -96,10 +96,10 @@ public List vacationDaysPerMonth() return monthData.values().stream() // .sorted(comparing(MonthIndex::getYearMonth)) // .map(this::calculateMonthVacation) // - .collect(toList()); + .toList(); } - private VacationMonth calculateMonthVacation(MonthIndex month) + private VacationMonth calculateMonthVacation(final MonthIndex month) { return new VacationMonth(month.getYearMonth(), month.getVacationDays()); } diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/AppService.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/AppService.java index 33200b6e..256c06dc 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/AppService.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/AppService.java @@ -183,7 +183,7 @@ public void updatePreviousMonthOvertimeField() { final List months = storage.loadAll().getMonths().stream() .sorted(Comparator.comparing(MonthIndex::getYearMonth)) // - .collect(toList()); + .toList(); Duration totalOvertime = Duration.ZERO; for (final MonthIndex month : months) { diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/AppPluginImpl.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/AppPluginImpl.java index 87f10803..1eed0bff 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/AppPluginImpl.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/AppPluginImpl.java @@ -50,7 +50,7 @@ public Collection getFeatures() { return Stream.of(AppPluginFeature.values()) .filter(feature -> supports(feature.getFeatureClass())) - .collect(toList()); + .toList(); } @Override diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/PluginManager.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/PluginManager.java index bbf6ca86..cb2e5291 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/PluginManager.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/PluginManager.java @@ -35,14 +35,14 @@ public List getAllFeatures(Class featureType) .map(plugin -> plugin.getFeature(featureType)) .filter(Optional::isPresent) .map(Optional::get) - .collect(toList()); + .toList(); } public List findPluginsSupporting(Class featureType) { return pluginRegistry.getAllPlugins().stream() .filter(plugin -> plugin.supports(featureType)) - .collect(toList()); + .toList(); } @SuppressWarnings("java:S1452") // Use generic wildcard as return type. diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/PluginRegistry.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/PluginRegistry.java index 644c4e84..cc035771 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/PluginRegistry.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/PluginRegistry.java @@ -1,7 +1,6 @@ package org.itsallcode.whiterabbit.logic.service.plugin; import static java.util.Collections.emptyList; -import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toMap; import java.io.IOException; @@ -32,7 +31,7 @@ class PluginRegistry private Map plugins = new HashMap<>(); private final Config config; - PluginRegistry(Config config) + PluginRegistry(final Config config) { this.config = config; } @@ -71,12 +70,12 @@ private Stream pluginsFromClasspath() return loadPlugins(PluginOrigin.forCurrentClassPath()); } - private Stream loadPlugins(Path jar) + private Stream loadPlugins(final Path jar) { return loadPlugins(PluginOrigin.forJar(jar)); } - private Stream loadPlugins(PluginOrigin origin) + private Stream loadPlugins(final PluginOrigin origin) { final ServiceLoader serviceLoader = ServiceLoader.load(Plugin.class, origin.getClassLoader()); return serviceLoader.stream() @@ -88,24 +87,24 @@ private List getPluginJars() final Path pluginDir = config.getPluginDir(); if (pluginDir == null || !Files.exists(pluginDir)) { - LOG.info("Plugin directory {} does not exist", pluginDir); + LOG.debug("Plugin directory {} does not exist", pluginDir); return emptyList(); } - LOG.info("Searching plugin jars in {}", pluginDir); + LOG.debug("Searching plugin jars in {}", pluginDir); try (Stream stream = Files.list(pluginDir)) { return stream.filter(file -> file.getFileName().toString().endsWith(".jar")) - .collect(toList()); + .toList(); } catch (final IOException e) { - throw new UncheckedIOException("Error listing plugins in " + pluginDir, e); + throw new UncheckedIOException("Error listing plugins in '" + pluginDir + "'", e); } } - private Optional loadPlugin(Provider provider, PluginOrigin origin) + private Optional loadPlugin(final Provider provider, final PluginOrigin origin) { - LOG.info("Loading plugin {} using {}", provider.type(), origin); + LOG.debug("Loading plugin {} using {}", provider.type().getName(), origin); try { final Plugin pluginInstance = provider.get(); @@ -115,7 +114,7 @@ private Optional loadPlugin(Provider provider, PluginOrig } catch (final RuntimeException e) { - LOG.warn("Error loading plugin {} using {}", provider.type(), origin, e); + LOG.warn("Error loading plugin {} using {}", provider.type().getName(), origin, e); return Optional.empty(); } } @@ -125,7 +124,7 @@ Collection getAllPlugins() return plugins.values(); } - AppPluginImpl getPlugin(String id) + AppPluginImpl getPlugin(final String id) { final AppPluginImpl plugin = plugins.get(id); if (plugin == null) diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/CachingStorageImpl.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/CachingStorageImpl.java index 308ba309..37039679 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/CachingStorageImpl.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/CachingStorageImpl.java @@ -97,7 +97,7 @@ List getRequiredYearMonths(final LocalDate maxAge) final YearMonth oldestYearMonth = YearMonth.from(maxAge); return delegateStorage.getAvailableDataMonths().stream() .filter(month -> !month.isBefore(oldestYearMonth)) - .collect(toList()); + .toList(); } @Override diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/MonthCache.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/MonthCache.java index 2627ba9b..758abbe0 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/MonthCache.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/MonthCache.java @@ -37,7 +37,7 @@ List getLatestDayRecords(final LocalDate maxAge) .filter(month -> !month.getYearMonth().isBefore(oldestYearMonth)) .flatMap(MonthIndex::getSortedDays) .filter(day -> !day.getDate().isBefore(maxAge)) - .collect(toList()); + .toList(); } private void notifyListeners(final MonthIndex updatedMonth) diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/MonthIndexStorage.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/MonthIndexStorage.java index c161b3e6..99513670 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/MonthIndexStorage.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/MonthIndexStorage.java @@ -62,7 +62,7 @@ public MultiMonthIndex loadAll() { return new MultiMonthIndex(fileStorage.loadAll().stream() .map(this::createMonthIndex) - .collect(toList())); + .toList()); } @Override diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/data/JsonFileStorage.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/data/JsonFileStorage.java index 5c8c7ef4..c456c3fe 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/data/JsonFileStorage.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/data/JsonFileStorage.java @@ -115,7 +115,7 @@ private void createDirectory(Path dir) @Override public List getAvailableDataMonths() { - return dateToFileMapper.getAllYearMonths().sorted().collect(toList()); + return dateToFileMapper.getAllYearMonths().sorted().toList(); } @Override @@ -125,7 +125,7 @@ public List loadAll() .filter(file -> !file.getFileName().toString().equals(Config.PROJECTS_JSON)) .map(this::loadFromFile) .sorted(comparing(JsonMonth::getYear).thenComparing(JsonMonth::getMonth)) - .collect(toList()); + .toList(); } @Override diff --git a/logic/src/test/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteServiceTest.java b/logic/src/test/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteServiceTest.java index 9977f63f..2aead783 100644 --- a/logic/src/test/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteServiceTest.java +++ b/logic/src/test/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteServiceTest.java @@ -151,12 +151,12 @@ private void simulateDays(final List days) private List createDayRecordsWithActivityComments(final String... comments) { - return Arrays.stream(comments).map(this::createDayRecordWithActivityComment).collect(toList()); + return Arrays.stream(comments).map(this::createDayRecordWithActivityComment).toList(); } private List createDayRecordsWithActivityProjects(final String... projectIds) { - return Arrays.stream(projectIds).map(this::createDayRecordWithProject).collect(toList()); + return Arrays.stream(projectIds).map(this::createDayRecordWithProject).toList(); } private DayRecord createDayRecordWithProject(final String projectId) @@ -185,7 +185,7 @@ private DayRecord dayWithActivities(final Activity... activityList) private List dayRecordsWithComments(final String... comments) { - return Arrays.stream(comments).map(this::createDayRecord).collect(toList()); + return Arrays.stream(comments).map(this::createDayRecord).toList(); } private DayRecord createDayRecord(final String comment) @@ -194,4 +194,4 @@ private DayRecord createDayRecord(final String comment) when(dayRecord.getComment()).thenReturn(comment); return dayRecord; } -} \ No newline at end of file +} diff --git a/logic/src/test/java/org/itsallcode/whiterabbit/logic/report/vacation/VacationReportGeneratorTest.java b/logic/src/test/java/org/itsallcode/whiterabbit/logic/report/vacation/VacationReportGeneratorTest.java index bd2cc007..ab07dce1 100644 --- a/logic/src/test/java/org/itsallcode/whiterabbit/logic/report/vacation/VacationReportGeneratorTest.java +++ b/logic/src/test/java/org/itsallcode/whiterabbit/logic/report/vacation/VacationReportGeneratorTest.java @@ -253,7 +253,7 @@ private MonthIndex month(int year, Month month, LocalDate... vacationDays) private void simulateMonths(MonthIndex... months) { final List availableDataYearMonth = Arrays.stream(months).map(MonthIndex::getYearMonth) - .collect(toList()); + .toList(); when(storageMock.getAvailableDataMonths()).thenReturn(availableDataYearMonth); for (final MonthIndex monthIndex : months) From f05b4a9ffa04dfc7f316ef092a990d05c546f652 Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Wed, 1 May 2024 15:57:45 +0200 Subject: [PATCH 02/11] Update copyright year --- jfxui/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jfxui/build.gradle b/jfxui/build.gradle index e37e62d1..bd607595 100644 --- a/jfxui/build.gradle +++ b/jfxui/build.gradle @@ -154,7 +154,7 @@ tasks.jpackage { appName = "WhiteRabbit" vendor = '"It\'s all code"' - copyright = '"Copyright (C) 2021 Christoph Pirkl "' + copyright = '"Copyright (C) 2024 Christoph Pirkl "' licenseFile = "${rootProject.rootDir}/LICENSE" appDescription = '"A time recording tool"' icon = "${projectDir}/src/main/resources/icon.png" From a912098b6b23246acef46c00d1a4128d70795872 Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Wed, 1 May 2024 17:37:35 +0200 Subject: [PATCH 03/11] Configure JDK home for sonar --- build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.gradle b/build.gradle index 49f7fca6..0ab1b7ef 100644 --- a/build.gradle +++ b/build.gradle @@ -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 } } } From 7af31e89a3b6de7c8f5499a3dda3c7c3e7bf7624 Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Wed, 1 May 2024 17:41:03 +0200 Subject: [PATCH 04/11] Revert "Configure JDK home for sonar" This reverts commit a912098b6b23246acef46c00d1a4128d70795872. --- build.gradle | 5 ----- 1 file changed, 5 deletions(-) diff --git a/build.gradle b/build.gradle index 0ab1b7ef..49f7fca6 100644 --- a/build.gradle +++ b/build.gradle @@ -91,15 +91,10 @@ 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 } } } From a386f1e75814a9b5ddfb2a2c15e6f379ee32902d Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Wed, 1 May 2024 17:56:53 +0200 Subject: [PATCH 05/11] Refactor import statements in several files --- .../jfxui/feature/InterruptionPresetFeature.java | 15 +++++++++++---- .../activities/ActivityPropertyAdapter.java | 2 -- .../jfxui/table/days/DayRecordTable.java | 2 -- .../jfxui/ui/DailyProjectReportViewer.java | 1 - .../jfxui/ui/PluginManagerViewer.java | 1 - .../jfxui/ui/YearlyProjectReportViewer.java | 1 - .../jfxui/ui/widget/AutoCompleteTextField.java | 2 -- .../jfxui/testutil/model/JavaFxTreeTable.java | 11 +++++++---- .../whiterabbit/logic/model/DayActivities.java | 1 - .../whiterabbit/logic/model/MonthIndex.java | 1 - .../report/project/ProjectReportGenerator.java | 2 +- .../report/vacation/VacationReportGenerator.java | 1 - .../whiterabbit/logic/service/AppService.java | 2 -- .../logic/service/plugin/AppPluginImpl.java | 2 -- .../logic/service/plugin/PluginManager.java | 13 ++++++------- .../logic/storage/CachingStorageImpl.java | 2 -- .../whiterabbit/logic/storage/MonthCache.java | 2 -- .../logic/storage/MonthIndexStorage.java | 2 -- .../logic/storage/data/JsonFileStorage.java | 16 ++++++++-------- .../autocomplete/AutocompleteServiceTest.java | 7 +++++-- .../vacation/VacationReportGeneratorTest.java | 5 ++--- 21 files changed, 40 insertions(+), 51 deletions(-) diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java index f3cea25e..17f2df89 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java @@ -1,7 +1,5 @@ package org.itsallcode.whiterabbit.jfxui.feature; -import static java.util.stream.Collectors.toList; - import java.text.NumberFormat; import java.text.ParsePosition; import java.time.Duration; @@ -13,9 +11,18 @@ import javafx.application.Platform; import javafx.geometry.Pos; import javafx.scene.Node; -import javafx.scene.control.*; import javafx.scene.control.ButtonBar.ButtonData; -import javafx.scene.layout.*; +import javafx.scene.control.ButtonType; +import javafx.scene.control.Dialog; +import javafx.scene.control.DialogPane; +import javafx.scene.control.Label; +import javafx.scene.control.MenuItem; +import javafx.scene.control.Spinner; +import javafx.scene.control.SplitMenuButton; +import javafx.scene.control.TextFormatter; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.Priority; +import javafx.scene.layout.Region; import javafx.util.converter.IntegerStringConverter; public class InterruptionPresetFeature diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/activities/ActivityPropertyAdapter.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/activities/ActivityPropertyAdapter.java index c87aaa62..3d41424b 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/activities/ActivityPropertyAdapter.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/activities/ActivityPropertyAdapter.java @@ -1,7 +1,5 @@ package org.itsallcode.whiterabbit.jfxui.table.activities; -import static java.util.stream.Collectors.toList; - import java.time.Duration; import java.util.List; diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java index 0fa5c2af..67f70754 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java @@ -1,7 +1,5 @@ package org.itsallcode.whiterabbit.jfxui.table.days; -import static java.util.stream.Collectors.toList; - import java.time.Duration; import java.time.LocalDate; import java.time.LocalTime; diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/DailyProjectReportViewer.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/DailyProjectReportViewer.java index 38fe30c1..0b150589 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/DailyProjectReportViewer.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/DailyProjectReportViewer.java @@ -1,7 +1,6 @@ package org.itsallcode.whiterabbit.jfxui.ui; import static java.util.stream.Collectors.joining; -import static java.util.stream.Collectors.toList; import java.time.Duration; import java.time.LocalDate; diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/PluginManagerViewer.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/PluginManagerViewer.java index d18c9174..de5e5346 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/PluginManagerViewer.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/PluginManagerViewer.java @@ -1,7 +1,6 @@ package org.itsallcode.whiterabbit.jfxui.ui; import static java.util.stream.Collectors.joining; -import static java.util.stream.Collectors.toList; import java.util.List; diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java index 0ad1a07c..df0e827e 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java @@ -1,7 +1,6 @@ package org.itsallcode.whiterabbit.jfxui.ui; import static java.util.stream.Collectors.joining; -import static java.util.stream.Collectors.toList; import java.time.Duration; import java.util.List; diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/widget/AutoCompleteTextField.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/widget/AutoCompleteTextField.java index 666e15b0..6b27728a 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/widget/AutoCompleteTextField.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/widget/AutoCompleteTextField.java @@ -1,7 +1,5 @@ package org.itsallcode.whiterabbit.jfxui.ui.widget; -import static java.util.stream.Collectors.toList; - import java.util.ArrayList; import java.util.List; diff --git a/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/testutil/model/JavaFxTreeTable.java b/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/testutil/model/JavaFxTreeTable.java index 1cfd913d..5d40f221 100644 --- a/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/testutil/model/JavaFxTreeTable.java +++ b/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/testutil/model/JavaFxTreeTable.java @@ -1,7 +1,5 @@ package org.itsallcode.whiterabbit.jfxui.testutil.model; -import static java.util.stream.Collectors.toList; - import java.util.List; import org.testfx.api.FxRobot; @@ -12,22 +10,26 @@ public class JavaFxTreeTable { private final TreeTableView table; + private final Class rowType; - private JavaFxTreeTable(final FxRobot robot, final TreeTableView table) + private JavaFxTreeTable(final TreeTableView table, final Class rowType) { this.table = table; + this.rowType = rowType; } @SuppressWarnings("unchecked") static JavaFxTreeTable find(final FxRobot robot, final String query, final Class rowType) { - return new JavaFxTreeTable<>(robot, robot.lookup(query).queryAs(TreeTableView.class)); + final TreeTableView table = robot.lookup(query).queryAs(TreeTableView.class); + return new JavaFxTreeTable<>(table, rowType); } List getRootChildNodes() { return table.getRoot().getChildren().stream() .map(TreeItem::getValue) + .map(rowType::cast) .toList(); } @@ -36,6 +38,7 @@ List getChildNodes(final int level1ChildIndex) return table.getRoot().getChildren().get(level1ChildIndex) .getChildren().stream() .map(TreeItem::getValue) + .map(rowType::cast) .toList(); } } diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/DayActivities.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/DayActivities.java index 4684e801..59c9a93f 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/DayActivities.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/DayActivities.java @@ -1,7 +1,6 @@ package org.itsallcode.whiterabbit.logic.model; import static java.util.Collections.emptyList; -import static java.util.stream.Collectors.toList; import java.time.Duration; import java.util.ArrayList; diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/MonthIndex.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/MonthIndex.java index ac3b980e..641da110 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/MonthIndex.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/MonthIndex.java @@ -1,6 +1,5 @@ package org.itsallcode.whiterabbit.logic.model; -import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toMap; import java.time.Duration; diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java index 28fd3922..74a8d063 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java @@ -64,7 +64,7 @@ private String activityProject(final Activity activity) return activity.getProject().getProjectId(); } - private ProjectReportImpl.ProjectActivityImpl aggregateProject(final List projectActivites) + private ProjectReportActivity aggregateProject(final List projectActivites) { final Duration totalWorkingTime = projectActivites.stream() .filter(activity -> activity.getDuration() != null) diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/vacation/VacationReportGenerator.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/vacation/VacationReportGenerator.java index 3a50acd3..9adcdbd0 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/vacation/VacationReportGenerator.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/vacation/VacationReportGenerator.java @@ -3,7 +3,6 @@ import static java.util.Comparator.comparing; import static java.util.stream.Collectors.counting; import static java.util.stream.Collectors.groupingBy; -import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toMap; import java.time.Year; diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/AppService.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/AppService.java index 256c06dc..53a8ab89 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/AppService.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/AppService.java @@ -1,7 +1,5 @@ package org.itsallcode.whiterabbit.logic.service; -import static java.util.stream.Collectors.toList; - import java.io.Closeable; import java.time.Clock; import java.time.Duration; diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/AppPluginImpl.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/AppPluginImpl.java index 1eed0bff..eb38ce11 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/AppPluginImpl.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/AppPluginImpl.java @@ -1,7 +1,5 @@ package org.itsallcode.whiterabbit.logic.service.plugin; -import static java.util.stream.Collectors.toList; - import java.nio.file.Path; import java.util.Collection; import java.util.Optional; diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/PluginManager.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/PluginManager.java index cb2e5291..dff8f970 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/PluginManager.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/PluginManager.java @@ -1,7 +1,5 @@ package org.itsallcode.whiterabbit.logic.service.plugin; -import static java.util.stream.Collectors.toList; - import java.util.Collection; import java.util.List; import java.util.Optional; @@ -16,12 +14,12 @@ public class PluginManager private static final Logger LOG = LogManager.getLogger(PluginManager.class); private final PluginRegistry pluginRegistry; - PluginManager(PluginRegistry pluginRegistry) + PluginManager(final PluginRegistry pluginRegistry) { this.pluginRegistry = pluginRegistry; } - public static PluginManager create(Config config) + public static PluginManager create(final Config config) { final PluginRegistry pluginRegistry = new PluginRegistry(config); pluginRegistry.load(); @@ -29,7 +27,7 @@ public static PluginManager create(Config config) return new PluginManager(pluginRegistry); } - public List getAllFeatures(Class featureType) + public List getAllFeatures(final Class featureType) { return findPluginsSupporting(featureType).stream() .map(plugin -> plugin.getFeature(featureType)) @@ -38,10 +36,11 @@ public List getAllFeatures(Class featureType) .toList(); } - public List findPluginsSupporting(Class featureType) + public List findPluginsSupporting(final Class featureType) { return pluginRegistry.getAllPlugins().stream() .filter(plugin -> plugin.supports(featureType)) + .map(AppPlugin.class::cast) .toList(); } @@ -51,7 +50,7 @@ public Collection getAllPlugins() return pluginRegistry.getAllPlugins(); } - public Optional getUniqueFeature(Class featureType) + public Optional getUniqueFeature(final Class featureType) { final List plugins = findPluginsSupporting(featureType); if (plugins.isEmpty()) diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/CachingStorageImpl.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/CachingStorageImpl.java index 37039679..07fd629a 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/CachingStorageImpl.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/CachingStorageImpl.java @@ -1,7 +1,5 @@ package org.itsallcode.whiterabbit.logic.storage; -import static java.util.stream.Collectors.toList; - import java.time.LocalDate; import java.time.YearMonth; import java.util.List; diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/MonthCache.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/MonthCache.java index 758abbe0..f4d1a053 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/MonthCache.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/MonthCache.java @@ -1,7 +1,5 @@ package org.itsallcode.whiterabbit.logic.storage; -import static java.util.stream.Collectors.toList; - import java.time.LocalDate; import java.time.YearMonth; import java.util.ArrayList; diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/MonthIndexStorage.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/MonthIndexStorage.java index 99513670..709c9b90 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/MonthIndexStorage.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/MonthIndexStorage.java @@ -1,7 +1,5 @@ package org.itsallcode.whiterabbit.logic.storage; -import static java.util.stream.Collectors.toList; - import java.time.Duration; import java.time.YearMonth; import java.time.temporal.ChronoUnit; diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/data/JsonFileStorage.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/data/JsonFileStorage.java index c456c3fe..707c87da 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/data/JsonFileStorage.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/data/JsonFileStorage.java @@ -1,7 +1,6 @@ package org.itsallcode.whiterabbit.logic.storage.data; import static java.util.Comparator.comparing; -import static java.util.stream.Collectors.toList; import java.io.IOException; import java.io.InputStream; @@ -32,21 +31,22 @@ public class JsonFileStorage implements MonthDataStorage // Made protected in order to allow tests in other packages to mock this // class. - protected JsonFileStorage(Jsonb jsonb, DateToFileMapper dateToFileMapper, ModelFactory modelFactory) + protected JsonFileStorage(final Jsonb jsonb, final DateToFileMapper dateToFileMapper, + final ModelFactory modelFactory) { this.jsonb = jsonb; this.dateToFileMapper = dateToFileMapper; this.modelFactory = modelFactory; } - public static MonthDataStorage create(Path dataDir) + public static MonthDataStorage create(final Path dataDir) { final Jsonb jsonb = new JsonbFactory().create(); return new JsonFileStorage(jsonb, new DateToFileMapper(dataDir), new JsonModelFactory()); } @Override - public Optional load(YearMonth date) + public Optional load(final YearMonth date) { final Path file = dateToFileMapper.getPathForDate(date); if (file.toFile().exists()) @@ -66,7 +66,7 @@ public Optional load(YearMonth date) // Made protected in order to allow tests in other packages to mock this // class. - protected JsonMonth loadFromFile(Path file) + protected MonthData loadFromFile(final Path file) { LOG.trace("Reading file {}", file); try (InputStream stream = Files.newInputStream(file)) @@ -80,7 +80,7 @@ protected JsonMonth loadFromFile(Path file) } @Override - public void store(YearMonth yearMonth, MonthData monthRecord) + public void store(final YearMonth yearMonth, final MonthData monthRecord) { final Path file = dateToFileMapper.getPathForDate(yearMonth); LOG.trace("Write month {} to file {}", yearMonth, file); @@ -96,7 +96,7 @@ public void store(YearMonth yearMonth, MonthData monthRecord) } } - private void createDirectory(Path dir) + private void createDirectory(final Path dir) { if (dir.toFile().isDirectory()) { @@ -124,7 +124,7 @@ public List loadAll() return dateToFileMapper.getAllFiles() .filter(file -> !file.getFileName().toString().equals(Config.PROJECTS_JSON)) .map(this::loadFromFile) - .sorted(comparing(JsonMonth::getYear).thenComparing(JsonMonth::getMonth)) + .sorted(comparing(MonthData::getYear).thenComparing(MonthData::getMonth)) .toList(); } diff --git a/logic/src/test/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteServiceTest.java b/logic/src/test/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteServiceTest.java index 2aead783..e127eda4 100644 --- a/logic/src/test/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteServiceTest.java +++ b/logic/src/test/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteServiceTest.java @@ -1,10 +1,13 @@ package org.itsallcode.whiterabbit.logic.autocomplete; import static java.util.Arrays.asList; -import static java.util.stream.Collectors.toList; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.lenient; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.time.LocalDate; import java.time.Month; diff --git a/logic/src/test/java/org/itsallcode/whiterabbit/logic/report/vacation/VacationReportGeneratorTest.java b/logic/src/test/java/org/itsallcode/whiterabbit/logic/report/vacation/VacationReportGeneratorTest.java index ab07dce1..0d3ccb5c 100644 --- a/logic/src/test/java/org/itsallcode/whiterabbit/logic/report/vacation/VacationReportGeneratorTest.java +++ b/logic/src/test/java/org/itsallcode/whiterabbit/logic/report/vacation/VacationReportGeneratorTest.java @@ -1,7 +1,6 @@ package org.itsallcode.whiterabbit.logic.report.vacation; import static java.util.Arrays.asList; -import static java.util.stream.Collectors.toList; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -241,7 +240,7 @@ void monthlyReportTwoMonthsInDifferentYears() assertThat(secondMonth.getUsedVacationDayCount()).isEqualTo(1); } - private MonthIndex month(int year, Month month, LocalDate... vacationDays) + private MonthIndex month(final int year, final Month month, final LocalDate... vacationDays) { final MonthIndex monthData = mock(MonthIndex.class); when(monthData.getYearMonth()).thenReturn(YearMonth.of(year, month)); @@ -250,7 +249,7 @@ private MonthIndex month(int year, Month month, LocalDate... vacationDays) return monthData; } - private void simulateMonths(MonthIndex... months) + private void simulateMonths(final MonthIndex... months) { final List availableDataYearMonth = Arrays.stream(months).map(MonthIndex::getYearMonth) .toList(); From 8620692e71df6789d05f72ded2220133c0caa497 Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Wed, 1 May 2024 18:16:29 +0200 Subject: [PATCH 06/11] Don't catch Exception class --- .../whiterabbit/jfxui/JavaFxApp.java | 49 ++++++++++++------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java index 4e603002..32a4345c 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java @@ -2,7 +2,11 @@ import java.lang.ProcessHandle.Info; import java.nio.file.Paths; -import java.time.*; +import java.time.Clock; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalTime; +import java.time.YearMonth; import java.util.Arrays; import java.util.Optional; import java.util.concurrent.ScheduledExecutorService; @@ -17,8 +21,13 @@ import org.itsallcode.whiterabbit.jfxui.ui.AppUi; import org.itsallcode.whiterabbit.jfxui.ui.InterruptionDialog; import org.itsallcode.whiterabbit.jfxui.uistate.UiStateService; -import org.itsallcode.whiterabbit.logic.*; -import org.itsallcode.whiterabbit.logic.model.*; +import org.itsallcode.whiterabbit.logic.Config; +import org.itsallcode.whiterabbit.logic.ConfigLoader; +import org.itsallcode.whiterabbit.logic.DefaultWorkingDirProvider; +import org.itsallcode.whiterabbit.logic.WorkingDirProvider; +import org.itsallcode.whiterabbit.logic.model.Activity; +import org.itsallcode.whiterabbit.logic.model.DayRecord; +import org.itsallcode.whiterabbit.logic.model.MonthIndex; import org.itsallcode.whiterabbit.logic.service.AppService; import org.itsallcode.whiterabbit.logic.service.AppServiceCallback; import org.itsallcode.whiterabbit.logic.service.singleinstance.OtherInstance; @@ -56,7 +65,8 @@ public JavaFxApp() this(new DefaultWorkingDirProvider(), Clock.systemDefaultZone(), new ScheduledThreadPoolExecutor(1)); } - JavaFxApp(WorkingDirProvider workingDirProvider, Clock clock, ScheduledExecutorService executorService) + JavaFxApp(final WorkingDirProvider workingDirProvider, final Clock clock, + final ScheduledExecutorService executorService) { this.workingDirProvider = workingDirProvider; this.clock = clock; @@ -70,14 +80,14 @@ public void init() { doInitialize(); } - catch (final Exception e) + catch (final RuntimeException e) { stop(); throw e; } } - private void notifyPreloaderProgress(Type notificationType) + private void notifyPreloaderProgress(final Type notificationType) { notifyPreloader(new ProgressPreloaderNotification(this, notificationType)); } @@ -113,7 +123,7 @@ private Config loadConfig() } @Override - public void start(Stage primaryStage) + public void start(final Stage primaryStage) { this.primaryStage = primaryStage; state.setPrimaryStage(primaryStage); @@ -122,7 +132,7 @@ public void start(Stage primaryStage) notifyPreloaderProgress(Type.STARTUP_FINISHED); } - private void doStart(Stage primaryStage) + private void doStart(final Stage primaryStage) { this.ui = new AppUi.Builder(this, actions, appService, primaryStage, state).build(); @@ -193,7 +203,8 @@ private void startAppService() appService.start(); } - private void messageFromOtherInstanceReceived(String message, RunningInstanceCallback.ClientConnection client) + private void messageFromOtherInstanceReceived(final String message, + final RunningInstanceCallback.ClientConnection client) { if (MESSAGE_BRING_TO_FRONT.equals(message)) { @@ -268,15 +279,15 @@ public void startManualInterruption() private final class AppServiceCallbackImplementation implements AppServiceCallback { @Override - public InterruptionDetectedDecision automaticInterruptionDetected(LocalTime startOfInterruption, - Duration interruption) + public InterruptionDetectedDecision automaticInterruptionDetected(final LocalTime startOfInterruption, + final Duration interruption) { return JavaFxUtil .runOnFxApplicationThread(() -> showAutomaticInterruptionDialog(startOfInterruption, interruption)); } - private InterruptionDetectedDecision showAutomaticInterruptionDialog(LocalTime startOfInterruption, - Duration interruption) + private InterruptionDetectedDecision showAutomaticInterruptionDialog(final LocalTime startOfInterruption, + final Duration interruption) { final Alert alert = createAlertDialog(startOfInterruption, interruption); LOG.info("Showing automatic interruption alert starting at {} for {}...", startOfInterruption, @@ -287,7 +298,7 @@ private InterruptionDetectedDecision showAutomaticInterruptionDialog(LocalTime s return decision; } - private Alert createAlertDialog(LocalTime startOfInterruption, Duration interruption) + private Alert createAlertDialog(final LocalTime startOfInterruption, final Duration interruption) { final Alert alert = new Alert(AlertType.CONFIRMATION); alert.setTitle("Interruption detected"); @@ -315,7 +326,7 @@ private InterruptionDetectedDecision evaluateButton(final Optional s return InterruptionDetectedDecision.SKIP_INTERRUPTION; } - private boolean isButton(Optional button, ButtonData data) + private boolean isButton(final Optional button, final ButtonData data) { return button.map(ButtonType::getButtonData) .filter(d -> d == data) @@ -323,7 +334,7 @@ private boolean isButton(Optional button, ButtonData data) } @Override - public void recordUpdated(DayRecord day) + public void recordUpdated(final DayRecord day) { final YearMonth month = YearMonth.from(day.getDate()); JavaFxUtil.runOnFxApplicationThread(() -> { @@ -339,14 +350,14 @@ public void recordUpdated(DayRecord day) }); } - private boolean daySelected(DayRecord dayRecord) + private boolean daySelected(final DayRecord dayRecord) { final Optional selectedDay = state.getSelectedDay(); return selectedDay.isPresent() && selectedDay.get().getDate().equals(dayRecord.getDate()); } @Override - public void exceptionOccurred(Exception e) + public void exceptionOccurred(final Exception e) { final String message = "An error occured: " + e.getClass() + ": " + e.getMessage(); LOG.error(message, e); @@ -354,7 +365,7 @@ public void exceptionOccurred(Exception e) } @Override - public void workStoppedForToday(boolean stopWorking) + public void workStoppedForToday(final boolean stopWorking) { JavaFxUtil.runOnFxApplicationThread(() -> state.stoppedWorkingForToday.setValue(stopWorking)); } From bacc130af28c9431fc9de9daa1bcc513ea05ad50 Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Wed, 1 May 2024 19:04:39 +0200 Subject: [PATCH 07/11] Fix sonar warnings --- .../whiterabbit/jfxui/JavaFxApp.java | 19 +++++------ .../feature/InterruptionPresetFeature.java | 5 +-- .../jfxui/table/days/DayRecordTable.java | 18 +++++++--- .../jfxui/ui/DailyProjectReportViewer.java | 4 +-- .../whiterabbit/jfxui/ui/MenuBarBuilder.java | 8 ++--- .../jfxui/ui/PluginManagerViewer.java | 4 +-- .../jfxui/ui/YearlyProjectReportViewer.java | 2 +- .../ui/widget/AutoCompleteTextField.java | 2 +- .../jfxui/JavaFxAppUiTestBase.java | 8 ++--- .../autocomplete/AutocompleteService.java | 25 ++++++++------ .../logic/autocomplete/TextIndex.java | 33 ++++++++++++------- .../whiterabbit/logic/model/MonthIndex.java | 16 +++++---- .../project/ProjectReportGenerator.java | 6 ++-- .../whiterabbit/logic/service/AppService.java | 3 +- .../logic/service/plugin/AppPluginImpl.java | 16 ++++----- .../logic/service/plugin/PluginRegistry.java | 2 +- .../logic/storage/data/JsonFileStorage.java | 2 +- .../autocomplete/AutocompleteServiceTest.java | 3 +- .../logic/autocomplete/TextIndexTest.java | 9 ++--- 19 files changed, 105 insertions(+), 80 deletions(-) diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java index 32a4345c..8ced575b 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java @@ -293,7 +293,7 @@ private InterruptionDetectedDecision showAutomaticInterruptionDialog(final Local LOG.info("Showing automatic interruption alert starting at {} for {}...", startOfInterruption, interruption); final Optional selectedButton = alert.showAndWait(); - final InterruptionDetectedDecision decision = evaluateButton(selectedButton); + final InterruptionDetectedDecision decision = evaluateButton(selectedButton.orElse(null)); LOG.info("User clicked button {} -> {}", selectedButton, decision); return decision; } @@ -313,26 +313,23 @@ private Alert createAlertDialog(final LocalTime startOfInterruption, final Durat return alert; } - private InterruptionDetectedDecision evaluateButton(final Optional selectedButton) + private InterruptionDetectedDecision evaluateButton(final ButtonType selectedButton) { - if (isButton(selectedButton, ButtonData.FINISH) && !state.stoppedWorkingForToday.get()) + if (selectedButton == null) + { + return InterruptionDetectedDecision.SKIP_INTERRUPTION; + } + if (selectedButton.getButtonData() == ButtonData.FINISH && !state.stoppedWorkingForToday.get()) { return InterruptionDetectedDecision.STOP_WORKING_FOR_TODAY; } - if (isButton(selectedButton, ButtonData.YES)) + if (selectedButton.getButtonData() == ButtonData.YES) { return InterruptionDetectedDecision.ADD_INTERRUPTION; } return InterruptionDetectedDecision.SKIP_INTERRUPTION; } - private boolean isButton(final Optional button, final ButtonData data) - { - return button.map(ButtonType::getButtonData) - .filter(d -> d == data) - .isPresent(); - } - @Override public void recordUpdated(final DayRecord day) { diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java index 17f2df89..e58e8163 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java @@ -4,6 +4,7 @@ import java.text.ParsePosition; import java.time.Duration; import java.util.List; +import java.util.Locale; import java.util.function.UnaryOperator; import org.itsallcode.whiterabbit.logic.service.AppService; @@ -65,7 +66,7 @@ private MenuItem createMenuitem(final Duration interruption) final String verb = interruption.isNegative() ? "Subtract" : "Add"; final MenuItem menuItem = new MenuItem( verb + " interruption of " + appService.formatter().format(interruption.abs())); - menuItem.setId(verb.toLowerCase() + "-interruption-preset-" + interruption.toString()); + menuItem.setId(verb.toLowerCase(Locale.ENGLISH) + "-interruption-preset-" + interruption.toString()); menuItem.setOnAction(event -> addInterruptionForToday(interruption)); return menuItem; } @@ -83,7 +84,6 @@ private static class DurationInputDialog extends Dialog private DurationInputDialog() { - final DialogPane dialogPane = getDialogPane(); final int maxValue = (int) Duration.ofHours(8).toMinutes(); spinner = new Spinner<>(0, maxValue, 0, 5); @@ -117,6 +117,7 @@ private DurationInputDialog() GridPane.setHgrow(spinner, Priority.ALWAYS); GridPane.setFillWidth(spinner, true); + final DialogPane dialogPane = getDialogPane(); label = createContentLabel(dialogPane.getContentText()); label.setPrefWidth(Region.USE_COMPUTED_SIZE); label.textProperty().bind(dialogPane.contentTextProperty()); diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java index 67f70754..d7c9ace7 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java @@ -103,14 +103,11 @@ private void updateRows(final List sortedDays) private void updateSelectedRow(final MonthIndex previousMonth, final MonthIndex month) { - final boolean isCurrentMonth = month.getYearMonth().equals(clockService.getCurrentYearMonth()); - final boolean otherMonthSelected = previousMonth != null - && !month.getYearMonth().equals(previousMonth.getYearMonth()); - if (!otherMonthSelected) + if (!otherMonthSelected(previousMonth, month)) { return; } - if (isCurrentMonth) + if (isCurrentMonth(month)) { selectRow(clockService.getCurrentDate()); } @@ -120,6 +117,17 @@ private void updateSelectedRow(final MonthIndex previousMonth, final MonthIndex } } + private boolean otherMonthSelected(final MonthIndex previousMonth, final MonthIndex month) + { + return previousMonth != null + && !month.getYearMonth().equals(previousMonth.getYearMonth()); + } + + private boolean isCurrentMonth(final MonthIndex month) + { + return month.getYearMonth().equals(clockService.getCurrentYearMonth()); + } + @SuppressWarnings("java:S110") // Deep inheritance tree required by JavaFx public TableView initTable() { diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/DailyProjectReportViewer.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/DailyProjectReportViewer.java index 0b150589..57a2fa1c 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/DailyProjectReportViewer.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/DailyProjectReportViewer.java @@ -103,7 +103,7 @@ private TreeTableView createTreeTable() final TreeItem root = new TreeItem<>(); root.getChildren().addAll(report.getDays().stream() - .map(this::createDayTreeItem) + .map(DailyProjectReportViewer::createDayTreeItem) .toList()); final TreeTableView treeTable = new TreeTableView<>(root); @@ -125,7 +125,7 @@ private TreeTableView createTreeTable() return treeTable; } - private TreeItem createDayTreeItem(final ProjectReportDay day) + private static TreeItem createDayTreeItem(final ProjectReportDay day) { final TreeItem treeItem = new TreeItem<>(new ReportRow(day)); treeItem.setExpanded(true); diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/MenuBarBuilder.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/MenuBarBuilder.java index 9774befb..211f273a 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/MenuBarBuilder.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/MenuBarBuilder.java @@ -68,12 +68,12 @@ public MenuBar build() return menuBar; } - private SeparatorMenuItem separatorItem() + private static SeparatorMenuItem separatorItem() { return new SeparatorMenuItem(); } - private Menu menu(final String label, final String id) + private static Menu menu(final String label, final String id) { final Menu menu = new Menu(label); menu.setId(id); @@ -91,12 +91,12 @@ private MenuItem createStopWorkingForTodayMenuItem() return menuItem; } - private MenuItem menuItem(final String label, final String id, final Runnable action) + private static MenuItem menuItem(final String label, final String id, final Runnable action) { return menuItem(label, id, event -> action.run()); } - private MenuItem menuItem(final String label, final String id, final EventHandler action) + private static MenuItem menuItem(final String label, final String id, final EventHandler action) { final MenuItem menuItem = new MenuItem(label); menuItem.setId(id); diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/PluginManagerViewer.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/PluginManagerViewer.java index de5e5346..52fa0ce0 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/PluginManagerViewer.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/PluginManagerViewer.java @@ -64,11 +64,11 @@ private TableView createTableView() private List getAllPlugins() { return pluginManager.getAllPlugins().stream() - .map(this::createTableEntry) + .map(PluginManagerViewer::createTableEntry) .toList(); } - private PluginTableEntry createTableEntry(final AppPlugin plugin) + private static PluginTableEntry createTableEntry(final AppPlugin plugin) { return new PluginTableEntry(plugin); } diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java index df0e827e..70369595 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java @@ -66,7 +66,7 @@ private TableView createTreeTable() return treeTable; } - private ReportRow createRow(final int year, final ProjectReportActivity project) + private static ReportRow createRow(final int year, final ProjectReportActivity project) { return new ReportRow(year, project); } diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/widget/AutoCompleteTextField.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/widget/AutoCompleteTextField.java index 6b27728a..a5fb7b08 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/widget/AutoCompleteTextField.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/widget/AutoCompleteTextField.java @@ -87,7 +87,7 @@ private MenuItem createMenuItem(final AutocompleteProposal result) return item; } - private List highlightMatch(final AutocompleteProposal result) + private static List highlightMatch(final AutocompleteProposal result) { final int matchPositionStart = result.getMatchPositionStart(); final List textParts = new ArrayList<>(); diff --git a/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/JavaFxAppUiTestBase.java b/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/JavaFxAppUiTestBase.java index 46cca8fd..2e6ee675 100644 --- a/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/JavaFxAppUiTestBase.java +++ b/jfxui/src/uiTest/java/org/itsallcode/whiterabbit/jfxui/JavaFxAppUiTestBase.java @@ -92,7 +92,7 @@ public void setCommandLineArgs(final List commandLineArgs) protected void doStart(final Stage stage, final ProjectConfig projectConfig) { - LOG.info("Starting application using stage {}", stage); + LOG.debug("Starting application using stage {}", stage); timeUtil = TimeUtil.start(initialTime); final TestDirProvider testDirProvider = TestDirProvider.create(tempDir); @@ -107,14 +107,14 @@ protected void doStart(final Stage stage, final ProjectConfig projectConfig) this.javaFxApp.start(stage); timeUtil.captureScheduledRunnables(); - LOG.info("Application startup finished"); + LOG.debug("Application startup finished"); } protected void doStop() { - LOG.info("Preparing application shutdown"); + LOG.debug("Preparing application shutdown"); this.javaFxApp.prepareShutdown(); - LOG.info("Application shutdown done"); + LOG.debug("Application shutdown done"); } private void prepareConfiguration(final ProjectConfig projectConfig, final WorkingDirProvider testDirProvider) diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteService.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteService.java index 995d89b7..049fa452 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteService.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteService.java @@ -1,11 +1,13 @@ package org.itsallcode.whiterabbit.logic.autocomplete; import static java.util.function.Function.identity; -import static java.util.stream.Collectors.*; +import static java.util.stream.Collectors.counting; +import static java.util.stream.Collectors.groupingBy; import java.time.LocalDate; import java.time.Period; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -30,15 +32,16 @@ public class AutocompleteService private final CachingStorage storage; private final ClockService clockService; - private final CachingAutocompleter dayCommentAutocompleter = new CachingAutocompleter(this::getDayComments); - private final CachingAutocompleter activityCommentAutocompleter = new CachingAutocompleter( - this::getActivityComments); + private final CachingAutocompleter dayCommentAutocompleter; + private final CachingAutocompleter activityCommentAutocompleter; - public AutocompleteService(final CachingStorage storage, final ClockService clockService) + public AutocompleteService(final CachingStorage storage, final ClockService clockService, final Locale locale) { - this.storage = storage; this.clockService = clockService; - storage.addCacheInvalidationListener(this::invalidateCache); + this.dayCommentAutocompleter = new CachingAutocompleter(this::getDayComments, locale); + this.activityCommentAutocompleter = new CachingAutocompleter(this::getActivityComments, locale); + this.storage = storage; + this.storage.addCacheInvalidationListener(this::invalidateCache); } private void invalidateCache(final MonthIndex updatedMonth) @@ -108,14 +111,16 @@ public Optional getSuggestedProject() return mostFrequentlyUsedProject; } - private class CachingAutocompleter implements AutocompleteEntrySupplier + private static class CachingAutocompleter implements AutocompleteEntrySupplier { private TextIndex index; private final Supplier> availableTextSupplier; + private final Locale locale; - private CachingAutocompleter(final Supplier> availableTextSupplier) + private CachingAutocompleter(final Supplier> availableTextSupplier, final Locale locale) { this.availableTextSupplier = availableTextSupplier; + this.locale = locale; } private void invalidateCache() @@ -128,7 +133,7 @@ public List getEntries(final String prompt) { if (index == null) { - index = TextIndex.build(availableTextSupplier.get()); + index = TextIndex.build(availableTextSupplier.get(), locale); } return index.getEntries(prompt); } diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/TextIndex.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/TextIndex.java index b174a7f8..e7afaa86 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/TextIndex.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/TextIndex.java @@ -5,7 +5,9 @@ import static java.util.stream.Collectors.groupingBy; import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.SortedSet; import java.util.TreeSet; @@ -21,28 +23,35 @@ class TextIndex implements AutocompleteEntrySupplier private final Map> lowerCaseIndex; private final SortedSet lowerCaseValues; private final Map lowerCaseFrequency; + private final Locale locale; private TextIndex(final Map> lowerCaseIndex, final SortedSet lowerCaseValues, - final Map lowerCaseFrequency) + final Map lowerCaseFrequency, final Locale locale) { - this.lowerCaseIndex = lowerCaseIndex; - this.lowerCaseValues = lowerCaseValues; - this.lowerCaseFrequency = lowerCaseFrequency; + this.lowerCaseIndex = new HashMap<>(lowerCaseIndex); + this.lowerCaseValues = new TreeSet<>(lowerCaseValues); + this.lowerCaseFrequency = new HashMap<>(lowerCaseFrequency); + this.locale = locale; } - static TextIndex build(final Collection entries) + static TextIndex build(final Collection entries, final Locale locale) { final List uniqueEntries = entries.stream().distinct().toList(); final Map> lowerCaseIndex = uniqueEntries.stream() - .collect(groupingBy(String::toLowerCase)); + .collect(groupingBy(value -> value.toLowerCase(locale))); final SortedSet lowerCaseValues = new TreeSet<>(lowerCaseIndex.keySet()); - final Map lowerCaseFrequency = entries.stream().map(String::toLowerCase) + final Map lowerCaseFrequency = entries.stream().map(value -> value.toLowerCase(locale)) .collect(groupingBy(identity(), counting())); LOG.trace("Creating autocompleter for {} entries ({} unique): {}, frequencies: {}", entries.size(), uniqueEntries.size(), uniqueEntries, lowerCaseFrequency); - return new TextIndex(lowerCaseIndex, lowerCaseValues, lowerCaseFrequency); + return new TextIndex(lowerCaseIndex, lowerCaseValues, lowerCaseFrequency, locale); + } + + private String toLowerCase(final String value) + { + return value.toLowerCase(locale); } @Override @@ -56,8 +65,8 @@ public List getEntries(final String searchText) { return createProposals(lowerCaseValues, searchText); } - final SortedSet lowerCaseMatches = lowerCaseValues.subSet(searchText.toLowerCase(), - searchText.toLowerCase() + Character.MAX_VALUE); + final SortedSet lowerCaseMatches = lowerCaseValues.subSet(toLowerCase(searchText), + toLowerCase(searchText) + Character.MAX_VALUE); return createProposals(lowerCaseMatches, searchText); } @@ -75,8 +84,8 @@ private List createProposals(final SortedSet lower 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); + final int matchPositionStart = toLowerCase(proposedText).indexOf(toLowerCase(searchText)); + final long priority = lowerCaseFrequency.getOrDefault(toLowerCase(proposedText), 0L); LOG.trace("Create proposal for '{}'. Proposal: {}, priority: {}", searchText, proposedText, priority); return new AutocompleteProposal(proposedText, priority, matchPositionStart, searchText.length()); } diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/MonthIndex.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/MonthIndex.java index 641da110..fc23f216 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/MonthIndex.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/MonthIndex.java @@ -27,15 +27,16 @@ public class MonthIndex private final MonthData monthRecord; private final Map days; - private MonthIndex(ModelFactory modelFactory, MonthData monthRecord, Map days) + private MonthIndex(final ModelFactory modelFactory, final MonthData monthRecord, + final Map days) { this.modelFactory = Objects.requireNonNull(modelFactory, "modelFactory"); this.monthRecord = monthRecord; this.days = days; } - public static MonthIndex create(ContractTermsService contractTerms, ProjectService projectService, - ModelFactory modelFactory, MonthData monthRecord) + public static MonthIndex create(final ContractTermsService contractTerms, final ProjectService projectService, + final ModelFactory modelFactory, final MonthData monthRecord) { final Map jsonDays = monthRecord.getDays().stream() .collect(toMap(DayData::getDate, Function.identity())); @@ -58,7 +59,8 @@ public static MonthIndex create(ContractTermsService contractTerms, ProjectServi return monthIndex; } - private static DayData createDummyDay(LocalDate date, ContractTermsService contractTerms, ModelFactory modelFactory) + private static DayData createDummyDay(final LocalDate date, final ContractTermsService contractTerms, + final ModelFactory modelFactory) { final DayData day = modelFactory.createDayData(); day.setDate(date); @@ -75,12 +77,12 @@ public YearMonth getYearMonth() return YearMonth.of(monthRecord.getYear(), monthRecord.getMonth()); } - public DayRecord getDay(LocalDate date) + public DayRecord getDay(final LocalDate date) { return days.get(date); } - public void put(DayRecord day) + public void put(final DayRecord day) { this.days.put(day.getDate(), day); } @@ -111,7 +113,7 @@ public Stream getSortedDays() .sorted(Comparator.comparing(DayRecord::getDate)); } - public void setOvertimePreviousMonth(Duration overtimePreviousMonth) + public void setOvertimePreviousMonth(final Duration overtimePreviousMonth) { monthRecord.setOvertimePreviousMonth(overtimePreviousMonth); } diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java index 74a8d063..2a09947e 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java @@ -40,7 +40,7 @@ public ProjectReport generateReport(final YearMonth month) .filter(activity -> activity.getProject() != null) .collect(groupingBy(Activity::getProject)) .values().stream() - .map(this::aggregateProject) + .map(ProjectReportGenerator::aggregateProject) .toList(); return new ProjectReportImpl(month, reportDays, reportProjects); @@ -53,7 +53,7 @@ private ProjectReportDay generateDayReport(final DayRecord dayRecord) .filter(activity -> activity.getProject() != null) .collect(groupingBy(this::activityProject)) .values().stream() - .map(this::aggregateProject) + .map(ProjectReportGenerator::aggregateProject) .toList(); return new DayImpl(dayRecord.getDate(), dayRecord.getType(), dayRecord.getComment(), projects); @@ -64,7 +64,7 @@ private String activityProject(final Activity activity) return activity.getProject().getProjectId(); } - private ProjectReportActivity aggregateProject(final List projectActivites) + private static ProjectReportActivity aggregateProject(final List projectActivites) { final Duration totalWorkingTime = projectActivites.stream() .filter(activity -> activity.getDuration() != null) diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/AppService.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/AppService.java index 53a8ab89..561a30a7 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/AppService.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/AppService.java @@ -109,7 +109,8 @@ public static AppService create(final Config config, final Clock clock, projectService, holidayService); final ClockService clockService = new ClockService(clock); - final AutocompleteService autocompleteService = new AutocompleteService(storage, clockService); + final AutocompleteService autocompleteService = new AutocompleteService(storage, clockService, + config.getLocale()); final SchedulingService schedulingService = new SchedulingService(clockService, scheduledExecutor); final DelegatingAppServiceCallback appServiceCallback = new DelegatingAppServiceCallback(); final WorkingTimeService workingTimeService = new WorkingTimeService(storage, clockService, appServiceCallback); diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/AppPluginImpl.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/AppPluginImpl.java index eb38ce11..9483a5e4 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/AppPluginImpl.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/AppPluginImpl.java @@ -20,14 +20,14 @@ class AppPluginImpl implements AppPlugin private final Plugin plugin; private final Config config; - private AppPluginImpl(Config config, AppPluginOrigin origin, Plugin plugin) + private AppPluginImpl(final Config config, final AppPluginOrigin origin, final Plugin plugin) { this.config = config; this.origin = origin; this.plugin = plugin; } - public static AppPluginImpl create(Config config, AppPluginOrigin origin, Plugin plugin) + public static AppPluginImpl create(final Config config, final AppPluginOrigin origin, final Plugin plugin) { return new AppPluginImpl(config, origin, plugin); } @@ -57,20 +57,20 @@ public AppPluginOrigin getOrigin() return origin; } - public boolean supports(Class featureType) + public boolean supports(final Class featureType) { try { return plugin.supports(featureType); } - catch (final Exception e) + catch (final RuntimeException e) { LOG.warn("Error loading plugin '{}'", getId(), e); return false; } } - public Optional getFeature(Class featureType) + public Optional getFeature(final Class featureType) { return plugin.getFeature(featureType); } @@ -93,19 +93,19 @@ public String toString() private class PluginConfigImpl implements PluginConfiguration { - private String prefixed(String key) + private String prefixed(final String key) { return plugin.getId() + "." + key; } @Override - public String getMandatoryValue(String key) + public String getMandatoryValue(final String key) { return config.getMandatoryValue(prefixed(key)); } @Override - public Optional getOptionalValue(String key) + public Optional getOptionalValue(final String key) { return config.getOptionalValue(prefixed(key)); } diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/PluginRegistry.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/PluginRegistry.java index cc035771..e13cf8c6 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/PluginRegistry.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/PluginRegistry.java @@ -48,7 +48,7 @@ private Map loadPlugins() .collect(toMap(AppPluginImpl::getId, Function.identity(), preferExternalJars())); } - private BinaryOperator preferExternalJars() + private static BinaryOperator preferExternalJars() { return (a, b) -> { LOG.warn("Found two plugins with same ID '{}':\n- {}\n- {}", a.getId(), a, b); diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/data/JsonFileStorage.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/data/JsonFileStorage.java index 707c87da..d9c3f227 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/data/JsonFileStorage.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/storage/data/JsonFileStorage.java @@ -96,7 +96,7 @@ public void store(final YearMonth yearMonth, final MonthData monthRecord) } } - private void createDirectory(final Path dir) + private static void createDirectory(final Path dir) { if (dir.toFile().isDirectory()) { diff --git a/logic/src/test/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteServiceTest.java b/logic/src/test/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteServiceTest.java index e127eda4..b3bc99e9 100644 --- a/logic/src/test/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteServiceTest.java +++ b/logic/src/test/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteServiceTest.java @@ -14,6 +14,7 @@ import java.time.Period; import java.util.Arrays; import java.util.List; +import java.util.Locale; import java.util.Optional; import org.itsallcode.whiterabbit.logic.model.Activity; @@ -43,7 +44,7 @@ class AutocompleteServiceTest @BeforeEach void setUp() { - autocompleteService = new AutocompleteService(storageMock, clockServiceMock); + autocompleteService = new AutocompleteService(storageMock, clockServiceMock, Locale.ENGLISH); } @Test diff --git a/logic/src/test/java/org/itsallcode/whiterabbit/logic/autocomplete/TextIndexTest.java b/logic/src/test/java/org/itsallcode/whiterabbit/logic/autocomplete/TextIndexTest.java index b2b1364e..e9a175df 100644 --- a/logic/src/test/java/org/itsallcode/whiterabbit/logic/autocomplete/TextIndexTest.java +++ b/logic/src/test/java/org/itsallcode/whiterabbit/logic/autocomplete/TextIndexTest.java @@ -3,6 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.List; +import java.util.Locale; import java.util.stream.Stream; import org.junit.jupiter.api.extension.ExtensionContext; @@ -13,12 +14,12 @@ class TextIndexTest { - @ParameterizedTest(name = "[{index}] available values {0}, search text ''{1}''") @ArgumentsSource(AutocompleterArgumentsProvider.class) - void autocompleter(List availableEntries, String searchText, List expectedResult) + void autocompleter(final List availableEntries, final String searchText, final List expectedResult) { - final List entries = TextIndex.build(availableEntries).getEntries(searchText); + final List entries = TextIndex.build(availableEntries, Locale.ENGLISH) + .getEntries(searchText); assertThat(entries) .as("autocomplete for available values " + availableEntries + " and search text '" + searchText + "'") .extracting(AutocompleteProposal::getText) @@ -28,7 +29,7 @@ void autocompleter(List availableEntries, String searchText, List provideArguments(ExtensionContext context) + public Stream provideArguments(final ExtensionContext context) { return Stream.of( Arguments.of(List.of(), "text", List.of()), From 3d9c6195c6c2a59477be95d59f1c4c08fdc8793d Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Wed, 1 May 2024 19:22:12 +0200 Subject: [PATCH 08/11] Fix sonar warnings --- .../jfxui/table/days/DayRecordTable.java | 2 +- .../jfxui/ui/YearlyProjectReportViewer.java | 2 +- .../autocomplete/AutocompleteService.java | 2 +- .../logic/autocomplete/TextIndex.java | 2 +- .../logic/model/DayActivities.java | 1 + .../whiterabbit/logic/model/MonthIndex.java | 3 +- .../project/ProjectReportGenerator.java | 102 +++++++++--------- .../logic/service/plugin/AppPluginImpl.java | 3 +- 8 files changed, 60 insertions(+), 57 deletions(-) diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java index d7c9ace7..94ef3ac1 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java @@ -117,7 +117,7 @@ private void updateSelectedRow(final MonthIndex previousMonth, final MonthIndex } } - private boolean otherMonthSelected(final MonthIndex previousMonth, final MonthIndex month) + private static boolean otherMonthSelected(final MonthIndex previousMonth, final MonthIndex month) { return previousMonth != null && !month.getYearMonth().equals(previousMonth.getYearMonth()); diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java index 70369595..86d7c4af 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java @@ -71,7 +71,7 @@ private static ReportRow createRow(final int year, final ProjectReportActivity p return new ReportRow(year, project); } - public static class ReportRow + public final static class ReportRow { private final int year; private final ProjectReportActivity project; diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteService.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteService.java index 049fa452..b0372887 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteService.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/AutocompleteService.java @@ -111,7 +111,7 @@ public Optional getSuggestedProject() return mostFrequentlyUsedProject; } - private static class CachingAutocompleter implements AutocompleteEntrySupplier + private static final class CachingAutocompleter implements AutocompleteEntrySupplier { private TextIndex index; private final Supplier> availableTextSupplier; diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/TextIndex.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/TextIndex.java index e7afaa86..26574b4e 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/TextIndex.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/autocomplete/TextIndex.java @@ -15,7 +15,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -class TextIndex implements AutocompleteEntrySupplier +final class TextIndex implements AutocompleteEntrySupplier { private static final Logger LOG = LogManager.getLogger(TextIndex.class); private static final int MAX_RESULTS = 10; diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/DayActivities.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/DayActivities.java index 59c9a93f..f72c318d 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/DayActivities.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/DayActivities.java @@ -136,6 +136,7 @@ private Duration getUnallocatedDuration() return dayRecord.getWorkingTime().minus(allocatedDuration); } + @SuppressWarnings("java:S1142") // More than 3 returns required for logging public boolean isValidAllocation() { final List remainderActivities = getActivities() diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/MonthIndex.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/MonthIndex.java index fc23f216..4b98c25c 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/MonthIndex.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/model/MonthIndex.java @@ -21,12 +21,13 @@ import org.itsallcode.whiterabbit.logic.service.contract.ContractTermsService; import org.itsallcode.whiterabbit.logic.service.project.ProjectService; -public class MonthIndex +public final class MonthIndex { private final ModelFactory modelFactory; private final MonthData monthRecord; private final Map days; + @SuppressWarnings("java:S2384") // Storing a copy of "days" is required here private MonthIndex(final ModelFactory modelFactory, final MonthData monthRecord, final Map days) { diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java index 2a09947e..7138ddd1 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java @@ -19,64 +19,64 @@ public class ProjectReportGenerator { - private final Storage storage; + private final Storage storage; - public ProjectReportGenerator(final Storage storage) - { - this.storage = storage; - } + public ProjectReportGenerator(final Storage storage) + { + this.storage = storage; + } - public ProjectReport generateReport(final YearMonth month) - { - final List sortedDays = storage.loadMonth(month) - .map(MonthIndex::getSortedDays).orElse(Stream.empty()).toList(); + public ProjectReport generateReport(final YearMonth month) + { + final List sortedDays = storage.loadMonth(month) + .map(MonthIndex::getSortedDays).orElse(Stream.empty()).toList(); - final List reportDays = sortedDays.stream() - .map(this::generateDayReport) - .toList(); + final List reportDays = sortedDays.stream() + .map(this::generateDayReport) + .toList(); - final List reportProjects = sortedDays.stream() - .flatMap(day -> day.activities().getAll().stream()) - .filter(activity -> activity.getProject() != null) - .collect(groupingBy(Activity::getProject)) - .values().stream() - .map(ProjectReportGenerator::aggregateProject) - .toList(); + final List reportProjects = sortedDays.stream() + .flatMap(day -> day.activities().getAll().stream()) + .filter(activity -> activity.getProject() != null) + .collect(groupingBy(Activity::getProject)) + .values().stream() + .map(ProjectReportGenerator::aggregateProject) + .toList(); - return new ProjectReportImpl(month, reportDays, reportProjects); - } + return new ProjectReportImpl(month, reportDays, reportProjects); + } - private ProjectReportDay generateDayReport(final DayRecord dayRecord) - { - final List projects = dayRecord.activities() - .getAll().stream() - .filter(activity -> activity.getProject() != null) - .collect(groupingBy(this::activityProject)) - .values().stream() - .map(ProjectReportGenerator::aggregateProject) - .toList(); + private ProjectReportDay generateDayReport(final DayRecord dayRecord) + { + final List projects = dayRecord.activities() + .getAll().stream() + .filter(activity -> activity.getProject() != null) + .collect(groupingBy(this::activityProject)) + .values().stream() + .map(ProjectReportGenerator::aggregateProject) + .toList(); - return new DayImpl(dayRecord.getDate(), dayRecord.getType(), dayRecord.getComment(), projects); - } + return new DayImpl(dayRecord.getDate(), dayRecord.getType(), dayRecord.getComment(), projects); + } - private String activityProject(final Activity activity) - { - return activity.getProject().getProjectId(); - } + private String activityProject(final Activity activity) + { + return activity.getProject().getProjectId(); + } - private static ProjectReportActivity aggregateProject(final List projectActivites) - { - final Duration totalWorkingTime = projectActivites.stream() - .filter(activity -> activity.getDuration() != null) - .map(Activity::getDuration).reduce(Duration::plus) - .orElse(Duration.ZERO); - final List comments = projectActivites.stream() - .map(Activity::getComment) - .filter(Objects::nonNull) - .filter(comment -> !comment.isBlank()) - .distinct() - .toList(); - return new ProjectReportImpl.ProjectActivityImpl(projectActivites.get(0).getProject(), totalWorkingTime, - comments); - } + private static ProjectReportActivity aggregateProject(final List projectActivites) + { + final Duration totalWorkingTime = projectActivites.stream() + .filter(activity -> activity.getDuration() != null) + .map(Activity::getDuration).reduce(Duration::plus) + .orElse(Duration.ZERO); + final List comments = projectActivites.stream() + .map(Activity::getComment) + .filter(Objects::nonNull) + .filter(comment -> !comment.isBlank()) + .distinct() + .toList(); + return new ProjectReportImpl.ProjectActivityImpl(projectActivites.get(0).getProject(), totalWorkingTime, + comments); + } } diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/AppPluginImpl.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/AppPluginImpl.java index 9483a5e4..7c46f98d 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/AppPluginImpl.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/service/plugin/AppPluginImpl.java @@ -12,7 +12,7 @@ import org.itsallcode.whiterabbit.api.features.PluginFeature; import org.itsallcode.whiterabbit.logic.Config; -class AppPluginImpl implements AppPlugin +final class AppPluginImpl implements AppPlugin { private static final Logger LOG = LogManager.getLogger(AppPluginImpl.class); @@ -70,6 +70,7 @@ public boolean supports(final Class featureType) } } + @Override public Optional getFeature(final Class featureType) { return plugin.getFeature(featureType); From f57522878f645b63caaa4e4c62cca859dfe717fa Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Sat, 4 May 2024 12:51:34 +0200 Subject: [PATCH 09/11] Fix sonar warnings --- .../whiterabbit/jfxui/JavaFxApp.java | 23 +++---- .../feature/InterruptionPresetFeature.java | 51 +++++++++------- .../jfxui/table/days/DayRecordTable.java | 61 +++++++++++-------- .../jfxui/ui/DailyProjectReportViewer.java | 2 +- .../jfxui/ui/YearlyProjectReportViewer.java | 2 +- .../project/ProjectReportGenerator.java | 4 +- 6 files changed, 81 insertions(+), 62 deletions(-) diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java index 8ced575b..41e2a3d3 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/JavaFxApp.java @@ -229,12 +229,10 @@ public void bringWindowToFront() Platform.runLater(() -> { if (primaryStage.isShowing()) { - LOG.debug("Request focus"); primaryStage.requestFocus(); } else { - LOG.debug("Show primary stage"); primaryStage.show(); } }); @@ -334,17 +332,20 @@ private InterruptionDetectedDecision evaluateButton(final ButtonType selectedBut public void recordUpdated(final DayRecord day) { final YearMonth month = YearMonth.from(day.getDate()); - JavaFxUtil.runOnFxApplicationThread(() -> { - ensureMonthAvailable(month); - if (state.currentMonth.get().getYearMonth().equals(month)) + JavaFxUtil.runOnFxApplicationThread(() -> recordUpdated(day, month)); + } + + private void recordUpdated(final DayRecord day, final YearMonth month) + { + ensureMonthAvailable(month); + if (state.currentMonth.get().getYearMonth().equals(month)) + { + state.currentMonth.setValue(day.getMonth()); + if (daySelected(day)) { - state.currentMonth.setValue(day.getMonth()); - if (daySelected(day)) - { - ui.updateActivities(day); - } + ui.updateActivities(day); } - }); + } } private boolean daySelected(final DayRecord dayRecord) diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java index e58e8163..73328931 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java @@ -76,7 +76,7 @@ private void addInterruptionForToday(final Duration interruption) appService.addInterruption(appService.getClock().getCurrentDate(), interruption); } - private static class DurationInputDialog extends Dialog + private static final class DurationInputDialog extends Dialog { private final GridPane grid; private final Label label; @@ -91,27 +91,8 @@ private DurationInputDialog() spinner.setMaxWidth(Double.MAX_VALUE); spinner.setEditable(true); - final NumberFormat numberFormat = NumberFormat.getIntegerInstance(); - final UnaryOperator filter = change -> { - if (change.isContentChange()) - { - final String newText = change.getControlNewText(); - if (newText.isEmpty()) - { - return change; - } - final ParsePosition parsePosition = new ParsePosition(0); - numberFormat.parse(newText, parsePosition); - if (parsePosition.getIndex() == 0 || - parsePosition.getIndex() < newText.length()) - { - return null; - } - } - return change; - }; final TextFormatter intFormatter = new TextFormatter<>( - new IntegerStringConverter(), 0, filter); + new IntegerStringConverter(), 0, removeInvalidNumber()); spinner.getEditor().setTextFormatter(intFormatter); GridPane.setHgrow(spinner, Priority.ALWAYS); @@ -149,6 +130,34 @@ private DurationInputDialog() }); } + private UnaryOperator removeInvalidNumber() + { + final NumberFormat numberFormat = NumberFormat.getIntegerInstance(); + return change -> { + if (change.isContentChange()) + { + final String newText = change.getControlNewText(); + if (newText.isEmpty()) + { + return change; + } + if (parsingFails(numberFormat, newText)) + { + return null; + } + } + return change; + }; + } + + private boolean parsingFails(final NumberFormat numberFormat, final String text) + { + final ParsePosition parsePosition = new ParsePosition(0); + numberFormat.parse(text, parsePosition); + return parsePosition.getIndex() == 0 || + parsePosition.getIndex() < text.length(); + } + private static Label createContentLabel(final String text) { final Label label = new Label(text); diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java index 94ef3ac1..1adeca16 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java @@ -150,31 +150,7 @@ public TableView initTable() } }); - table.setRowFactory(param -> new TableRow() - { - @Override - public void updateIndex(final int newIndex) - { - if (newIndex != getIndex() && newIndex >= 0 && newIndex < dayRecords.size()) - { - final DayRecordPropertyAdapter dayRecord = dayRecords.get(newIndex); - LOG.trace("Row index changed from {} to {}: update day {}", getIndex(), newIndex, - dayRecord.date.get()); - dayRecord.setTableRow(this); - } - super.updateIndex(newIndex); - } - - @Override - protected void updateItem(final DayRecordPropertyAdapter item, final boolean empty) - { - super.updateItem(item, empty); - if (item != null) - { - item.setTableRow(this); - } - } - }); + table.setRowFactory(param -> new DayRecordTableRow(dayRecords)); return table; } @@ -197,7 +173,7 @@ public void selectRow(final LocalDate date) final StringConverter durationConverter = new DurationStringConverter(formatterService); final StringConverter localTimeConverter = new CustomLocalTimeStringConverter( formatterService.getLocale()); - final TableColumn dayTypeCol = UiWidget + final TableColumn dayTypeCol = UiWidget .column("day-type", "Type", param -> new ChoiceBoxTableCell<>(new DayTypeStringConverter(), DayType.values()), data -> data.getValue().dayType); @@ -235,4 +211,37 @@ public void selectRow(final LocalDate date) return List.of(dateCol, dayTypeCol, beginCol, endCol, breakCol, interruptionCol, workingTimeCol, overTimeCol, totalOvertimeCol, commentCol); } + + private static final class DayRecordTableRow extends TableRow + { + private final ObservableList dayRecords; + + private DayRecordTableRow(final ObservableList dayRecords) + { + this.dayRecords = dayRecords; + } + + @Override + public void updateIndex(final int newIndex) + { + if (newIndex != getIndex() && newIndex >= 0 && newIndex < dayRecords.size()) + { + final DayRecordPropertyAdapter dayRecord = dayRecords.get(newIndex); + LOG.trace("Row index changed from {} to {}: update day {}", getIndex(), newIndex, + dayRecord.date.get()); + dayRecord.setTableRow(this); + } + super.updateIndex(newIndex); + } + + @Override + protected void updateItem(final DayRecordPropertyAdapter item, final boolean empty) + { + super.updateItem(item, empty); + if (item != null) + { + item.setTableRow(this); + } + } + } } diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/DailyProjectReportViewer.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/DailyProjectReportViewer.java index 57a2fa1c..59d87445 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/DailyProjectReportViewer.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/DailyProjectReportViewer.java @@ -137,7 +137,7 @@ private static TreeItem createDayTreeItem(final ProjectReportDay day) return treeItem; } - public static class ReportRow + public static final class ReportRow { private final LocalDate date; private final DayType dayType; diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java index 86d7c4af..10022b4f 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/ui/YearlyProjectReportViewer.java @@ -71,7 +71,7 @@ private static ReportRow createRow(final int year, final ProjectReportActivity p return new ReportRow(year, project); } - public final static class ReportRow + public static final class ReportRow { private final int year; private final ProjectReportActivity project; diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java index 7138ddd1..db6d57d1 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java @@ -51,7 +51,7 @@ private ProjectReportDay generateDayReport(final DayRecord dayRecord) final List projects = dayRecord.activities() .getAll().stream() .filter(activity -> activity.getProject() != null) - .collect(groupingBy(this::activityProject)) + .collect(groupingBy(ProjectReportGenerator::activityProject)) .values().stream() .map(ProjectReportGenerator::aggregateProject) .toList(); @@ -59,7 +59,7 @@ private ProjectReportDay generateDayReport(final DayRecord dayRecord) return new DayImpl(dayRecord.getDate(), dayRecord.getType(), dayRecord.getComment(), projects); } - private String activityProject(final Activity activity) + private static String activityProject(final Activity activity) { return activity.getProject().getProjectId(); } From 364a2087f657b41b1567add82ccf368e4398c698 Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Sat, 4 May 2024 13:10:33 +0200 Subject: [PATCH 10/11] Fix sonar warnings --- .../feature/InterruptionPresetFeature.java | 34 +++++++++---------- .../jfxui/table/days/DayRecordTable.java | 2 ++ .../project/ProjectReportGenerator.java | 4 +-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java index 73328931..c66da0a4 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java @@ -5,7 +5,6 @@ import java.time.Duration; import java.util.List; import java.util.Locale; -import java.util.function.UnaryOperator; import org.itsallcode.whiterabbit.logic.service.AppService; @@ -21,6 +20,7 @@ import javafx.scene.control.Spinner; import javafx.scene.control.SplitMenuButton; import javafx.scene.control.TextFormatter; +import javafx.scene.control.TextFormatter.Change; import javafx.scene.layout.GridPane; import javafx.scene.layout.Priority; import javafx.scene.layout.Region; @@ -91,8 +91,9 @@ private DurationInputDialog() spinner.setMaxWidth(Double.MAX_VALUE); spinner.setEditable(true); + final NumberFormat numberFormat = NumberFormat.getIntegerInstance(); final TextFormatter intFormatter = new TextFormatter<>( - new IntegerStringConverter(), 0, removeInvalidNumber()); + new IntegerStringConverter(), 0, change -> removeInvalidNumber(numberFormat, change)); spinner.getEditor().setTextFormatter(intFormatter); GridPane.setHgrow(spinner, Priority.ALWAYS); @@ -130,27 +131,24 @@ private DurationInputDialog() }); } - private UnaryOperator removeInvalidNumber() + private Change removeInvalidNumber(final NumberFormat numberFormat, final Change change) { - final NumberFormat numberFormat = NumberFormat.getIntegerInstance(); - return change -> { - if (change.isContentChange()) + if (change.isContentChange()) + { + final String newText = change.getControlNewText(); + if (newText.isEmpty()) { - final String newText = change.getControlNewText(); - if (newText.isEmpty()) - { - return change; - } - if (parsingFails(numberFormat, newText)) - { - return null; - } + return change; + } + if (parsingFails(numberFormat, newText)) + { + return null; } - return change; - }; + } + return change; } - private boolean parsingFails(final NumberFormat numberFormat, final String text) + private static boolean parsingFails(final NumberFormat numberFormat, final String text) { final ParsePosition parsePosition = new ParsePosition(0); numberFormat.parse(text, parsePosition); diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java index 1adeca16..2623fc08 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/table/days/DayRecordTable.java @@ -216,6 +216,8 @@ private static final class DayRecordTableRow extends TableRow dayRecords; + // Storing a copy of "dayRecords" is required here + @SuppressWarnings("java:S2384") private DayRecordTableRow(final ObservableList dayRecords) { this.dayRecords = dayRecords; diff --git a/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java b/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java index db6d57d1..1417e040 100644 --- a/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java +++ b/logic/src/main/java/org/itsallcode/whiterabbit/logic/report/project/ProjectReportGenerator.java @@ -32,7 +32,7 @@ public ProjectReport generateReport(final YearMonth month) .map(MonthIndex::getSortedDays).orElse(Stream.empty()).toList(); final List reportDays = sortedDays.stream() - .map(this::generateDayReport) + .map(ProjectReportGenerator::generateDayReport) .toList(); final List reportProjects = sortedDays.stream() @@ -46,7 +46,7 @@ public ProjectReport generateReport(final YearMonth month) return new ProjectReportImpl(month, reportDays, reportProjects); } - private ProjectReportDay generateDayReport(final DayRecord dayRecord) + private static ProjectReportDay generateDayReport(final DayRecord dayRecord) { final List projects = dayRecord.activities() .getAll().stream() From fd7c23982935fcc336daf2248fbf33677af90b3b Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Sat, 4 May 2024 14:43:19 +0200 Subject: [PATCH 11/11] Fix sonar finding --- .../whiterabbit/jfxui/feature/InterruptionPresetFeature.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java index c66da0a4..11a8a70a 100644 --- a/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java +++ b/jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/feature/InterruptionPresetFeature.java @@ -131,7 +131,7 @@ private DurationInputDialog() }); } - private Change removeInvalidNumber(final NumberFormat numberFormat, final Change change) + private static Change removeInvalidNumber(final NumberFormat numberFormat, final Change change) { if (change.isContentChange()) {