Skip to content

Commit d10c551

Browse files
committed
refactor: SneakyThrow
1 parent 3e21914 commit d10c551

File tree

9 files changed

+39
-33
lines changed

9 files changed

+39
-33
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.lokic</groupId>
88
<artifactId>java-plus</artifactId>
9-
<version>0.0.3</version>
9+
<version>0.0.4</version>
1010
<name>java-plus</name>
1111
<description>Provide some useful extensions on the basis of core java to make java more usable.</description>
1212
<url>https://github.com/lokic/java-plus</url>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.github.lokic.javaplus.func.sneakythrows;
2+
3+
import com.github.lokic.javaplus.func.throwable.*;
4+
5+
public interface SneakyThrow {
6+
7+
static <T> SneakyThrowConsumer1<T> cast(ThrowConsumer1<T> throwConsumer1) {
8+
return throwConsumer1::throwableAccept;
9+
}
10+
11+
static <T, R> SneakyThrowFunction1<T, R> cast(ThrowFunction1<T, R> throwFunction1) {
12+
return throwFunction1::throwableApply;
13+
}
14+
15+
static <T1, T2, R> SneakyThrowFunction2<T1, T2, R> cast(ThrowFunction2<T1, T2, R> throwFunction2) {
16+
return throwFunction2::throwableApply;
17+
}
18+
19+
static <T1, T2, T3, R> SneakyThrowFunction3<T1, T2, T3, R> cast(ThrowFunction3<T1, T2, T3, R> throwFunction3) {
20+
return throwFunction3::throwableApply;
21+
}
22+
23+
static SneakyThrowRunnable cast(ThrowRunnable throwRunnable) {
24+
return throwRunnable::throwableRun;
25+
}
26+
27+
static <T> SneakyThrowSupplier<T> cast(ThrowSupplier<T> throwSupplier) {
28+
return throwSupplier::throwableGet;
29+
}
30+
31+
}

src/main/java/com/github/lokic/javaplus/func/sneakythrows/SneakyThrowConsumer1.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@
66
import java.util.function.Consumer;
77

88
@FunctionalInterface
9-
public interface SneakyThrowConsumer1<T> extends Consumer<T>, ThrowConsumer1<T> {
10-
9+
public interface SneakyThrowConsumer1<T> extends Consumer<T>, ThrowConsumer1<T>, SneakyThrow {
1110

1211
@SneakyThrows
1312
@Override
1413
default void accept(T t) {
1514
throwableAccept(t);
1615
}
1716

18-
19-
static <T> SneakyThrowConsumer1<T> cast(ThrowConsumer1<T> throwConsumer1) {
20-
return throwConsumer1::throwableAccept;
21-
}
2217
}

src/main/java/com/github/lokic/javaplus/func/sneakythrows/SneakyThrowFunction1.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
import java.util.function.Function;
77

88
@FunctionalInterface
9-
public interface SneakyThrowFunction1<T, R> extends Function<T, R>, ThrowFunction1<T, R> {
9+
public interface SneakyThrowFunction1<T, R> extends Function<T, R>, ThrowFunction1<T, R>, SneakyThrow {
1010

1111
@SneakyThrows
1212
@Override
1313
default R apply(T t) {
1414
return throwableApply(t);
1515
}
1616

17-
static <T, R> SneakyThrowFunction1<T, R> cast(ThrowFunction1<T, R> throwFunction1) {
18-
return throwFunction1::throwableApply;
19-
}
2017
}

src/main/java/com/github/lokic/javaplus/func/sneakythrows/SneakyThrowFunction2.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55
import lombok.SneakyThrows;
66

77
@FunctionalInterface
8-
public interface SneakyThrowFunction2<T1, T2, R> extends TupleFunction2<T1, T2, R>, ThrowFunction2<T1, T2, R> {
9-
8+
public interface SneakyThrowFunction2<T1, T2, R> extends TupleFunction2<T1, T2, R>, ThrowFunction2<T1, T2, R>, SneakyThrow {
109

1110
@SneakyThrows
1211
@Override
1312
default R apply(T1 t1, T2 t2) {
1413
return throwableApply(t1, t2);
1514
}
1615

17-
static <T1, T2, R> SneakyThrowFunction2<T1, T2, R> cast(ThrowFunction2<T1, T2, R> throwFunction2) {
18-
return throwFunction2::throwableApply;
19-
}
2016
}

src/main/java/com/github/lokic/javaplus/func/sneakythrows/SneakyThrowFunction3.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@
55
import lombok.SneakyThrows;
66

77
@FunctionalInterface
8-
public interface SneakyThrowFunction3<T1, T2, T3, R> extends TupleFunction3<T1, T2, T3, R>, ThrowFunction3<T1, T2, T3, R> {
9-
8+
public interface SneakyThrowFunction3<T1, T2, T3, R> extends TupleFunction3<T1, T2, T3, R>, ThrowFunction3<T1, T2, T3, R>, SneakyThrow {
109

1110
@SneakyThrows
1211
@Override
1312
default R apply(T1 t1, T2 t2, T3 t3) {
1413
return throwableApply(t1, t2, t3);
1514
}
1615

17-
18-
static <T1, T2, T3, R> SneakyThrowFunction3<T1, T2, T3, R> cast(ThrowFunction3<T1, T2, T3, R> throwFunction3) {
19-
return throwFunction3::throwableApply;
20-
}
2116
}

src/main/java/com/github/lokic/javaplus/func/sneakythrows/SneakyThrowRunnable.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@
44
import lombok.SneakyThrows;
55

66
@FunctionalInterface
7-
public interface SneakyThrowRunnable extends Runnable, ThrowRunnable {
8-
7+
public interface SneakyThrowRunnable extends Runnable, ThrowRunnable, SneakyThrow {
98

109
@SneakyThrows
1110
@Override
1211
default void run() {
1312
throwableRun();
1413
}
1514

16-
static SneakyThrowRunnable cast(ThrowRunnable throwRunnable) {
17-
return throwRunnable::throwableRun;
18-
}
1915
}

src/main/java/com/github/lokic/javaplus/func/sneakythrows/SneakyThrowSupplier.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66
import java.util.function.Supplier;
77

88
@FunctionalInterface
9-
public interface SneakyThrowSupplier<T> extends Supplier<T>, ThrowSupplier<T> {
10-
9+
public interface SneakyThrowSupplier<T> extends Supplier<T>, ThrowSupplier<T>, SneakyThrow {
1110

1211
@SneakyThrows
1312
@Override
1413
default T get() {
1514
return throwableGet();
1615
}
1716

18-
static <T> SneakyThrowSupplier<T> cast(ThrowSupplier<T> throwSupplier) {
19-
return throwSupplier::throwableGet;
20-
}
2117
}

src/main/java/com/github/lokic/javaplus/func/sneakythrows/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*
2525
* <pre>{@code
2626
* Optional.of(0)
27-
* .map( SneakyThrowFunction1.cast(this::throwableMethod ));
27+
* .map( SneakyThrow.cast(this::throwableMethod ));
2828
*
2929
* int throwableMethod(int i) throws Exception {
3030
*

0 commit comments

Comments
 (0)