mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-14 08:41:28 +00:00
replaced some "old" switch statements by switch expressions
This commit is contained in:
@@ -41,16 +41,13 @@ public class VaultStats {
|
||||
}
|
||||
|
||||
private void vaultStateChanged(@SuppressWarnings("unused") Observable observable) {
|
||||
switch (state.get()) {
|
||||
case UNLOCKED:
|
||||
assert fs.get() != null;
|
||||
LOG.debug("start recording stats");
|
||||
updateService.restart();
|
||||
break;
|
||||
default:
|
||||
LOG.debug("stop recording stats");
|
||||
updateService.cancel();
|
||||
break;
|
||||
if (VaultState.UNLOCKED.equals(state.get())) {
|
||||
assert fs.get() != null;
|
||||
LOG.debug("start recording stats");
|
||||
updateService.restart();
|
||||
} else {
|
||||
LOG.debug("stop recording stats");
|
||||
updateService.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,17 +43,10 @@ public interface Volume {
|
||||
}
|
||||
|
||||
static VolumeImpl[] getCurrentSupportedAdapters() {
|
||||
return Stream.of(VolumeImpl.values()).filter(impl -> {
|
||||
switch (impl) {
|
||||
case WEBDAV:
|
||||
return WebDavVolume.isSupportedStatic();
|
||||
case DOKANY:
|
||||
return DokanyVolume.isSupportedStatic();
|
||||
case FUSE:
|
||||
return FuseVolume.isSupportedStatic();
|
||||
default:
|
||||
return false;//throw new IllegalStateException("Adapter not implemented.");
|
||||
}
|
||||
return Stream.of(VolumeImpl.values()).filter(impl -> switch (impl) {
|
||||
case WEBDAV -> WebDavVolume.isSupportedStatic();
|
||||
case DOKANY -> DokanyVolume.isSupportedStatic();
|
||||
case FUSE -> FuseVolume.isSupportedStatic();
|
||||
}).toArray(VolumeImpl[]::new);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,16 +31,12 @@ public class VaultDetailController implements FxController {
|
||||
}
|
||||
|
||||
private FontAwesome5Icon getGlyphForVaultState(VaultState state) {
|
||||
switch (state) {
|
||||
case LOCKED:
|
||||
return FontAwesome5Icon.LOCK;
|
||||
case PROCESSING:
|
||||
return FontAwesome5Icon.SPINNER;
|
||||
case UNLOCKED:
|
||||
return FontAwesome5Icon.LOCK_OPEN;
|
||||
default:
|
||||
return FontAwesome5Icon.EXCLAMATION_TRIANGLE;
|
||||
}
|
||||
return switch (state) {
|
||||
case LOCKED -> FontAwesome5Icon.LOCK;
|
||||
case PROCESSING -> FontAwesome5Icon.SPINNER;
|
||||
case UNLOCKED -> FontAwesome5Icon.LOCK_OPEN;
|
||||
case NEEDS_MIGRATION, MISSING, ERROR -> FontAwesome5Icon.EXCLAMATION_TRIANGLE;
|
||||
};
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
||||
@@ -3,9 +3,9 @@ package org.cryptomator.ui.mainwindow;
|
||||
import javafx.beans.binding.Binding;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.common.vaults.VaultState;
|
||||
import org.cryptomator.ui.common.FxController;
|
||||
import org.cryptomator.common.vaults.Vault;
|
||||
import org.cryptomator.ui.controls.FontAwesome5Icon;
|
||||
import org.fxmisc.easybind.EasyBind;
|
||||
|
||||
@@ -23,16 +23,12 @@ public class VaultListCellController implements FxController {
|
||||
}
|
||||
|
||||
private FontAwesome5Icon getGlyphForVaultState(VaultState state) {
|
||||
switch (state) {
|
||||
case LOCKED:
|
||||
return FontAwesome5Icon.LOCK;
|
||||
case PROCESSING:
|
||||
return FontAwesome5Icon.SPINNER;
|
||||
case UNLOCKED:
|
||||
return FontAwesome5Icon.LOCK_OPEN;
|
||||
default:
|
||||
return FontAwesome5Icon.EXCLAMATION_TRIANGLE;
|
||||
}
|
||||
return switch (state) {
|
||||
case LOCKED -> FontAwesome5Icon.LOCK;
|
||||
case PROCESSING -> FontAwesome5Icon.SPINNER;
|
||||
case UNLOCKED -> FontAwesome5Icon.LOCK_OPEN;
|
||||
case NEEDS_MIGRATION, MISSING, ERROR -> FontAwesome5Icon.EXCLAMATION_TRIANGLE;
|
||||
};
|
||||
}
|
||||
|
||||
/* Getter/Setter */
|
||||
|
||||
@@ -66,9 +66,7 @@ public class VaultListController implements FxController {
|
||||
}
|
||||
VaultState reportedState = newValue.getState();
|
||||
switch (reportedState) {
|
||||
case LOCKED:
|
||||
case NEEDS_MIGRATION:
|
||||
case MISSING:
|
||||
case LOCKED, NEEDS_MIGRATION, MISSING:
|
||||
try {
|
||||
VaultState determinedState = VaultListManager.determineVaultState(newValue.getPath());
|
||||
newValue.setState(determinedState);
|
||||
@@ -78,11 +76,8 @@ public class VaultListController implements FxController {
|
||||
newValue.setLastKnownException(e);
|
||||
}
|
||||
break;
|
||||
case ERROR:
|
||||
case UNLOCKED:
|
||||
case PROCESSING:
|
||||
default:
|
||||
// no-op
|
||||
case ERROR, UNLOCKED, PROCESSING:
|
||||
break; // no-op
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -142,19 +142,11 @@ public class MigrationRunController implements FxController {
|
||||
|
||||
// Called by a background task. We can not directly modify observable properties from here
|
||||
private void migrationProgressChanged(MigrationProgressListener.ProgressState state, double progress) {
|
||||
switch (state) {
|
||||
case INITIALIZING:
|
||||
volatileMigrationProgress = -1.0;
|
||||
break;
|
||||
case MIGRATING:
|
||||
volatileMigrationProgress = progress;
|
||||
break;
|
||||
case FINALIZING:
|
||||
volatileMigrationProgress = 1.0;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpted state " + state);
|
||||
}
|
||||
volatileMigrationProgress = switch (state) {
|
||||
case INITIALIZING -> -1.0;
|
||||
case MIGRATING -> progress;
|
||||
case FINALIZING -> 1.0;
|
||||
};
|
||||
}
|
||||
|
||||
private void loadStoredPassword() {
|
||||
@@ -194,12 +186,10 @@ public class MigrationRunController implements FxController {
|
||||
}
|
||||
|
||||
public ContentDisplay getMigrateButtonContentDisplay() {
|
||||
switch (vault.getState()) {
|
||||
case PROCESSING:
|
||||
return ContentDisplay.LEFT;
|
||||
default:
|
||||
return ContentDisplay.TEXT_ONLY;
|
||||
}
|
||||
return switch (vault.getState()) {
|
||||
case PROCESSING -> ContentDisplay.LEFT;
|
||||
default -> ContentDisplay.TEXT_ONLY;
|
||||
};
|
||||
}
|
||||
|
||||
public ReadOnlyDoubleProperty migrationProgressProperty() {
|
||||
|
||||
@@ -49,21 +49,14 @@ public class PreferencesController implements FxController {
|
||||
}
|
||||
|
||||
private Tab getTabToSelect(SelectedPreferencesTab selectedTab) {
|
||||
switch (selectedTab) {
|
||||
case UPDATES:
|
||||
return updatesTab;
|
||||
case VOLUME:
|
||||
return volumeTab;
|
||||
case DONATION_KEY:
|
||||
return donationKeyTab;
|
||||
case GENERAL:
|
||||
return generalTab;
|
||||
case ABOUT:
|
||||
return aboutTab;
|
||||
case ANY:
|
||||
default:
|
||||
return updateAvailable.get() ? updatesTab : generalTab;
|
||||
}
|
||||
return switch (selectedTab) {
|
||||
case UPDATES -> updatesTab;
|
||||
case VOLUME -> volumeTab;
|
||||
case DONATION_KEY -> donationKeyTab;
|
||||
case GENERAL -> generalTab;
|
||||
case ABOUT -> aboutTab;
|
||||
case ANY -> updateAvailable.get() ? updatesTab : generalTab;
|
||||
};
|
||||
}
|
||||
|
||||
private void selectedTabChanged() {
|
||||
|
||||
@@ -29,12 +29,10 @@ class TrayImageFactory {
|
||||
MacApplicationUiInterfaceStyle interfaceStyle = macFunctions.map(MacFunctions::uiAppearance) //
|
||||
.map(MacApplicationUiAppearance::getCurrentInterfaceStyle) //
|
||||
.orElse(MacApplicationUiInterfaceStyle.LIGHT);
|
||||
switch (interfaceStyle) {
|
||||
case DARK:
|
||||
return "/tray_icon_mac_white.png";
|
||||
default:
|
||||
return "/tray_icon_mac_black.png";
|
||||
}
|
||||
return switch (interfaceStyle) {
|
||||
case DARK -> "/tray_icon_mac_white.png";
|
||||
case LIGHT -> "/tray_icon_mac_black.png";
|
||||
};
|
||||
}
|
||||
|
||||
private String getWinOrLinuxResourceName() {
|
||||
|
||||
@@ -174,12 +174,10 @@ public class UnlockController implements FxController {
|
||||
}
|
||||
|
||||
public ContentDisplay getUnlockButtonState() {
|
||||
switch (vault.getState()) {
|
||||
case PROCESSING:
|
||||
return ContentDisplay.LEFT;
|
||||
default:
|
||||
return ContentDisplay.TEXT_ONLY;
|
||||
}
|
||||
return switch (vault.getState()) {
|
||||
case PROCESSING -> ContentDisplay.LEFT;
|
||||
default -> ContentDisplay.TEXT_ONLY;
|
||||
};
|
||||
}
|
||||
|
||||
public ReadOnlyBooleanProperty unlockButtonDisabledProperty() {
|
||||
|
||||
Reference in New Issue
Block a user