diff --git a/pom.xml b/pom.xml
index bf9810f..91e4c65 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,8 +35,8 @@
UTF-8
- 1.8
- 1.8
+ 15
+ 15
@@ -52,8 +52,10 @@
maven-compiler-plugin3.8.1
- 1.8
- 1.8
+ 15
+
+ --enable-preview
+
diff --git a/src/main/java/io/github/mooninaut/result/AcceptedResult.java b/src/main/java/io/github/mooninaut/result/AcceptedResult.java
index d553956..3094196 100644
--- a/src/main/java/io/github/mooninaut/result/AcceptedResult.java
+++ b/src/main/java/io/github/mooninaut/result/AcceptedResult.java
@@ -22,7 +22,7 @@
* limitations under the License.
*/
-final class AcceptedResult implements Result {
+final class AcceptedResult extends Result {
////// Fields //////
private final VAL value;
@@ -116,7 +116,6 @@ Result map(F mapper) {
@Override
public Optional toOptional() throws NullPointerException {
return Optional.of(get());
-
}
@Override
diff --git a/src/main/java/io/github/mooninaut/result/EmptyResult.java b/src/main/java/io/github/mooninaut/result/EmptyResult.java
index 00fd479..864919d 100644
--- a/src/main/java/io/github/mooninaut/result/EmptyResult.java
+++ b/src/main/java/io/github/mooninaut/result/EmptyResult.java
@@ -22,7 +22,7 @@
* limitations under the License.
*/
-final class EmptyResult implements Result {
+public final class EmptyResult extends Result {
private enum Self {
INSTANCE;
diff --git a/src/main/java/io/github/mooninaut/result/RejectedResult.java b/src/main/java/io/github/mooninaut/result/RejectedResult.java
index ab3fb2f..91e8bcc 100644
--- a/src/main/java/io/github/mooninaut/result/RejectedResult.java
+++ b/src/main/java/io/github/mooninaut/result/RejectedResult.java
@@ -22,7 +22,7 @@
* limitations under the License.
*/
-final class RejectedResult implements Result {
+public final class RejectedResult extends Result {
////// Fields //////
private final Throwable throwable;
diff --git a/src/main/java/io/github/mooninaut/result/Result.java b/src/main/java/io/github/mooninaut/result/Result.java
index 1f34da3..89f06a9 100644
--- a/src/main/java/io/github/mooninaut/result/Result.java
+++ b/src/main/java/io/github/mooninaut/result/Result.java
@@ -27,7 +27,7 @@
* or if rejected, a Throwable.
* @param The type of the included value, if present.
*/
-public interface Result {
+public sealed abstract class Result permits AcceptedResult, EmptyResult, RejectedResult {
/**
* Returns an empty Result. May or may not be a singleton.
@@ -132,31 +132,31 @@ static Result requireNonNull(VAL val) {
* Is this result Accepted?
* @return true for an accepted (possibly null) value, false if rejected.
*/
- boolean isAccepted();
+ abstract boolean isAccepted();
/**
* Is this Result accepted and non-null?
* @return true for an accepted non-null value, false if null or rejected.
*/
- boolean isPresent();
+ abstract boolean isPresent();
/**
* Is this Result accepted and null?
* @return true if this Result is accepted and null, false if non-null or rejected.
*/
- boolean isEmpty();
+ abstract boolean isEmpty();
/**
* Is this result rejected?
* @return true if this Result is rejected, false if accepted.
*/
- boolean isRejected();
+ abstract boolean isRejected();
/**
* Get the class of the contained value or Empty if this Result contains null or is rejected.
* @return the class of the contained value or Empty if this Result contains null or is rejected.
*/
- Optional> getValueType();
+ abstract Optional> getValueType();
/**
* Perform a checked cast to {@code Result} if this Result is accepted.
@@ -165,48 +165,48 @@ static Result requireNonNull(VAL val) {
* @param The class to checkedCast to.
* @return {@code this} if {@code } can be checkedCast to {@code OUT}.
*/
- Result checkedCast(Class type) throws ClassCastException;
+ abstract Result checkedCast(Class type) throws ClassCastException;
/**
* Performs an unchecked cast to {@code RESULT}.
*/
- Result uncheckedCast();
+ abstract Result uncheckedCast();
/**
* Get this Result's value if this Result is accepted, or throws IllegalStateException.
*/
- VAL get() throws IllegalStateException;
+ abstract VAL get() throws IllegalStateException;
/**
* Get this Result's Throwable if this result is Rejected, or throws IllegalStateException.
*/
- Throwable getException() throws IllegalStateException;
+ abstract Throwable getException() throws IllegalStateException;
/**
* Get this Result's value if this Result is accepted, or {@code other} if it is rejected.
*/
- VAL orElse(VAL other);
+ abstract VAL orElse(VAL other);
/**
* Get this Result's value if this Result is accepted, or throws the included Throwable if it is rejected.
*/
- VAL orElseThrow() throws Throwable;
+ abstract VAL orElseThrow() throws Throwable;
/**
* Get this Result's value if this Result is accepted, or throws the included Throwable
* wrapped in a {@link RuntimeException} if it is rejected.
*/
- VAL orElseThrowRuntime() throws RuntimeException;
+ abstract VAL orElseThrowRuntime() throws RuntimeException;
/**
* Throws the included Throwable if it is rejected, otherwise does nothing.
*/
- void throwIfRejected() throws Throwable;
+ abstract void throwIfRejected() throws Throwable;
/**
* Throws the included Throwable wrapped in a {@link RuntimeException} if it is rejected, otherwise does nothing.
*/
- void throwRuntimeIfRejected() throws RuntimeException;
+ abstract void throwRuntimeIfRejected() throws RuntimeException;
/**
* Calls {@code mapper} on IN and returns {@code Result}.
@@ -214,10 +214,10 @@ static Result requireNonNull(VAL val) {
* @param mapper A function mapping from type {@code } to type {@code }, possibly throwing an exception.
* @return If this Result accepted, the result of executing {@code mapper} on this Result's value, otherwise {@code this}
*/
- >
+ abstract >
Result exMap(EF mapper);
- >
+ abstract >
Result exMapChecked(EF mapper, Class inClass, Class outClass);
/**
@@ -226,7 +226,7 @@ static Result requireNonNull(VAL val) {
* @param The return type of {@code mapper}
* @return If this Result accepted, the Result of executing {@code mapper} on this Result's value, otherwise {@code this}
*/
- >
+ abstract >
Result map(F mapper);
/**
@@ -234,56 +234,56 @@ static Result requireNonNull(VAL val) {
* @return the accepted value in an Optional, or, if rejected, an empty Optional.
* @throws NullPointerException if result is accepted, but value is null
*/
- Optional toOptional() throws NullPointerException;
+ abstract Optional toOptional() throws NullPointerException;
/**
* Converts the Result to an {@link Optional}.
* Does not distinguish between a rejected result and an accepted, but null result. In either case, returns an empty Optional.
* @return the accepted value in an Optional, or, if rejected, an empty Optional.
*/
- Optional toNullableOptional();
+ abstract Optional toNullableOptional();
/**
* If this Result is accepted, feed the included value to the supplied {@link Consumer}, otherwise, do nothing.
* Chainable.
*/
- Result ifAccepted(Consumer super VAL> consumer);
+ abstract Result ifAccepted(Consumer super VAL> consumer);
/**
* If this Result is rejected, feed the included {@link Throwable} to the supplied {@link Consumer}, otherwise, do nothing.
* Chainable.
*/
- Result ifRejected(Consumer super Throwable> rejector);
+ abstract Result ifRejected(Consumer super Throwable> rejector);
/**
* Feed this Result's value or {@link Throwable} to the appropriate {@link Consumer}.
* Chainable.
*/
- Result then(Consumer super VAL> consumer, Consumer super Throwable> rejector);
+ abstract Result then(Consumer super VAL> consumer, Consumer super Throwable> rejector);
/**
* Feed this Result's value to the supplied {@link Consumer} if it is present, otherwise feed {@code other} to it.
* Chainable.
*/
- Result acceptOrElse(Consumer super VAL> consumer, VAL other);
+ abstract Result acceptOrElse(Consumer super VAL> consumer, VAL other);
/**
* Feed this Result's value to the supplied {@link Consumer} if it is present, otherwise throw this Result's {@link Throwable}.
* Chainable.
*/
- Result acceptOrElseThrow(Consumer super VAL> consumer) throws Throwable;
+ abstract Result acceptOrElseThrow(Consumer super VAL> consumer) throws Throwable;
/**
* Feed this Result's value to the supplied {@link Consumer} if it is present, otherwise
* throw this Result's {@link Throwable} wrapped in a {@link RuntimeException}.
* Chainable.
*/
- Result acceptOrElseThrowRuntime(Consumer super VAL> consumer) throws RuntimeException;
+ abstract Result acceptOrElseThrowRuntime(Consumer super VAL> consumer) throws RuntimeException;
/**
* Feed this Result's value to the supplied {@link Consumer} if it is present, otherwise
* print the stack trace associated with this Result's {@link Throwable} to standard error.
* Chainable.
*/
- Result acceptOrPrintStacktrace(Consumer super VAL> consumer);
+ abstract Result acceptOrPrintStacktrace(Consumer super VAL> consumer);
}