Skip to content

Commit 73fb0c0

Browse files
author
Grzegorz Piwowarek
committed
Refactor names
1 parent 180ba0d commit 73fb0c0

File tree

9 files changed

+36
-53
lines changed

9 files changed

+36
-53
lines changed

src/main/java/pl/touk/throwing/ThrowingBiConsumer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ default ThrowingBiFunction<T, U, Void, E> asFunction() {
5959
static <T, U, E extends Exception> BiConsumer<T, U> unchecked(ThrowingBiConsumer<T, U, E> consumer) {
6060
Objects.requireNonNull(consumer);
6161

62-
return consumer.unchecked();
62+
return consumer.uncheck();
6363
}
6464

6565
/**
6666
* Returns a new BiConsumer instance which wraps thrown checked exception instance into a RuntimeException
6767
* @return BiConsumer instance that packages checked exceptions into RuntimeException instances
6868
*/
69-
default BiConsumer<T, U> unchecked() {
69+
default BiConsumer<T, U> uncheck() {
7070
return (arg1, arg2) -> {
7171
try {
7272
accept(arg1, arg2);

src/main/java/pl/touk/throwing/ThrowingBiFunction.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@
3838
public interface ThrowingBiFunction<T1, T2, R, E extends Throwable> {
3939
R apply(T1 arg1, T2 arg2) throws E;
4040

41+
static <T1, T2, R, E extends Throwable> BiFunction<T1, T2, R> unchecked(ThrowingBiFunction<T1, T2, R, E> function) {
42+
Objects.requireNonNull(function);
43+
44+
return function.unchecked();
45+
}
46+
47+
static <T1, T2, R, E extends Exception> BiFunction<T1, T2, Optional<R>> lifted(ThrowingBiFunction<T1, T2, R, E> f) {
48+
Objects.requireNonNull(f);
49+
50+
return f.lift();
51+
}
52+
4153
/**
4254
* Performs provided action on the result of this ThrowingBiFunction instance
4355
* @param after action that is supposed to be made on the result of apply()
@@ -50,12 +62,6 @@ default <V> ThrowingBiFunction<T1, T2, V, E> andThen(final ThrowingFunction<? su
5062
return (arg1, arg2) -> after.apply(apply(arg1, arg2));
5163
}
5264

53-
static <T1, T2, R, E extends Throwable> BiFunction<T1, T2, R> unchecked(ThrowingBiFunction<T1, T2, R, E> function) {
54-
Objects.requireNonNull(function);
55-
56-
return function.unchecked();
57-
}
58-
5965
default BiFunction<T1, T2, R> unchecked() {
6066
return (arg1, arg2) -> {
6167
try {
@@ -75,10 +81,4 @@ default BiFunction<T1, T2, Optional<R>> lift() {
7581
}
7682
};
7783
}
78-
79-
static <T1, T2, R, E extends Exception> BiFunction<T1, T2, Optional<R>> lifted(ThrowingBiFunction<T1, T2, R, E> f) {
80-
Objects.requireNonNull(f);
81-
82-
return f.lift();
83-
}
8484
}

src/main/java/pl/touk/throwing/ThrowingBiPredicate.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
public interface ThrowingBiPredicate<T, U, E extends Throwable> {
3434
boolean test(T t, U u) throws E;
3535

36+
static <T, U, E extends Exception> BiPredicate<T, U> unchecked(ThrowingBiPredicate<T, U, E> predicate) {
37+
Objects.requireNonNull(predicate);
38+
39+
return predicate.uncheck();
40+
}
41+
3642
default ThrowingBiPredicate<T, U, E> and(final ThrowingBiPredicate<? super T, ? super U, E> other) {
3743
Objects.requireNonNull(other);
3844

@@ -62,16 +68,10 @@ default ThrowingBiFunction<T, U, Boolean, E> asFunction() {
6268
return this::test;
6369
}
6470

65-
static <T, U, E extends Exception> BiPredicate<T, U> unchecked(ThrowingBiPredicate<T, U, E> predicate) {
66-
Objects.requireNonNull(predicate);
67-
68-
return predicate.unchecked();
69-
}
70-
7171
/**
7272
* @return a new BiPredicate instance which wraps thrown checked exception instance into a RuntimeException
7373
*/
74-
default BiPredicate<T, U> unchecked() {
74+
default BiPredicate<T, U> uncheck() {
7575
return (arg1, arg2) -> {
7676
try {
7777
return test(arg1, arg2);

src/main/java/pl/touk/throwing/ThrowingConsumer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public interface ThrowingConsumer<T, E extends Throwable> {
3333

3434
void accept(T t) throws E;
3535

36+
static <T, E extends Throwable> Consumer<T> unchecked(ThrowingConsumer<T, E> consumer) {
37+
Objects.requireNonNull(consumer);
38+
39+
return consumer.uncheck();
40+
}
41+
3642
/**
3743
* Chains given ThrowingConsumer instance
3844
* @param after - consumer that is chained after this instance
@@ -57,16 +63,10 @@ default ThrowingFunction<T, Void, E> asFunction() {
5763
};
5864
}
5965

60-
static <T, E extends Throwable> Consumer<T> unchecked(ThrowingConsumer<T, E> consumer) {
61-
Objects.requireNonNull(consumer);
62-
63-
return consumer.unchecked();
64-
}
65-
6666
/**
6767
* @return a Consumer instance which wraps thrown checked exception instance into a RuntimeException
6868
*/
69-
default Consumer<T> unchecked() {
69+
default Consumer<T> uncheck() {
7070
return t -> {
7171
try {
7272
accept(t);

src/main/java/pl/touk/throwing/ThrowingSupplier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ default ThrowingFunction<Void, T, E> asFunction() {
4343
static <T, E extends Exception> Supplier<T> unchecked(ThrowingSupplier<T, E> supplier) {
4444
Objects.requireNonNull(supplier);
4545

46-
return supplier.unchecked();
46+
return supplier.uncheck();
4747
}
4848

4949
static <T, E extends Exception> Supplier<Optional<T>> lifted(ThrowingSupplier<T, E> supplier) {
@@ -55,7 +55,7 @@ static <T, E extends Exception> Supplier<Optional<T>> lifted(ThrowingSupplier<T,
5555
/**
5656
* @return a new Supplier instance which wraps thrown checked exception instance into a RuntimeException
5757
*/
58-
default Supplier<T> unchecked() {
58+
default Supplier<T> uncheck() {
5959
return () -> {
6060
try {
6161
return get();

src/main/java/pl/touk/throwing/ThrowingUnaryOperator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
@FunctionalInterface
3535
public interface ThrowingUnaryOperator<T, E extends Throwable> extends ThrowingFunction<T, T, E> {
3636

37-
static <T, E extends Exception> UnaryOperator<T> uncheck(ThrowingUnaryOperator<T, E> operator) {
37+
static <T, E extends Exception> UnaryOperator<T> unchecked(ThrowingUnaryOperator<T, E> operator) {
3838
Objects.requireNonNull(operator);
3939

4040
return operator.uncheck();

src/test/java/pl/touk/throwing/ThrowingBiPredicateTest.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,8 @@ public void shouldTestWhenUsingUncheck() throws Exception {
9797
final ThrowingBiPredicate<Integer, Integer, Exception> predicate = (i, j) -> true;
9898

9999
// when
100-
predicate.unchecked().test(1, 2);
100+
predicate.uncheck().test(1, 2);
101101

102102
// then no exception is thrown
103103
}
104-
105-
@Test(expected = RuntimeException.class)
106-
public void shouldWrapInRuntimeExWhenUsingUncheck() throws Exception {
107-
// given
108-
final ThrowingBiPredicate<Integer, Integer, Exception> predicate = (i, j) -> {
109-
throw new Exception();
110-
};
111-
112-
// when
113-
predicate.unchecked().test(0, 2);
114-
115-
// then RuntimeException is thrown
116-
}
117-
118-
119-
120-
121104
}

src/test/java/pl/touk/throwing/ThrowingSupplierTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void shouldGetUnchecked() throws Exception {
6464
final ThrowingSupplier<Integer, IOException> supplier = () -> 42;
6565

6666
// when
67-
final Integer result = supplier.unchecked().get();
67+
final Integer result = supplier.uncheck().get();
6868

6969
// then
7070
assertThat(result).isEqualTo(42);
@@ -76,7 +76,7 @@ public void shouldGetUncheckedAndThrow() throws Exception {
7676
final ThrowingSupplier<Integer, IOException> supplier = () -> { throw new IOException(); };
7777

7878
// when
79-
supplier.unchecked().get();
79+
supplier.uncheck().get();
8080

8181
// then exception is thrown
8282
}

src/test/java/pl/touk/throwing/ThrowingUnaryOperatorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void shouldApplyUnchecked() throws Exception {
2424
ThrowingUnaryOperator<Integer, IOException> op = i -> i;
2525

2626
// when
27-
ThrowingUnaryOperator.uncheck(op).apply(42);
27+
ThrowingUnaryOperator.unchecked(op).apply(42);
2828

2929
// then no exception thrown
3030
}
@@ -35,7 +35,7 @@ public void shouldApplyUncheckedAndThrow() throws Exception {
3535
ThrowingUnaryOperator<Integer, IOException> op = i -> { throw new IOException(); };
3636

3737
// when
38-
ThrowingUnaryOperator.uncheck(op).apply(42);
38+
ThrowingUnaryOperator.unchecked(op).apply(42);
3939

4040
// then no exception thrown
4141
}

0 commit comments

Comments
 (0)