From 4e075ab0ca080e4a6f0d6fc45163517f47704595 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Wed, 17 Mar 2021 09:22:16 +0100 Subject: [PATCH] using pattern-matching instanceof where applicable --- .../src/main/java/org/cryptomator/common/LicenseChecker.java | 4 ++-- .../java/org/cryptomator/common/settings/VaultSettings.java | 3 +-- .../src/main/java/org/cryptomator/common/vaults/Vault.java | 3 +-- .../src/main/java/org/cryptomator/logging/LoggerModule.java | 4 ++-- .../java/org/cryptomator/ui/common/DefaultSceneFactory.java | 4 ++-- .../main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java | 4 ++-- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/main/commons/src/main/java/org/cryptomator/common/LicenseChecker.java b/main/commons/src/main/java/org/cryptomator/common/LicenseChecker.java index 93f16f755..38bf8e191 100644 --- a/main/commons/src/main/java/org/cryptomator/common/LicenseChecker.java +++ b/main/commons/src/main/java/org/cryptomator/common/LicenseChecker.java @@ -33,8 +33,8 @@ class LicenseChecker { try { byte[] keyBytes = BaseEncoding.base64().decode(pemEncodedPublicKey); PublicKey key = KeyFactory.getInstance("EC").generatePublic(new X509EncodedKeySpec(keyBytes)); - if (key instanceof ECPublicKey) { - return (ECPublicKey) key; + if (key instanceof ECPublicKey k) { + return k; } else { throw new IllegalStateException("Key not an EC public key."); } diff --git a/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettings.java b/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettings.java index 7de22753a..b273bb642 100644 --- a/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettings.java +++ b/main/commons/src/main/java/org/cryptomator/common/settings/VaultSettings.java @@ -173,8 +173,7 @@ public class VaultSettings { @Override public boolean equals(Object obj) { - if (obj instanceof VaultSettings && obj.getClass().equals(this.getClass())) { - VaultSettings other = (VaultSettings) obj; + if (obj instanceof VaultSettings other && obj.getClass().equals(this.getClass())) { return Objects.equals(this.id, other.id); } else { return false; diff --git a/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java b/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java index ae1f6aac6..98a6cf21b 100644 --- a/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java +++ b/main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java @@ -355,8 +355,7 @@ public class Vault { @Override public boolean equals(Object obj) { - if (obj instanceof Vault && obj.getClass().equals(this.getClass())) { - final Vault other = (Vault) obj; + if (obj instanceof Vault other && obj.getClass().equals(this.getClass())) { return Objects.equals(this.vaultSettings, other.vaultSettings); } else { return false; diff --git a/main/launcher/src/main/java/org/cryptomator/logging/LoggerModule.java b/main/launcher/src/main/java/org/cryptomator/logging/LoggerModule.java index ba556933e..0b24e0e24 100644 --- a/main/launcher/src/main/java/org/cryptomator/logging/LoggerModule.java +++ b/main/launcher/src/main/java/org/cryptomator/logging/LoggerModule.java @@ -47,8 +47,8 @@ public class LoggerModule { @Singleton static LoggerContext provideLoggerContext() { ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory(); - if (loggerFactory instanceof LoggerContext) { - return (LoggerContext) loggerFactory; + if (loggerFactory instanceof LoggerContext context) { + return context; } else { throw new IllegalStateException("SLF4J not bound to Logback."); } diff --git a/main/ui/src/main/java/org/cryptomator/ui/common/DefaultSceneFactory.java b/main/ui/src/main/java/org/cryptomator/ui/common/DefaultSceneFactory.java index ad6056c44..7f6daa44d 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/common/DefaultSceneFactory.java +++ b/main/ui/src/main/java/org/cryptomator/ui/common/DefaultSceneFactory.java @@ -42,8 +42,8 @@ public class DefaultSceneFactory implements Function { protected void configureScene(Scene scene) { scene.windowProperty().addListener(observable -> { Window window = scene.getWindow(); - if (window instanceof Stage) { - setupDefaultAccelerators(scene, (Stage) window); + if (window instanceof Stage s) { + setupDefaultAccelerators(scene, s); } }); } diff --git a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java index 12f6d4dc6..c1b5fbd45 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java +++ b/main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java @@ -76,8 +76,8 @@ public class UnlockWorkflow extends Task { setOnFailed(event -> { Throwable throwable = event.getSource().getException(); - if (throwable instanceof InvalidMountPointException) { - handleInvalidMountPoint((InvalidMountPointException) throwable); + if (throwable instanceof InvalidMountPointException e) { + handleInvalidMountPoint(e); } else { handleGenericError(throwable); }