Merge pull request #47 from kemitix/bump-kemitix-checkstyle-ruleset-from-4.1.1-to-5.0.0
Bump kemitix-checkstyle-ruleset from 4.1.1 to 5.0.0
This commit is contained in:
commit
3ad4019f53
9 changed files with 56 additions and 56 deletions
2
pom.xml
2
pom.xml
|
@ -39,7 +39,7 @@
|
||||||
<tiles-maven-plugin.version>2.12</tiles-maven-plugin.version>
|
<tiles-maven-plugin.version>2.12</tiles-maven-plugin.version>
|
||||||
<kemitix-maven-tiles.version>1.2.0</kemitix-maven-tiles.version>
|
<kemitix-maven-tiles.version>1.2.0</kemitix-maven-tiles.version>
|
||||||
<digraph-dependency.basePackage>net.kemitix.mon</digraph-dependency.basePackage>
|
<digraph-dependency.basePackage>net.kemitix.mon</digraph-dependency.basePackage>
|
||||||
<kemitix-checkstyle.version>4.1.1</kemitix-checkstyle.version>
|
<kemitix-checkstyle.version>5.0.0</kemitix-checkstyle.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
|
@ -48,5 +48,5 @@ public interface Functor<T, F extends Functor<?, ?>> {
|
||||||
*
|
*
|
||||||
* @return a Functor containing the result of the function {@code f} applied to the value
|
* @return a Functor containing the result of the function {@code f} applied to the value
|
||||||
*/
|
*/
|
||||||
<R> F map(Function<T, R> f);
|
public abstract <R> F map(Function<T, R> f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ public interface After<T, R> extends
|
||||||
* @return a partially applied Function that will take an argument and return the result of applying it to the
|
* @return a partially applied Function that will take an argument and return the result of applying it to the
|
||||||
* function parameter
|
* function parameter
|
||||||
*/
|
*/
|
||||||
static <T, R> Function<T, R> decorate(
|
public static <T, R> Function<T, R> decorate(
|
||||||
final Function<T, R> function,
|
final Function<T, R> function,
|
||||||
final BiConsumer<T, R> after
|
final BiConsumer<T, R> after
|
||||||
) {
|
) {
|
||||||
|
@ -68,7 +68,7 @@ public interface After<T, R> extends
|
||||||
*
|
*
|
||||||
* @return a curried function that will pass the argument and the result of the function to the supplied bi-consumer
|
* @return a curried function that will pass the argument and the result of the function to the supplied bi-consumer
|
||||||
*/
|
*/
|
||||||
static <T, R> After<T, R> create() {
|
public static <T, R> After<T, R> create() {
|
||||||
return function -> after -> argument -> {
|
return function -> after -> argument -> {
|
||||||
final R result = function.apply(argument);
|
final R result = function.apply(argument);
|
||||||
after.accept(argument, result);
|
after.accept(argument, result);
|
||||||
|
|
|
@ -54,7 +54,7 @@ public interface Around<T, R> extends
|
||||||
*
|
*
|
||||||
* @return a partially applied Function that will take an argument, and the result of applying it to function
|
* @return a partially applied Function that will take an argument, and the result of applying it to function
|
||||||
*/
|
*/
|
||||||
static <T, R> Function<T, R> decorate(
|
public static <T, R> Function<T, R> decorate(
|
||||||
final Function<T, R> function,
|
final Function<T, R> function,
|
||||||
final BiConsumer<Executable<R>, T> around
|
final BiConsumer<Executable<R>, T> around
|
||||||
) {
|
) {
|
||||||
|
@ -71,7 +71,7 @@ public interface Around<T, R> extends
|
||||||
* @return a curried function that will execute the around function, passing an executable and the invocations
|
* @return a curried function that will execute the around function, passing an executable and the invocations
|
||||||
* argument. The around function must {@code execute()} the executable and may capture the result.
|
* argument. The around function must {@code execute()} the executable and may capture the result.
|
||||||
*/
|
*/
|
||||||
static <T, R> Around<T, R> create() {
|
public static <T, R> Around<T, R> create() {
|
||||||
return function -> around -> argument -> {
|
return function -> around -> argument -> {
|
||||||
final AtomicReference<R> result = new AtomicReference<>();
|
final AtomicReference<R> result = new AtomicReference<>();
|
||||||
final Executable<R> callback = () -> {
|
final Executable<R> callback = () -> {
|
||||||
|
@ -89,13 +89,13 @@ public interface Around<T, R> extends
|
||||||
* @param <R> the return type of the function
|
* @param <R> the return type of the function
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
interface Executable<R> {
|
public static interface Executable<R> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the function.
|
* Executes the function.
|
||||||
*
|
*
|
||||||
* @return the result of applying the function
|
* @return the result of applying the function
|
||||||
*/
|
*/
|
||||||
R execute();
|
public abstract R execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ public interface Before<T, R> extends
|
||||||
* @return a partially applied Function that will take an argument and return the result of applying it to the
|
* @return a partially applied Function that will take an argument and return the result of applying it to the
|
||||||
* function parameter
|
* function parameter
|
||||||
*/
|
*/
|
||||||
static <T, R> Function<T, R> decorate(
|
public static <T, R> Function<T, R> decorate(
|
||||||
final Consumer<T> before,
|
final Consumer<T> before,
|
||||||
final Function<T, R> function
|
final Function<T, R> function
|
||||||
) {
|
) {
|
||||||
|
@ -69,7 +69,7 @@ public interface Before<T, R> extends
|
||||||
*
|
*
|
||||||
* @return a curried function that will pass the argument to before applying the supplied function
|
* @return a curried function that will pass the argument to before applying the supplied function
|
||||||
*/
|
*/
|
||||||
static <T, R> Before<T, R> create() {
|
public static <T, R> Before<T, R> create() {
|
||||||
return before -> function -> argument -> {
|
return before -> function -> argument -> {
|
||||||
before.accept(argument);
|
before.accept(argument);
|
||||||
return function.apply(argument);
|
return function.apply(argument);
|
||||||
|
|
|
@ -41,7 +41,7 @@ public interface Either<L, R> {
|
||||||
* @param <R> the type of the right value
|
* @param <R> the type of the right value
|
||||||
* @return a Either holding the left value
|
* @return a Either holding the left value
|
||||||
*/
|
*/
|
||||||
static <L, R> Either<L, R> left(final L l) {
|
public static <L, R> Either<L, R> left(final L l) {
|
||||||
return new Left<>(l);
|
return new Left<>(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public interface Either<L, R> {
|
||||||
* @param <R> the type of the right value
|
* @param <R> the type of the right value
|
||||||
* @return a Either holding the right value
|
* @return a Either holding the right value
|
||||||
*/
|
*/
|
||||||
static <L, R> Either<L, R> right(final R r) {
|
public static <L, R> Either<L, R> right(final R r) {
|
||||||
return new Right<>(r);
|
return new Right<>(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,14 +62,14 @@ public interface Either<L, R> {
|
||||||
*
|
*
|
||||||
* @return true if this Either is a left
|
* @return true if this Either is a left
|
||||||
*/
|
*/
|
||||||
boolean isLeft();
|
public abstract boolean isLeft();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the Either holds a right value.
|
* Checks if the Either holds a right value.
|
||||||
*
|
*
|
||||||
* @return true if this Either is a right
|
* @return true if this Either is a right
|
||||||
*/
|
*/
|
||||||
boolean isRight();
|
public abstract boolean isRight();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Matches the Either, invoking the correct Consumer.
|
* Matches the Either, invoking the correct Consumer.
|
||||||
|
@ -77,7 +77,7 @@ public interface Either<L, R> {
|
||||||
* @param onLeft the Consumer to invoke when the Either is a left
|
* @param onLeft the Consumer to invoke when the Either is a left
|
||||||
* @param onRight the Consumer to invoke when the Either is a right
|
* @param onRight the Consumer to invoke when the Either is a right
|
||||||
*/
|
*/
|
||||||
void match(Consumer<L> onLeft, Consumer<R> onRight);
|
public abstract void match(Consumer<L> onLeft, Consumer<R> onRight);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map the function across the left value.
|
* Map the function across the left value.
|
||||||
|
@ -86,7 +86,7 @@ public interface Either<L, R> {
|
||||||
* @param <T> the type to change the left value to
|
* @param <T> the type to change the left value to
|
||||||
* @return a new Either
|
* @return a new Either
|
||||||
*/
|
*/
|
||||||
<T> Either<T, R> mapLeft(Function<L, T> f);
|
public abstract <T> Either<T, R> mapLeft(Function<L, T> f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map the function across the right value.
|
* Map the function across the right value.
|
||||||
|
@ -95,5 +95,5 @@ public interface Either<L, R> {
|
||||||
* @param <T> the type to change the right value to
|
* @param <T> the type to change the right value to
|
||||||
* @return a new Either
|
* @return a new Either
|
||||||
*/
|
*/
|
||||||
<T> Either<L, T> mapRight(Function<R, T> f);
|
public abstract <T> Either<L, T> mapRight(Function<R, T> f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public interface Maybe<T> extends Functor<T, Maybe<?>> {
|
||||||
* @param <T> the type of the value
|
* @param <T> the type of the value
|
||||||
* @return a Maybe of the value
|
* @return a Maybe of the value
|
||||||
*/
|
*/
|
||||||
static <T> Maybe<T> just(@NonNull final T value) {
|
public static <T> Maybe<T> just(@NonNull final T value) {
|
||||||
return new Just<>(value);
|
return new Just<>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public interface Maybe<T> extends Functor<T, Maybe<?>> {
|
||||||
* @return an empty Maybe
|
* @return an empty Maybe
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
static <T> Maybe<T> nothing() {
|
public static <T> Maybe<T> nothing() {
|
||||||
return (Maybe<T>) Nothing.INSTANCE;
|
return (Maybe<T>) Nothing.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ public interface Maybe<T> extends Functor<T, Maybe<?>> {
|
||||||
* @param <T> the type of the value
|
* @param <T> the type of the value
|
||||||
* @return a Maybe, either a Just, or Nothing if value is null
|
* @return a Maybe, either a Just, or Nothing if value is null
|
||||||
*/
|
*/
|
||||||
static <T> Maybe<T> maybe(final T value) {
|
public static <T> Maybe<T> maybe(final T value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return nothing();
|
return nothing();
|
||||||
}
|
}
|
||||||
|
@ -86,14 +86,14 @@ public interface Maybe<T> extends Functor<T, Maybe<?>> {
|
||||||
*
|
*
|
||||||
* @return true if the Maybe is a Just
|
* @return true if the Maybe is a Just
|
||||||
*/
|
*/
|
||||||
boolean isJust();
|
public abstract boolean isJust();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the Maybe is Nothing.
|
* Checks if the Maybe is Nothing.
|
||||||
*
|
*
|
||||||
* @return true if the Maybe is Nothing
|
* @return true if the Maybe is Nothing
|
||||||
*/
|
*/
|
||||||
boolean isNothing();
|
public abstract boolean isNothing();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monad binder maps the Maybe into another Maybe using the binder method f.
|
* Monad binder maps the Maybe into another Maybe using the binder method f.
|
||||||
|
@ -102,10 +102,10 @@ public interface Maybe<T> extends Functor<T, Maybe<?>> {
|
||||||
* @param <R> the type of the value in the final maybe
|
* @param <R> the type of the value in the final maybe
|
||||||
* @return a Maybe with the mapped value
|
* @return a Maybe with the mapped value
|
||||||
*/
|
*/
|
||||||
<R> Maybe<R> flatMap(Function<T, Maybe<R>> f);
|
public abstract <R> Maybe<R> flatMap(Function<T, Maybe<R>> f);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
<R> Maybe<R> map(Function<T, R> f);
|
public abstract <R> Maybe<R> map(Function<T, R> f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide a value to use when Maybe is Nothing.
|
* Provide a value to use when Maybe is Nothing.
|
||||||
|
@ -113,7 +113,7 @@ public interface Maybe<T> extends Functor<T, Maybe<?>> {
|
||||||
* @param supplier supplier for an alternate value
|
* @param supplier supplier for an alternate value
|
||||||
* @return a Maybe
|
* @return a Maybe
|
||||||
*/
|
*/
|
||||||
T orElseGet(Supplier<T> supplier);
|
public abstract T orElseGet(Supplier<T> supplier);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A value to use when Maybe is Nothing.
|
* A value to use when Maybe is Nothing.
|
||||||
|
@ -121,14 +121,14 @@ public interface Maybe<T> extends Functor<T, Maybe<?>> {
|
||||||
* @param otherValue an alternate value
|
* @param otherValue an alternate value
|
||||||
* @return the value of the Maybe if a Just, otherwise the otherValue
|
* @return the value of the Maybe if a Just, otherwise the otherValue
|
||||||
*/
|
*/
|
||||||
T orElse(T otherValue);
|
public abstract T orElse(T otherValue);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the Maybe to an {@link Optional}.
|
* Convert the Maybe to an {@link Optional}.
|
||||||
*
|
*
|
||||||
* @return an Optional containing a value for a Just, or empty for a Nothing
|
* @return an Optional containing a value for a Just, or empty for a Nothing
|
||||||
*/
|
*/
|
||||||
Optional<T> toOptional();
|
public abstract Optional<T> toOptional();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throw the exception if the Maybe is a Nothing.
|
* Throw the exception if the Maybe is a Nothing.
|
||||||
|
@ -138,14 +138,14 @@ public interface Maybe<T> extends Functor<T, Maybe<?>> {
|
||||||
* @return the value of the Maybe if a Just
|
* @return the value of the Maybe if a Just
|
||||||
* @throws X if the Maybe is nothing
|
* @throws X if the Maybe is nothing
|
||||||
*/
|
*/
|
||||||
<X extends Throwable> T orElseThrow(Supplier<? extends X> e) throws X;
|
public abstract <X extends Throwable> T orElseThrow(Supplier<? extends X> e) throws X;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the Maybe into either a single value stream or an empty stream.
|
* Converts the Maybe into either a single value stream or an empty stream.
|
||||||
*
|
*
|
||||||
* @return a Stream containing the value or nothing.
|
* @return a Stream containing the value or nothing.
|
||||||
*/
|
*/
|
||||||
Stream<T> stream();
|
public abstract Stream<T> stream();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter a Maybe by the predicate, replacing with Nothing when it fails.
|
* Filter a Maybe by the predicate, replacing with Nothing when it fails.
|
||||||
|
@ -153,7 +153,7 @@ public interface Maybe<T> extends Functor<T, Maybe<?>> {
|
||||||
* @param predicate the test
|
* @param predicate the test
|
||||||
* @return the Maybe, or Nothing if the test returns false
|
* @return the Maybe, or Nothing if the test returns false
|
||||||
*/
|
*/
|
||||||
Maybe<T> filter(Predicate<T> predicate);
|
public abstract Maybe<T> filter(Predicate<T> predicate);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide the value within the Maybe, if it exists, to the Consumer, and returns this Maybe.
|
* Provide the value within the Maybe, if it exists, to the Consumer, and returns this Maybe.
|
||||||
|
@ -161,14 +161,14 @@ public interface Maybe<T> extends Functor<T, Maybe<?>> {
|
||||||
* @param consumer the Consumer to the value if present
|
* @param consumer the Consumer to the value if present
|
||||||
* @return this Maybe
|
* @return this Maybe
|
||||||
*/
|
*/
|
||||||
Maybe<T> peek(Consumer<T> consumer);
|
public abstract Maybe<T> peek(Consumer<T> consumer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the runnable if the Maybe is a Nothing, otherwise do nothing.
|
* Run the runnable if the Maybe is a Nothing, otherwise do nothing.
|
||||||
*
|
*
|
||||||
* @param runnable the runnable to call if this is a Nothing
|
* @param runnable the runnable to call if this is a Nothing
|
||||||
*/
|
*/
|
||||||
void ifNothing(Runnable runnable);
|
public abstract void ifNothing(Runnable runnable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Matches the Maybe, either just or nothing, and performs either the Consumer, for Just, or Runnable for nothing.
|
* Matches the Maybe, either just or nothing, and performs either the Consumer, for Just, or Runnable for nothing.
|
||||||
|
@ -176,7 +176,7 @@ public interface Maybe<T> extends Functor<T, Maybe<?>> {
|
||||||
* @param justMatcher the Consumer to pass the value of a Just to
|
* @param justMatcher the Consumer to pass the value of a Just to
|
||||||
* @param nothingMatcher the Runnable to call if the Maybe is a Nothing
|
* @param nothingMatcher the Runnable to call if the Maybe is a Nothing
|
||||||
*/
|
*/
|
||||||
void match(Consumer<T> justMatcher, Runnable nothingMatcher);
|
public abstract void match(Consumer<T> justMatcher, Runnable nothingMatcher);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps the Maybe into another Maybe only when it is nothing.
|
* Maps the Maybe into another Maybe only when it is nothing.
|
||||||
|
@ -185,5 +185,5 @@ public interface Maybe<T> extends Functor<T, Maybe<?>> {
|
||||||
*
|
*
|
||||||
* @return the original Maybe if not nothing, or the alternative
|
* @return the original Maybe if not nothing, or the alternative
|
||||||
*/
|
*/
|
||||||
Maybe<T> or(Supplier<Maybe<T>> alternative);
|
public abstract Maybe<T> or(Supplier<Maybe<T>> alternative);
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
||||||
* @param <T> the type of the Maybe and the Result
|
* @param <T> the type of the Maybe and the Result
|
||||||
* @return a Result containing the value of the Maybe when it is a Just, or the error when it is Nothing
|
* @return a Result containing the value of the Maybe when it is a Just, or the error when it is Nothing
|
||||||
*/
|
*/
|
||||||
static <T> Result<T> fromMaybe(final Maybe<T> maybe, final Supplier<Throwable> error) {
|
public static <T> Result<T> fromMaybe(final Maybe<T> maybe, final Supplier<Throwable> error) {
|
||||||
return maybe.map(Result::ok)
|
return maybe.map(Result::ok)
|
||||||
.orElseGet(() -> Result.error(error.get()));
|
.orElseGet(() -> Result.error(error.get()));
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
||||||
* @param <T> the type had the result been a success
|
* @param <T> the type had the result been a success
|
||||||
* @return an error Result
|
* @return an error Result
|
||||||
*/
|
*/
|
||||||
static <T> Result<T> error(final Throwable error) {
|
public static <T> Result<T> error(final Throwable error) {
|
||||||
return new Err<>(error);
|
return new Err<>(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
||||||
* @return a Result
|
* @return a Result
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("illegalcatch")
|
@SuppressWarnings("illegalcatch")
|
||||||
static <T> Result<T> of(final Callable<T> callable) {
|
public static <T> Result<T> of(final Callable<T> callable) {
|
||||||
try {
|
try {
|
||||||
return Result.ok(callable.call());
|
return Result.ok(callable.call());
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
|
@ -83,7 +83,7 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
||||||
* @param <T> the type of the value
|
* @param <T> the type of the value
|
||||||
* @return a successful Result
|
* @return a successful Result
|
||||||
*/
|
*/
|
||||||
static <T> Result<T> ok(final T value) {
|
public static <T> Result<T> ok(final T value) {
|
||||||
return new Success<>(value);
|
return new Success<>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
||||||
* @return a Result containing the value of the Maybe when it is a Just, or the error when it is Nothing
|
* @return a Result containing the value of the Maybe when it is a Just, or the error when it is Nothing
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("illegalcatch")
|
@SuppressWarnings("illegalcatch")
|
||||||
static <T> Maybe<T> toMaybe(final Result<T> result) {
|
public static <T> Maybe<T> toMaybe(final Result<T> result) {
|
||||||
try {
|
try {
|
||||||
return Maybe.just(result.orElseThrow());
|
return Maybe.just(result.orElseThrow());
|
||||||
} catch (final Throwable throwable) {
|
} catch (final Throwable throwable) {
|
||||||
|
@ -112,7 +112,7 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
||||||
* @throws Throwable the result is an error
|
* @throws Throwable the result is an error
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("illegalthrows")
|
@SuppressWarnings("illegalthrows")
|
||||||
T orElseThrow() throws Throwable;
|
public abstract T orElseThrow() throws Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Swaps the inner Result of a Maybe, so that a Result is on the outside.
|
* Swaps the inner Result of a Maybe, so that a Result is on the outside.
|
||||||
|
@ -123,7 +123,7 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
||||||
* original Maybe. If the original Maybe is Nothing, the Result will contain Nothing. If the original Result was an
|
* original Maybe. If the original Maybe is Nothing, the Result will contain Nothing. If the original Result was an
|
||||||
* error, then the Result will also be an error.
|
* error, then the Result will also be an error.
|
||||||
*/
|
*/
|
||||||
static <T> Result<Maybe<T>> swap(final Maybe<Result<T>> maybeResult) {
|
public static <T> Result<Maybe<T>> swap(final Maybe<Result<T>> maybeResult) {
|
||||||
return maybeResult.orElseGet(() -> Result.ok(null))
|
return maybeResult.orElseGet(() -> Result.ok(null))
|
||||||
.flatMap(value -> Result.ok(Maybe.maybe(value)));
|
.flatMap(value -> Result.ok(Maybe.maybe(value)));
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
||||||
* @param <R> the type of the value withing the Result of the mapping function
|
* @param <R> the type of the value withing the Result of the mapping function
|
||||||
* @return a Result
|
* @return a Result
|
||||||
*/
|
*/
|
||||||
<R> Result<R> flatMap(Function<T, Result<R>> f);
|
public abstract <R> Result<R> flatMap(Function<T, Result<R>> f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies the function to the contents of a Maybe within the Result.
|
* Applies the function to the contents of a Maybe within the Result.
|
||||||
|
@ -146,7 +146,7 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
||||||
* @param <R> the type of the updated Result
|
* @param <R> the type of the updated Result
|
||||||
* @return a new Maybe within a Result
|
* @return a new Maybe within a Result
|
||||||
*/
|
*/
|
||||||
static <T, R> Result<Maybe<R>> flatMapMaybe(
|
public static <T, R> Result<Maybe<R>> flatMapMaybe(
|
||||||
final Result<Maybe<T>> maybeResult,
|
final Result<Maybe<T>> maybeResult,
|
||||||
final Function<Maybe<T>, Result<Maybe<R>>> f
|
final Function<Maybe<T>, Result<Maybe<R>>> f
|
||||||
) {
|
) {
|
||||||
|
@ -158,17 +158,17 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
||||||
*
|
*
|
||||||
* @return true if the Result is an error.
|
* @return true if the Result is an error.
|
||||||
*/
|
*/
|
||||||
boolean isError();
|
public abstract boolean isError();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the Result is a success.
|
* Checks if the Result is a success.
|
||||||
*
|
*
|
||||||
* @return true if the Result is a success.
|
* @return true if the Result is a success.
|
||||||
*/
|
*/
|
||||||
boolean isOkay();
|
public abstract boolean isOkay();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
<R> Result<R> map(Function<T, R> f);
|
public abstract <R> Result<R> map(Function<T, R> f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Matches the Result, either success or error, and supplies the appropriate Consumer with the value or error.
|
* Matches the Result, either success or error, and supplies the appropriate Consumer with the value or error.
|
||||||
|
@ -176,7 +176,7 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
||||||
* @param onSuccess the Consumer to pass the value of a successful Result to
|
* @param onSuccess the Consumer to pass the value of a successful Result to
|
||||||
* @param onError the Consumer to pass the error from an error Result to
|
* @param onError the Consumer to pass the error from an error Result to
|
||||||
*/
|
*/
|
||||||
void match(Consumer<T> onSuccess, Consumer<Throwable> onError);
|
public abstract void match(Consumer<T> onSuccess, Consumer<Throwable> onError);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps the value within the Result in a Maybe, either a Just if the predicate is true, or Nothing.
|
* Wraps the value within the Result in a Maybe, either a Just if the predicate is true, or Nothing.
|
||||||
|
@ -184,7 +184,7 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
||||||
* @param predicate the test to decide
|
* @param predicate the test to decide
|
||||||
* @return a Result containing a Maybe that may or may not contain a value
|
* @return a Result containing a Maybe that may or may not contain a value
|
||||||
*/
|
*/
|
||||||
Result<Maybe<T>> maybe(Predicate<T> predicate);
|
public abstract Result<Maybe<T>> maybe(Predicate<T> predicate);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide the value within the Result, if it is a success, to the Consumer, and returns this Result.
|
* Provide the value within the Result, if it is a success, to the Consumer, and returns this Result.
|
||||||
|
@ -192,7 +192,7 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
||||||
* @param consumer the Consumer to the value if a success
|
* @param consumer the Consumer to the value if a success
|
||||||
* @return this Result
|
* @return this Result
|
||||||
*/
|
*/
|
||||||
Result<T> peek(Consumer<T> consumer);
|
public abstract Result<T> peek(Consumer<T> consumer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide a way to attempt to recover from an error state.
|
* Provide a way to attempt to recover from an error state.
|
||||||
|
@ -200,7 +200,7 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
||||||
* @param f the function to recover from the error
|
* @param f the function to recover from the error
|
||||||
* @return a new Result, either a Success, or if recovery is not possible an other Err.
|
* @return a new Result, either a Success, or if recovery is not possible an other Err.
|
||||||
*/
|
*/
|
||||||
Result<T> recover(Function<Throwable, Result<T>> f);
|
public abstract Result<T> recover(Function<Throwable, Result<T>> f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A handler for error states.
|
* A handler for error states.
|
||||||
|
@ -210,7 +210,7 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
||||||
*
|
*
|
||||||
* @param errorConsumer the consumer to handle the error
|
* @param errorConsumer the consumer to handle the error
|
||||||
*/
|
*/
|
||||||
void onError(Consumer<Throwable> errorConsumer);
|
public abstract void onError(Consumer<Throwable> errorConsumer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps a Success Result to another Result using a Callable that is able to throw a checked exception.
|
* Maps a Success Result to another Result using a Callable that is able to throw a checked exception.
|
||||||
|
@ -230,7 +230,7 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
||||||
* @param <R> the type of the final Result
|
* @param <R> the type of the final Result
|
||||||
* @return a new Result
|
* @return a new Result
|
||||||
*/
|
*/
|
||||||
<R> Result<R> andThen(Function<T, Callable<R>> f);
|
public abstract <R> Result<R> andThen(Function<T, Callable<R>> f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform the continuation with the current Result value then return the current Result, assuming there was no
|
* Perform the continuation with the current Result value then return the current Result, assuming there was no
|
||||||
|
@ -250,7 +250,7 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
||||||
* @param f the function to map the Success value into the result continuation
|
* @param f the function to map the Success value into the result continuation
|
||||||
* @return the Result or a new error Result
|
* @return the Result or a new error Result
|
||||||
*/
|
*/
|
||||||
Result<T> thenWith(Function<T, WithResultContinuation<T>> f);
|
public abstract Result<T> thenWith(Function<T, WithResultContinuation<T>> f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reduce two Results of the same type into one using the reducing function provided.
|
* Reduce two Results of the same type into one using the reducing function provided.
|
||||||
|
@ -262,5 +262,5 @@ public interface Result<T> extends Functor<T, Result<?>> {
|
||||||
* @param operator the function to combine the values the Results
|
* @param operator the function to combine the values the Results
|
||||||
* @return a Result containing the combination of the two Results
|
* @return a Result containing the combination of the two Results
|
||||||
*/
|
*/
|
||||||
Result<T> reduce(Result<T> identify, BinaryOperator<T> operator);
|
public abstract Result<T> reduce(Result<T> identify, BinaryOperator<T> operator);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,10 +35,10 @@ public interface WithResultContinuation<T> {
|
||||||
*
|
*
|
||||||
* @throws Exception to replace the current Result with an error
|
* @throws Exception to replace the current Result with an error
|
||||||
*/
|
*/
|
||||||
void run() throws Exception;
|
public abstract void run() throws Exception;
|
||||||
|
|
||||||
@SuppressWarnings({"illegalcatch", "javadocmethod"})
|
@SuppressWarnings({"illegalcatch", "javadocmethod"})
|
||||||
default Result<T> call(final Result<T> currentResult) {
|
public default Result<T> call(final Result<T> currentResult) {
|
||||||
try {
|
try {
|
||||||
run();
|
run();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
|
Loading…
Reference in a new issue