Skip to content

Commit

Permalink
0.9.80
Browse files Browse the repository at this point in the history
  • Loading branch information
landawn committed Aug 19, 2017
1 parent 2d54d9b commit 358ffa6
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 53 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

========Changes in 0.9.80=========================================================================

1, Improvements and bug fix.


========Changes in 0.9.79=========================================================================

1, Add select to Stream.
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 6 additions & 1 deletion src/com/landawn/abacus/util/CompletableFuture.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ public static CompletableFuture<Void> run(final Runnable action, final Executor
}

public static <T> CompletableFuture<T> run(final Try.Callable<T, RuntimeException> action, final Executor executor) {
final FutureTask<T> futureTask = new FutureTask<>(action);
final FutureTask<T> futureTask = new FutureTask<>(new Callable<T>() {
@Override
public T call() throws Exception {
return action.call();
}
});

executor.execute(futureTask);

Expand Down
104 changes: 52 additions & 52 deletions src/com/landawn/abacus/util/Try.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public static <T extends AutoCloseable> Try<T> of(final T t) {
return new Try<>(t);
}

public static <T extends AutoCloseable> Try<T> of(final Supplier<T, ? extends Exception> supplier) {
public static <T extends AutoCloseable> Try<T> of(final Supplier<T, ? extends Throwable> supplier) {
try {
return new Try<>(supplier.get());
} catch (Exception e) {
} catch (Throwable e) {
throw N.toRuntimeException(e);
}
}
Expand Down Expand Up @@ -83,7 +83,7 @@ public void run() {
// public void run() {
// try {
// run.run();
// } catch (Exception e) {
// } catch (Throwable e) {
// throw N.toRuntimeException(e);
// }
// }
Expand All @@ -96,7 +96,7 @@ public void run() {
// public R call() {
// try {
// return call.call();
// } catch (Exception e) {
// } catch (Throwable e) {
// throw N.toRuntimeException(e);
// }
// }
Expand All @@ -108,20 +108,20 @@ public void run() {
* @param cmd
* @throws RuntimeException if some error happens
*/
public static void run(final Try.Runnable<? extends Exception> cmd) {
public static void run(final Try.Runnable<? extends Throwable> cmd) {
try {
cmd.run();
} catch (Exception e) {
} catch (Throwable e) {
throw N.toRuntimeException(e);
}
}

public static void run(final Try.Runnable<? extends Exception> cmd, final com.landawn.abacus.util.function.Consumer<? super Exception> actionOnError) {
public static void run(final Try.Runnable<? extends Throwable> cmd, final com.landawn.abacus.util.function.Consumer<? super Throwable> actionOnError) {
N.requireNonNull(actionOnError);

try {
cmd.run();
} catch (Exception e) {
} catch (Throwable e) {
actionOnError.accept(e);
}
}
Expand All @@ -132,38 +132,39 @@ public static void run(final Try.Runnable<? extends Exception> cmd, final com.la
* @return
* @throws RuntimeException if some error happens
*/
public static <R> R call(final java.util.concurrent.Callable<R> cmd) {
public static <R> R call(final Try.Callable<R, ? extends Throwable> cmd) {
try {
return cmd.call();
} catch (Exception e) {
} catch (Throwable e) {
throw N.toRuntimeException(e);
}
}

public static <R> R call(final java.util.concurrent.Callable<R> cmd, final com.landawn.abacus.util.function.Function<? super Exception, R> actionOnError) {
public static <R> R call(final Try.Callable<R, ? extends Throwable> cmd,
final com.landawn.abacus.util.function.Function<? super Throwable, R> actionOnError) {
N.requireNonNull(actionOnError);

try {
return cmd.call();
} catch (Exception e) {
} catch (Throwable e) {
return actionOnError.apply(e);
}
}

public static <R> R call(final java.util.concurrent.Callable<R> cmd, final com.landawn.abacus.util.function.Supplier<R> supplier) {
public static <R> R call(final Try.Callable<R, ? extends Throwable> cmd, final com.landawn.abacus.util.function.Supplier<R> supplier) {
N.requireNonNull(supplier);

try {
return cmd.call();
} catch (Exception e) {
} catch (Throwable e) {
return supplier.get();
}
}

public static <R> R call(final java.util.concurrent.Callable<R> cmd, final R defaultValue) {
public static <R> R call(final Try.Callable<R, ? extends Throwable> cmd, final R defaultValue) {
try {
return cmd.call();
} catch (Exception e) {
} catch (Throwable e) {
return defaultValue;
}
}
Expand All @@ -176,14 +177,14 @@ public static <R> R call(final java.util.concurrent.Callable<R> cmd, final R def
* @return the value returned <code>Supplier.get()</code> if some error happens and <code>predicate</code> return true.
* @throws RuntimeException if some error happens and <code>predicate</code> return false.
*/
public static <R> R call(final java.util.concurrent.Callable<R> cmd, final com.landawn.abacus.util.function.Predicate<? super Exception> predicate,
public static <R> R call(final Try.Callable<R, ? extends Throwable> cmd, final com.landawn.abacus.util.function.Predicate<? super Throwable> predicate,
final com.landawn.abacus.util.function.Supplier<R> supplier) {
N.requireNonNull(predicate);
N.requireNonNull(supplier);

try {
return cmd.call();
} catch (Exception e) {
} catch (Throwable e) {
if (predicate.test(e)) {
return supplier.get();
} else {
Expand All @@ -200,13 +201,13 @@ public static <R> R call(final java.util.concurrent.Callable<R> cmd, final com.l
* @return the <code>defaultValue()</code> if some error happens and <code>predicate</code> return true.
* @throws RuntimeException if some error happens and <code>predicate</code> return false.
*/
public static <R> R call(final java.util.concurrent.Callable<R> cmd, final com.landawn.abacus.util.function.Predicate<? super Exception> predicate,
public static <R> R call(final Try.Callable<R, ? extends Throwable> cmd, final com.landawn.abacus.util.function.Predicate<? super Throwable> predicate,
final R defaultValue) {
N.requireNonNull(predicate);

try {
return cmd.call();
} catch (Exception e) {
} catch (Throwable e) {
if (predicate.test(e)) {
return defaultValue;
} else {
Expand All @@ -215,81 +216,81 @@ public static <R> R call(final java.util.concurrent.Callable<R> cmd, final com.l
}
}

public void run(final Try.Consumer<? super T, ? extends Exception> cmd) {
public void run(final Try.Consumer<? super T, ? extends Throwable> cmd) {
try {
cmd.accept(t);
} catch (Exception e) {
} catch (Throwable e) {
throw N.toRuntimeException(e);
} finally {
IOUtil.close(t);
}
}

public void run(final Try.Consumer<? super T, ? extends Exception> cmd, final com.landawn.abacus.util.function.Consumer<? super Exception> actionOnError) {
public void run(final Try.Consumer<? super T, ? extends Throwable> cmd, final com.landawn.abacus.util.function.Consumer<? super Throwable> actionOnError) {
N.requireNonNull(actionOnError);

try {
cmd.accept(t);
} catch (Exception e) {
} catch (Throwable e) {
actionOnError.accept(e);
} finally {
IOUtil.close(t);
}
}

public <R> R call(final Try.Function<? super T, R, ? extends Exception> cmd) {
public <R> R call(final Try.Function<? super T, R, ? extends Throwable> cmd) {
try {
return cmd.apply(t);
} catch (Exception e) {
} catch (Throwable e) {
throw N.toRuntimeException(e);
} finally {
IOUtil.close(t);
}
}

public <R> R call(final Try.Function<? super T, R, ? extends Exception> cmd,
final com.landawn.abacus.util.function.Function<? super Exception, R> actionOnError) {
public <R> R call(final Try.Function<? super T, R, ? extends Throwable> cmd,
final com.landawn.abacus.util.function.Function<? super Throwable, R> actionOnError) {
N.requireNonNull(actionOnError);

try {
return cmd.apply(t);
} catch (Exception e) {
} catch (Throwable e) {
return actionOnError.apply(e);
} finally {
IOUtil.close(t);
}
}

public <R> R call(final Try.Function<? super T, R, ? extends Exception> cmd, final com.landawn.abacus.util.function.Supplier<R> supplier) {
public <R> R call(final Try.Function<? super T, R, ? extends Throwable> cmd, final com.landawn.abacus.util.function.Supplier<R> supplier) {
N.requireNonNull(supplier);

try {
return cmd.apply(t);
} catch (Exception e) {
} catch (Throwable e) {
return supplier.get();
} finally {
IOUtil.close(t);
}
}

public <R> R call(final Try.Function<? super T, R, ? extends Exception> cmd, final R defaultValue) {
public <R> R call(final Try.Function<? super T, R, ? extends Throwable> cmd, final R defaultValue) {
try {
return cmd.apply(t);
} catch (Exception e) {
} catch (Throwable e) {
return defaultValue;
} finally {
IOUtil.close(t);
}
}

public <R> R call(final Try.Function<? super T, R, ? extends Exception> cmd, final com.landawn.abacus.util.function.Predicate<? super Exception> predicate,
public <R> R call(final Try.Function<? super T, R, ? extends Throwable> cmd, final com.landawn.abacus.util.function.Predicate<? super Throwable> predicate,
final com.landawn.abacus.util.function.Supplier<R> supplier) {
N.requireNonNull(predicate);
N.requireNonNull(supplier);

try {
return cmd.apply(t);
} catch (Exception e) {
} catch (Throwable e) {
if (predicate.test(e)) {
return supplier.get();
} else {
Expand All @@ -300,13 +301,13 @@ public <R> R call(final Try.Function<? super T, R, ? extends Exception> cmd, fin
}
}

public <R> R call(final Try.Function<? super T, R, ? extends Exception> cmd, final com.landawn.abacus.util.function.Predicate<? super Exception> predicate,
public <R> R call(final Try.Function<? super T, R, ? extends Throwable> cmd, final com.landawn.abacus.util.function.Predicate<? super Throwable> predicate,
final R defaultValue) {
N.requireNonNull(predicate);

try {
return cmd.apply(t);
} catch (Exception e) {
} catch (Throwable e) {
if (predicate.test(e)) {
return defaultValue;
} else {
Expand All @@ -317,60 +318,59 @@ public <R> R call(final Try.Function<? super T, R, ? extends Exception> cmd, fin
}
}

public static interface Callable<R, E extends Exception> extends java.util.concurrent.Callable<R> {
@Override
R call() throws E;
public static interface Runnable<E extends Throwable> {
void run() throws E;
}

public static interface Runnable<E extends Exception> {
void run() throws E;
public static interface Callable<R, E extends Throwable> {
R call() throws E;
}

public static interface Supplier<T, E extends Exception> {
public static interface Supplier<T, E extends Throwable> {
T get() throws E;
}

public static interface Predicate<T, E extends Exception> {
public static interface Predicate<T, E extends Throwable> {
boolean test(T t) throws E;

default Predicate<T, E> negate() throws E {
return (t) -> !test(t);
}
}

public static interface BiPredicate<T, U, E extends Exception> {
public static interface BiPredicate<T, U, E extends Throwable> {
boolean test(T t, U u) throws E;

default BiPredicate<T, U, E> negate() throws E {
return (T t, U u) -> !test(t, u);
}
}

public static interface TriPredicate<A, B, C, E extends Exception> {
public static interface TriPredicate<A, B, C, E extends Throwable> {
boolean test(A a, B b, C c) throws E;
}

public static interface Function<T, R, E extends Exception> {
public static interface Function<T, R, E extends Throwable> {
R apply(T t) throws E;
}

public static interface BiFunction<T, U, R, E extends Exception> {
public static interface BiFunction<T, U, R, E extends Throwable> {
R apply(T t, U u) throws E;
}

public static interface TriFunction<A, B, C, R, E extends Exception> {
public static interface TriFunction<A, B, C, R, E extends Throwable> {
R apply(A a, B b, C c) throws E;
}

public static interface Consumer<T, E extends Exception> {
public static interface Consumer<T, E extends Throwable> {
void accept(T t) throws E;
}

public static interface BiConsumer<T, U, E extends Exception> {
public static interface BiConsumer<T, U, E extends Throwable> {
void accept(T t, U u) throws E;
}

public static interface TriConsumer<A, B, C, E extends Exception> {
public static interface TriConsumer<A, B, C, E extends Throwable> {
void accept(A a, B b, C c) throws E;
}
}

0 comments on commit 358ffa6

Please sign in to comment.