Skip to content

Commit

Permalink
replaced asUnchecked method with static method
Browse files Browse the repository at this point in the history
  • Loading branch information
evpl committed Mar 9, 2024
1 parent 116777b commit 37d64a6
Show file tree
Hide file tree
Showing 52 changed files with 597 additions and 242 deletions.
74 changes: 37 additions & 37 deletions src/main/java/com/plugatar/jkscope/JKScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,41 +137,41 @@ public interface JKScope<V extends JKScope<V>> extends BaseScope<V, V> {
@Override
default V also(final ThConsumer<? super V, ?> block) {
blockArgNotNull(block);
block.asUnchecked().accept(uncheckedCast(this));
ThConsumer.unchecked(block).accept(uncheckedCast(this));
return uncheckedCast(this);
}

@Override
default V letIt(final ThConsumer<? super V, ?> block) {
blockArgNotNull(block);
block.asUnchecked().accept(uncheckedCast(this));
ThConsumer.unchecked(block).accept(uncheckedCast(this));
return uncheckedCast(this);
}

@Override
default <R> R letOut(final ThFunction<? super V, ? extends R, ?> block) {
blockArgNotNull(block);
return block.asUnchecked().apply(uncheckedCast(this));
return ThFunction.unchecked(block).apply(uncheckedCast(this));
}

@Override
default <R> Opt<R> letOpt(final ThFunction<? super V, ? extends R, ?> block) {
blockArgNotNull(block);
return Opt.of(block.asUnchecked().apply(uncheckedCast(this)));
return Opt.of(ThFunction.unchecked(block).apply(uncheckedCast(this)));
}

@Override
default Opt<V> takeIf(final ThPredicate<? super V, ?> block) {
blockArgNotNull(block);
return block.asUnchecked().test(uncheckedCast(this))
return ThPredicate.unchecked(block).test(uncheckedCast(this))
? Opt.of(uncheckedCast(this))
: Opt.empty();
}

@Override
default Opt<V> takeUnless(final ThPredicate<? super V, ?> block) {
blockArgNotNull(block);
return block.asUnchecked().test(uncheckedCast(this))
return ThPredicate.unchecked(block).test(uncheckedCast(this))
? Opt.empty()
: Opt.of(uncheckedCast(this));
}
Expand All @@ -189,7 +189,7 @@ default Opt<V> takeUnless(final ThPredicate<? super V, ?> block) {
*/
static void run(final ThRunnable<?> block) {
blockArgNotNull(block);
block.asUnchecked().run();
ThRunnable.unchecked(block).run();
}

/**
Expand All @@ -208,7 +208,7 @@ static void run(final ThRunnable<?> block) {
static void runCatching(final ThRunnable<?> block) {
blockArgNotNull(block);
try {
block.asUnchecked().run();
block.run();
} catch (final Throwable ignored) { }
}

Expand All @@ -229,7 +229,7 @@ static void runRec(final ThConsumer<ThRunnable<Throwable>, ?> block) {
blockArgNotNull(block);
final AtomicReference<ThRunnable<Throwable>> selfRef = new AtomicReference<>();
selfRef.set(() -> block.accept(selfRef.get()));
block.asUnchecked().accept(selfRef.get());
ThConsumer.unchecked(block).accept(selfRef.get());
}

/**
Expand All @@ -248,7 +248,7 @@ static void runRec(final ThConsumer<ThRunnable<Throwable>, ?> block) {
static <V> void with(final V value,
final ThConsumer<? super V, ?> block) {
blockArgNotNull(block);
block.asUnchecked().accept(value);
ThConsumer.unchecked(block).accept(value);
}

/**
Expand All @@ -266,7 +266,7 @@ static <V> void with(final V value,
static void withInt(final int value,
final ThIntConsumer<?> block) {
blockArgNotNull(block);
block.asUnchecked().accept(value);
ThIntConsumer.unchecked(block).accept(value);
}

/**
Expand All @@ -284,7 +284,7 @@ static void withInt(final int value,
static void withLong(final long value,
final ThLongConsumer<?> block) {
blockArgNotNull(block);
block.asUnchecked().accept(value);
ThLongConsumer.unchecked(block).accept(value);
}

/**
Expand All @@ -302,7 +302,7 @@ static void withLong(final long value,
static void withDouble(final double value,
final ThDoubleConsumer<?> block) {
blockArgNotNull(block);
block.asUnchecked().accept(value);
ThDoubleConsumer.unchecked(block).accept(value);
}

/**
Expand All @@ -319,11 +319,11 @@ static void withDouble(final double value,
static <V extends AutoCloseable> void withResource(final V value,
final ThConsumer<? super V, ?> block) {
blockArgNotNull(block);
((ThBiConsumer<V, ThConsumer<? super V, ?>, Throwable>) (v, b) -> {
ThBiConsumer.<V, ThConsumer<? super V, ?>>unchecked((v, b) -> {
try (final V resource = v) {
b.accept(resource);
}
}).asUnchecked().accept(value, block);
}).accept(value, block);
}

/**
Expand All @@ -345,7 +345,7 @@ static <V1, V2> void with(final V1 value1,
final V2 value2,
final ThBiConsumer<? super V1, ? super V2, ?> block) {
blockArgNotNull(block);
block.asUnchecked().accept(value1, value2);
ThBiConsumer.unchecked(block).accept(value1, value2);
}

/**
Expand All @@ -370,7 +370,7 @@ static <V1, V2, V3> void with(final V1 value1,
final V3 value3,
final ThTriConsumer<? super V1, ? super V2, ? super V3, ?> block) {
blockArgNotNull(block);
block.asUnchecked().accept(value1, value2, value3);
ThTriConsumer.unchecked(block).accept(value1, value2, value3);
}

/**
Expand Down Expand Up @@ -418,7 +418,7 @@ static <V> Opt<V> letNonNull(final V value) {
*/
static <V> V let(final ThSupplier<? extends V, ?> block) {
blockArgNotNull(block);
return block.asUnchecked().get();
return ThSupplier.unchecked(block).get();
}

/**
Expand All @@ -436,7 +436,7 @@ static <V> V let(final ThSupplier<? extends V, ?> block) {
*/
static int letInt(final ThIntSupplier<?> block) {
blockArgNotNull(block);
return block.asUnchecked().get();
return ThIntSupplier.unchecked(block).get();
}

/**
Expand All @@ -454,7 +454,7 @@ static int letInt(final ThIntSupplier<?> block) {
*/
static long letLong(final ThLongSupplier<?> block) {
blockArgNotNull(block);
return block.asUnchecked().get();
return ThLongSupplier.unchecked(block).get();
}

/**
Expand All @@ -472,7 +472,7 @@ static long letLong(final ThLongSupplier<?> block) {
*/
static double letDouble(final ThDoubleSupplier<?> block) {
blockArgNotNull(block);
return block.asUnchecked().get();
return ThDoubleSupplier.unchecked(block).get();
}

/**
Expand All @@ -492,7 +492,7 @@ static double letDouble(final ThDoubleSupplier<?> block) {
static <V> V let(final V value,
final ThConsumer<? super V, ?> block) {
blockArgNotNull(block);
block.asUnchecked().accept(value);
ThConsumer.unchecked(block).accept(value);
return value;
}

Expand All @@ -512,7 +512,7 @@ static <V> V let(final V value,
static int letInt(final int value,
final ThIntConsumer<?> block) {
blockArgNotNull(block);
block.asUnchecked().accept(value);
ThIntConsumer.unchecked(block).accept(value);
return value;
}

Expand All @@ -532,7 +532,7 @@ static int letInt(final int value,
static long letLong(final long value,
final ThLongConsumer<?> block) {
blockArgNotNull(block);
block.asUnchecked().accept(value);
ThLongConsumer.unchecked(block).accept(value);
return value;
}

Expand All @@ -552,7 +552,7 @@ static long letLong(final long value,
static double letDouble(final double value,
final ThDoubleConsumer<?> block) {
blockArgNotNull(block);
block.asUnchecked().accept(value);
ThDoubleConsumer.unchecked(block).accept(value);
return value;
}

Expand All @@ -578,7 +578,7 @@ static <V> V letRec(final V initialValue,
blockArgNotNull(block);
final AtomicReference<ThFunction<V, V, Throwable>> selfRef = new AtomicReference<>();
selfRef.set(v -> block.apply(v, selfRef.get()));
return block.asUnchecked().apply(initialValue, selfRef.get());
return ThBiFunction.unchecked(block).apply(initialValue, selfRef.get());
}

/**
Expand All @@ -602,7 +602,7 @@ static int letIntRec(final int initialValue,
blockArgNotNull(block);
final AtomicReference<ThIntToIntFunction<Throwable>> selfRef = new AtomicReference<>();
selfRef.set(v -> block.apply(v, selfRef.get()));
return block.asUnchecked().apply(initialValue, selfRef.get());
return ThIntObjToIntFunction.unchecked(block).apply(initialValue, selfRef.get());
}

/**
Expand All @@ -626,7 +626,7 @@ static long letLongRec(final long initialValue,
blockArgNotNull(block);
final AtomicReference<ThLongToLongFunction<Throwable>> selfRef = new AtomicReference<>();
selfRef.set(v -> block.apply(v, selfRef.get()));
return block.asUnchecked().apply(initialValue, selfRef.get());
return ThLongObjToLongFunction.unchecked(block).apply(initialValue, selfRef.get());
}

/**
Expand All @@ -650,7 +650,7 @@ static double letDoubleRec(final double initialValue,
blockArgNotNull(block);
final AtomicReference<ThDoubleToDoubleFunction<Throwable>> selfRef = new AtomicReference<>();
selfRef.set(v -> block.apply(v, selfRef.get()));
return block.asUnchecked().apply(initialValue, selfRef.get());
return ThDoubleObjToDoubleFunction.unchecked(block).apply(initialValue, selfRef.get());
}

/**
Expand All @@ -672,7 +672,7 @@ static double letDoubleRec(final double initialValue,
static <V, R> R letWith(final V value,
final ThFunction<? super V, ? extends R, ?> block) {
blockArgNotNull(block);
return block.asUnchecked().apply(value);
return ThFunction.unchecked(block).apply(value);
}

/**
Expand All @@ -692,7 +692,7 @@ static <V, R> R letWith(final V value,
static <V> int letIntWith(final V value,
final ThToIntFunction<? super V, ?> block) {
blockArgNotNull(block);
return block.asUnchecked().apply(value);
return ThToIntFunction.unchecked(block).apply(value);
}

/**
Expand All @@ -712,7 +712,7 @@ static <V> int letIntWith(final V value,
static <V> long letLongWith(final V value,
final ThToLongFunction<? super V, ?> block) {
blockArgNotNull(block);
return block.asUnchecked().apply(value);
return ThToLongFunction.unchecked(block).apply(value);
}

/**
Expand All @@ -732,7 +732,7 @@ static <V> long letLongWith(final V value,
static <V> double letDoubleWith(final V value,
final ThToDoubleFunction<? super V, ?> block) {
blockArgNotNull(block);
return block.asUnchecked().apply(value);
return ThToDoubleFunction.unchecked(block).apply(value);
}

/**
Expand All @@ -751,11 +751,11 @@ static <V> double letDoubleWith(final V value,
static <V extends AutoCloseable, R> R letWithResource(final V value,
final ThFunction<? super V, ? extends R, ?> block) {
blockArgNotNull(block);
return ((ThBiFunction<V, ThFunction<? super V, ? extends R, ?>, R, Throwable>) (v, b) -> {
return ThBiFunction.<V, ThFunction<? super V, ? extends R, ?>, R>unchecked((v, b) -> {
try (final V resource = v) {
return b.apply(resource);
}
}).asUnchecked().apply(value, block);
}).apply(value, block);
}

/**
Expand All @@ -781,7 +781,7 @@ static <V1, V2, R> R letWith(final V1 value1,
final V2 value2,
final ThBiFunction<? super V1, ? super V2, ? extends R, ?> block) {
blockArgNotNull(block);
return block.asUnchecked().apply(value1, value2);
return ThBiFunction.unchecked(block).apply(value1, value2);
}

/**
Expand Down Expand Up @@ -811,7 +811,7 @@ static <V1, V2, V3, R> R letWith(final V1 value1,
final V3 value3,
final ThTriFunction<? super V1, ? super V2, ? super V3, ? extends R, ?> block) {
blockArgNotNull(block);
return block.asUnchecked().apply(value1, value2, value3);
return ThTriFunction.unchecked(block).apply(value1, value2, value3);
}

/**
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/plugatar/jkscope/Lazy.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,34 @@ public interface Lazy<V> extends ThSupplier<V, RuntimeException>, BaseScope<V, L
@Override
default Lazy<V> also(final ThConsumer<? super V, ?> block) {
blockArgNotNull(block);
block.asUnchecked().accept(this.get());
ThConsumer.unchecked(block).accept(this.get());
return this;
}

@Override
default Lazy<V> letIt(final ThConsumer<? super V, ?> block) {
blockArgNotNull(block);
block.asUnchecked().accept(this.get());
ThConsumer.unchecked(block).accept(this.get());
return this;
}

@Override
default <R> R letOut(final ThFunction<? super V, ? extends R, ?> block) {
blockArgNotNull(block);
return block.asUnchecked().apply(this.get());
return ThFunction.unchecked(block).apply(this.get());
}

@Override
default <R> Opt<R> letOpt(final ThFunction<? super V, ? extends R, ?> block) {
blockArgNotNull(block);
return Opt.of(block.asUnchecked().apply(this.get()));
return Opt.of(ThFunction.unchecked(block).apply(this.get()));
}

@Override
default Opt<V> takeIf(final ThPredicate<? super V, ?> block) {
blockArgNotNull(block);
final V v = this.get();
return block.asUnchecked().test(v)
return ThPredicate.unchecked(block).test(v)
? Opt.of(v)
: Opt.empty();
}
Expand All @@ -74,7 +74,7 @@ default Opt<V> takeIf(final ThPredicate<? super V, ?> block) {
default Opt<V> takeUnless(final ThPredicate<? super V, ?> block) {
blockArgNotNull(block);
final V v = this.get();
return block.asUnchecked().test(v)
return ThPredicate.unchecked(block).test(v)
? Opt.empty()
: Opt.of(v);
}
Expand Down Expand Up @@ -210,7 +210,7 @@ public V get() {
if (v2 != UNINITIALIZED_VALUE) {
return uncheckedCast(v2);
}
final V newValue = this.initializer.asUnchecked().get();
final V newValue = ThSupplier.unchecked(this.initializer).get();
this.value = newValue;
this.initializer = null;
return newValue;
Expand Down Expand Up @@ -264,7 +264,7 @@ public V get() {
}
final ThSupplier<? extends V, ?> init = this.initializer;
if (init != null) {
final V newValue = init.asUnchecked().get();
final V newValue = ThSupplier.unchecked(init).get();
if (VALUE_UPDATER.compareAndSet(this, UNINITIALIZED_VALUE, newValue)) {
this.initializer = null;
return newValue;
Expand Down Expand Up @@ -318,7 +318,7 @@ public V get() {
}
final ThSupplier<? extends V, ?> init = this.initializer;
if (init != null) {
final V newValue = init.asUnchecked().get();
final V newValue = ThSupplier.unchecked(init).get();
this.value = newValue;
this.initializer = null;
return newValue;
Expand Down
Loading

0 comments on commit 37d64a6

Please sign in to comment.