diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/result/Result.java b/src/main/java/com/onarandombox/MultiverseCore/utils/result/Result.java index fab68fde..df79f10c 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/result/Result.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/result/Result.java @@ -1,9 +1,9 @@ package com.onarandombox.MultiverseCore.utils.result; +import java.util.NoSuchElementException; import java.util.function.Consumer; -public interface Result { - +public sealed interface Result permits Result.Success, Result.Failure { static Result success(S successReason) { return new Success<>(successReason); } @@ -20,28 +20,28 @@ public interface Result { F failureReason(); - default Result success(Consumer consumer) { + default Result success(Consumer consumer) { if (this.isSuccess()) { consumer.accept(this.successReason()); } return this; } - default Result failure(Consumer consumer) { + default Result failure(Consumer consumer) { if (this.isFailure()) { consumer.accept(this.failureReason()); } return this; } - default Result successWithReason(S successReason, Consumer consumer) { + default Result successWithReason(S successReason, Consumer consumer) { if (this.isSuccess() && this.successReason() == successReason) { consumer.accept(this.successReason()); } return this; } - default Result failureWithReason(F failureReason, Consumer consumer) { + default Result failureWithReason(F failureReason, Consumer consumer) { if (this.isFailure() && this.failureReason() == failureReason) { consumer.accept(this.failureReason()); } @@ -61,7 +61,7 @@ public interface Result { @Override public F failureReason() { - return null; + throw new NoSuchElementException("No failure reason for success"); } } @@ -78,7 +78,7 @@ public interface Result { @Override public S successReason() { - return null; + throw new NoSuchElementException("No success reason for failure"); } } }