add doc comment

dev
ehlxr 2020-12-22 23:07:35 +08:00
parent c7c1cc0648
commit d2ffda2813
1 changed files with 60 additions and 8 deletions

View File

@ -36,18 +36,46 @@ import java.util.function.Consumer;
* @since 2020-12-03 10:37.
*/
public interface Try {
/**
* Tryable
*
* @param consumer {@link ThrowableConsumer}
* @param <T>
* @return {@link TryConsumer}
*/
static <T> TryConsumer<T> of(ThrowableConsumer<? super T> consumer) {
return new TryConsumer<>(consumer);
}
/**
* Tryable
*
* @param supplier {@link ThrowableSupplier}
* @param <R>
* @return {@link TrySupplier}
*/
static <R> TrySupplier<R> of(ThrowableSupplier<? extends R> supplier) {
return new TrySupplier<>(supplier);
}
/**
* Tryable
*
* @param function {@link ThrowableFunction}
* @param <T>
* @param <R>
* @return {@link TryFunction}
*/
static <T, R> TryFunction<T, R> of(ThrowableFunction<? super T, ? extends R> function) {
return new TryFunction<>(function);
}
/**
* Tryable
*
* @param runnable {@link ThrowableRunnable}
* @return {@link TryRunnable}
*/
static TryRunnable of(ThrowableRunnable runnable) {
return new TryRunnable(runnable);
}
@ -61,7 +89,7 @@ public interface Try {
/**
* finally
*/
protected void _finally() {
protected void doFinally() {
Optional.ofNullable(finallyRunnable).ifPresent(r -> {
try {
r.run();
@ -127,7 +155,7 @@ public interface Try {
} catch (final Throwable e) {
Optional.ofNullable(throwConsumer).ifPresent(c -> c.accept(e));
} finally {
_finally();
doFinally();
}
}
}
@ -155,7 +183,7 @@ public interface Try {
} catch (final Throwable e) {
Optional.ofNullable(throwConsumer).ifPresent(c -> c.accept(e));
} finally {
_finally();
doFinally();
}
}
}
@ -183,7 +211,7 @@ public interface Try {
Optional.ofNullable(throwConsumer).ifPresent(c -> c.accept(e));
return r;
} finally {
_finally();
doFinally();
}
}
@ -199,7 +227,7 @@ public interface Try {
Optional.ofNullable(throwConsumer).ifPresent(c -> c.accept(e));
return null;
} finally {
_finally();
doFinally();
}
}
}
@ -222,7 +250,7 @@ public interface Try {
* @return {@link TryFunction}
*/
public TryFunction<T, R> apply(T t) {
Objects.requireNonNull(t, "Apply t shoud not null");
Objects.requireNonNull(t, "Apply t should not null");
this.t = t;
return this;
@ -243,7 +271,7 @@ public interface Try {
Optional.ofNullable(throwConsumer).ifPresent(c -> c.accept(e));
return r;
} finally {
_finally();
doFinally();
}
}
@ -261,28 +289,52 @@ public interface Try {
Optional.ofNullable(throwConsumer).ifPresent(c -> c.accept(e));
return null;
} finally {
_finally();
doFinally();
}
}
}
@FunctionalInterface
interface ThrowableRunnable {
/**
* Performs this operation
*
* @throws Throwable throwable
*/
void run() throws Throwable;
}
@FunctionalInterface
interface ThrowableConsumer<T> {
/**
* Performs this operation on the given argument.
*
* @param t the input argument
* @throws Throwable throwable
*/
void accept(T t) throws Throwable;
}
@FunctionalInterface
interface ThrowableSupplier<T> {
/**
* Gets a result.
*
* @return a result
* @throws Throwable throwable
*/
T get() throws Throwable;
}
@FunctionalInterface
interface ThrowableFunction<T, R> {
/**
* Applies this function to the given argument.
*
* @param t the function argument
* @return the function result
* @throws Throwable throwable
*/
R apply(T t) throws Throwable;
}