From 7396fc2158738a23db2169a4dbfb23fd5c468cfa Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Wed, 10 Mar 2021 16:20:25 +0100 Subject: [PATCH] Result javadocs --- src/main/java/edu/kit/typicalc/util/Result.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/kit/typicalc/util/Result.java b/src/main/java/edu/kit/typicalc/util/Result.java index bd52e03..2bb939a 100644 --- a/src/main/java/edu/kit/typicalc/util/Result.java +++ b/src/main/java/edu/kit/typicalc/util/Result.java @@ -71,13 +71,19 @@ public class Result { * @return the value * @throws IllegalStateException if this is an error */ - public T unwrap() { + public T unwrap() throws IllegalStateException { if (value == null) { throw new IllegalStateException("tried to unwrap a result, but error = " + error); } return value; } + /** + * If the result contains a regular value, returns that value. + * Otherwise return the supplied alternative value. + * + * @return the value or the alternative + */ public T unwrapOr(T alternative) { if (value == null) { return alternative; @@ -99,6 +105,13 @@ public class Result { return error; } + /** + * Apply a function to the value of this result if it exists. + * + * @param mapping function to apply + * @param new type of the value + * @return new result + */ public Result map(Function mapping) { return new Result<>(value != null ? mapping.apply(value) : null, error); }