From d2189d379ca8634479fc8495b9cc2034dfac37a5 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Mon, 11 May 2020 07:47:15 +0200 Subject: [PATCH] Using switch expressions --- .../common/settings/SettingsJsonAdapter.java | 52 +++++------------- .../settings/VaultSettingsJsonAdapter.java | 54 +++++-------------- .../cryptomator/ui/fxapp/FxApplication.java | 9 ++-- .../ui/launcher/AppLaunchEventHandler.java | 12 ++--- .../ui/mainwindow/VaultListController.java | 7 ++- 5 files changed, 38 insertions(+), 96 deletions(-) diff --git a/main/commons/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java b/main/commons/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java index 33afb7306..395034f56 100644 --- a/main/commons/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java +++ b/main/commons/src/main/java/org/cryptomator/common/settings/SettingsJsonAdapter.java @@ -58,46 +58,22 @@ public class SettingsJsonAdapter extends TypeAdapter { while (in.hasNext()) { String name = in.nextName(); switch (name) { - case "directories": - settings.getDirectories().addAll(readVaultSettingsArray(in)); - break; - case "askedForUpdateCheck": - settings.askedForUpdateCheck().set(in.nextBoolean()); - break; - case "checkForUpdatesEnabled": - settings.checkForUpdates().set(in.nextBoolean()); - break; - case "startHidden": - settings.startHidden().set(in.nextBoolean()); - break; - case "port": - settings.port().set(in.nextInt()); - break; - case "numTrayNotifications": - settings.numTrayNotifications().set(in.nextInt()); - break; - case "preferredGvfsScheme": - settings.preferredGvfsScheme().set(parseWebDavUrlSchemePrefix(in.nextString())); - break; - case "debugMode": - settings.debugMode().set(in.nextBoolean()); - break; - case "preferredVolumeImpl": - settings.preferredVolumeImpl().set(parsePreferredVolumeImplName(in.nextString())); - break; - case "theme": - settings.theme().set(parseUiTheme(in.nextString())); - break; - case "uiOrientation": - settings.userInterfaceOrientation().set(parseUiOrientation(in.nextString())); - break; - case "licenseKey": - settings.licenseKey().set(in.nextString()); - break; - default: + case "directories" -> settings.getDirectories().addAll(readVaultSettingsArray(in)); + case "askedForUpdateCheck" -> settings.askedForUpdateCheck().set(in.nextBoolean()); + case "checkForUpdatesEnabled" -> settings.checkForUpdates().set(in.nextBoolean()); + case "startHidden" -> settings.startHidden().set(in.nextBoolean()); + case "port" -> settings.port().set(in.nextInt()); + case "numTrayNotifications" -> settings.numTrayNotifications().set(in.nextInt()); + case "preferredGvfsScheme" -> settings.preferredGvfsScheme().set(parseWebDavUrlSchemePrefix(in.nextString())); + case "debugMode" -> settings.debugMode().set(in.nextBoolean()); + case "preferredVolumeImpl" -> settings.preferredVolumeImpl().set(parsePreferredVolumeImplName(in.nextString())); + case "theme" -> settings.theme().set(parseUiTheme(in.nextString())); + case "uiOrientation" -> settings.userInterfaceOrientation().set(parseUiOrientation(in.nextString())); + case "licenseKey" -> settings.licenseKey().set(in.nextString()); + default -> { LOG.warn("Unsupported vault setting found in JSON: " + name); in.skipValue(); - break; + } } } in.endObject(); diff --git a/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettingsJsonAdapter.java b/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettingsJsonAdapter.java index 980bfd355..d136ffaff 100644 --- a/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettingsJsonAdapter.java +++ b/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettingsJsonAdapter.java @@ -52,48 +52,22 @@ class VaultSettingsJsonAdapter { while (in.hasNext()) { String name = in.nextName(); switch (name) { - case "id": - id = in.nextString(); - break; - case "path": - path = in.nextString(); - break; - case "mountName": - mountName = in.nextString(); - break; - case "winDriveLetter": - winDriveLetter = in.nextString(); - break; - case "unlockAfterStartup": - unlockAfterStartup = in.nextBoolean(); - break; - case "revealAfterMount": - revealAfterMount = in.nextBoolean(); - break; - case "usesIndividualMountPath": - case "useCustomMountPath": - useCustomMountPath = in.nextBoolean(); - break; - case "individualMountPath": - case "customMountPath": - customMountPath = in.nextString(); - break; - case "usesReadOnlyMode": - usesReadOnlyMode = in.nextBoolean(); - break; - case "mountFlags": - mountFlags = in.nextString(); - break; - case "filenameLengthLimit": - filenameLengthLimit = in.nextInt(); - break; - case "actionAfterUnlock": - actionAfterUnlock = parseActionAfterUnlock(in.nextString()); - break; - default: + case "id" -> id = in.nextString(); + case "path" -> path = in.nextString(); + case "mountName" -> mountName = in.nextString(); + case "winDriveLetter" -> winDriveLetter = in.nextString(); + case "unlockAfterStartup" -> unlockAfterStartup = in.nextBoolean(); + case "revealAfterMount" -> revealAfterMount = in.nextBoolean(); + case "usesIndividualMountPath", "useCustomMountPath" -> useCustomMountPath = in.nextBoolean(); + case "individualMountPath", "customMountPath" -> customMountPath = in.nextString(); + case "usesReadOnlyMode" -> usesReadOnlyMode = in.nextBoolean(); + case "mountFlags" -> mountFlags = in.nextString(); + case "filenameLengthLimit" -> filenameLengthLimit = in.nextInt(); + case "actionAfterUnlock" -> actionAfterUnlock = parseActionAfterUnlock(in.nextString()); + default -> { LOG.warn("Unsupported vault setting found in JSON: " + name); in.skipValue(); - break; + } } } in.endObject(); diff --git a/main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java b/main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java index e0d1ecf93..c197ecf87 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java +++ b/main/ui/src/main/java/org/cryptomator/ui/fxapp/FxApplication.java @@ -121,15 +121,14 @@ public class FxApplication extends Application { private void loadSelectedStyleSheet(UiTheme desiredTheme) { UiTheme theme = licenseHolder.isValidLicense() ? desiredTheme : UiTheme.LIGHT; switch (theme) { - case DARK: + case DARK -> { Application.setUserAgentStylesheet(getClass().getResource("/css/dark_theme.css").toString()); macFunctions.map(MacFunctions::uiAppearance).ifPresent(JniException.ignore(MacApplicationUiAppearance::setToDarkAqua)); - break; - case LIGHT: - default: + } + case LIGHT -> { Application.setUserAgentStylesheet(getClass().getResource("/css/light_theme.css").toString()); macFunctions.map(MacFunctions::uiAppearance).ifPresent(JniException.ignore(MacApplicationUiAppearance::setToAqua)); - break; + } } } diff --git a/main/ui/src/main/java/org/cryptomator/ui/launcher/AppLaunchEventHandler.java b/main/ui/src/main/java/org/cryptomator/ui/launcher/AppLaunchEventHandler.java index 3ab8d0de1..fb75418f3 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/launcher/AppLaunchEventHandler.java +++ b/main/ui/src/main/java/org/cryptomator/ui/launcher/AppLaunchEventHandler.java @@ -52,19 +52,13 @@ class AppLaunchEventHandler { private void handleLaunchEvent(boolean hasTrayIcon, AppLaunchEvent event) { switch (event.getType()) { - case REVEAL_APP: - fxApplicationStarter.get(hasTrayIcon).thenAccept(FxApplication::showMainWindow); - break; - case OPEN_FILE: - fxApplicationStarter.get(hasTrayIcon).thenRun(() -> { + case REVEAL_APP -> fxApplicationStarter.get(hasTrayIcon).thenAccept(FxApplication::showMainWindow); + case OPEN_FILE -> fxApplicationStarter.get(hasTrayIcon).thenRun(() -> { Platform.runLater(() -> { event.getPathsToOpen().forEach(this::addVault); }); }); - break; - default: - LOG.warn("Unsupported event type: {}", event.getType()); - break; + default -> LOG.warn("Unsupported event type: {}", event.getType()); } } diff --git a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java index de39719bc..26929028d 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java @@ -66,7 +66,7 @@ public class VaultListController implements FxController { } VaultState reportedState = newValue.getState(); switch (reportedState) { - case LOCKED, NEEDS_MIGRATION, MISSING: + case LOCKED, NEEDS_MIGRATION, MISSING -> { try { VaultState determinedState = VaultListManager.determineVaultState(newValue.getPath()); newValue.setState(determinedState); @@ -75,9 +75,8 @@ public class VaultListController implements FxController { newValue.setState(VaultState.ERROR); newValue.setLastKnownException(e); } - break; - case ERROR, UNLOCKED, PROCESSING: - break; // no-op + } + case ERROR, UNLOCKED, PROCESSING -> {} } }