Ver Fonte

using pattern-matching instanceof where applicable

Sebastian Stenzel há 4 anos atrás
pai
commit
4e075ab0ca

+ 2 - 2
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.");
 			}

+ 1 - 2
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;

+ 1 - 2
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;

+ 2 - 2
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.");
 		}

+ 2 - 2
main/ui/src/main/java/org/cryptomator/ui/common/DefaultSceneFactory.java

@@ -42,8 +42,8 @@ public class DefaultSceneFactory implements Function<Parent, Scene> {
 	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);
 			}
 		});
 	}

+ 2 - 2
main/ui/src/main/java/org/cryptomator/ui/unlock/UnlockWorkflow.java

@@ -76,8 +76,8 @@ public class UnlockWorkflow extends Task<Boolean> {
 
 		setOnFailed(event -> {
 			Throwable throwable = event.getSource().getException();
-			if (throwable instanceof InvalidMountPointException) {
-				handleInvalidMountPoint((InvalidMountPointException) throwable);
+			if (throwable instanceof InvalidMountPointException e) {
+				handleInvalidMountPoint(e);
 			} else {
 				handleGenericError(throwable);
 			}