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()),