JaniruTEC
2021-06-25 00:17:17 +02:00
parent 3762441230
commit 714a0c6664
3 changed files with 21 additions and 33 deletions
@@ -1,23 +0,0 @@
package org.cryptomator.common.settings;
import java.net.URI;
public interface AbstractInvalidSetting {
/**
* Returns the corresponding issue URI of this setting.<br>
* The issue URI usually resolves to a page on the
* <a href="https://github.com/cryptomator/cryptomator/issues">Cryptomator Bugtracker.</a>
*
* @return the issue URI or {@code null} if none is provided.
*/
URI getIssueURI();
/**
* Returns a (preferably localized) message, that helps the user understand the
* issue in their configuration and how to fix it.
*
* @return the non-null description of the issue.
*/
String getMessage();
}
@@ -4,7 +4,7 @@ import java.net.URI;
import java.util.Objects; import java.util.Objects;
import java.util.ResourceBundle; import java.util.ResourceBundle;
public enum InvalidSetting implements AbstractInvalidSetting { public enum InvalidSetting {
; ;
@@ -24,12 +24,23 @@ public enum InvalidSetting implements AbstractInvalidSetting {
this(onDefaultTracker(issueId), Objects.requireNonNull(resourceKey)); this(onDefaultTracker(issueId), Objects.requireNonNull(resourceKey));
} }
@Override /**
* Returns the corresponding issue URI of this setting.<br>
* The issue URI usually resolves to a page on the
* <a href="https://github.com/cryptomator/cryptomator/issues">Cryptomator Bugtracker.</a>
*
* @return the issue URI or {@code null} if none is provided.
*/
public URI getIssueURI() { public URI getIssueURI() {
return this.issue; return this.issue;
} }
@Override /**
* Returns a (preferably localized) message, that helps the user understand the
* issue in their configuration and how to fix it.
*
* @return the non-null description of the issue.
*/
public String getMessage() { public String getMessage() {
if (!BUNDLE.containsKey(this.resourceKey)) { if (!BUNDLE.containsKey(this.resourceKey)) {
return UNKNOWN_KEY_FORMAT.formatted(this.resourceKey); return UNKNOWN_KEY_FORMAT.formatted(this.resourceKey);
@@ -3,28 +3,28 @@ package org.cryptomator.common.settings;
public class InvalidSettingException extends RuntimeException { public class InvalidSettingException extends RuntimeException {
private final AbstractInvalidSetting reason; private final InvalidSetting reason;
private final String additionalMessage; private final String additionalMessage;
public InvalidSettingException(AbstractInvalidSetting reason) { public InvalidSettingException(InvalidSetting reason) {
this(reason, null, null); this(reason, null, null);
} }
public InvalidSettingException(AbstractInvalidSetting reason, String additionalMessage) { public InvalidSettingException(InvalidSetting reason, String additionalMessage) {
this(reason, additionalMessage, null); this(reason, additionalMessage, null);
} }
public InvalidSettingException(AbstractInvalidSetting reason, Throwable cause) { public InvalidSettingException(InvalidSetting reason, Throwable cause) {
this(reason, null, cause); this(reason, null, cause);
} }
public InvalidSettingException(AbstractInvalidSetting reason, String additionalMessage, Throwable cause) { public InvalidSettingException(InvalidSetting reason, String additionalMessage, Throwable cause) {
super(composeMessage(reason, additionalMessage), cause); super(composeMessage(reason, additionalMessage), cause);
this.reason = reason; this.reason = reason;
this.additionalMessage = additionalMessage; this.additionalMessage = additionalMessage;
} }
public AbstractInvalidSetting getReason() { public InvalidSetting getReason() {
return this.reason; return this.reason;
} }
@@ -32,7 +32,7 @@ public class InvalidSettingException extends RuntimeException {
return this.additionalMessage; return this.additionalMessage;
} }
private static String composeMessage(AbstractInvalidSetting reason, String additionalMessage) { private static String composeMessage(InvalidSetting reason, String additionalMessage) {
if (additionalMessage == null) { if (additionalMessage == null) {
return reason.getMessage(); return reason.getMessage();
} }