Skip to content

Commit 85e0c81

Browse files
authored
Merge pull request #5 from lokic/dev/0.2.1
Dev/0.2.1
2 parents c626512 + eeac935 commit 85e0c81

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+776
-53
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
- Lazy:带缓存功能的 Supplier
5050

5151
- Supplier 每一次执行 Supplier.get() 都会执行一次 Supplier.get() 内的业务逻辑。 如果在一些Supplier.get() 比较耗时的场景,且多次执行 Supplier.get()
52-
结果相同的情况下, 我们没有必要多次执行,只需要把执行第一次的结果保存下来,之后多次调用直接返回即可,Lazy 就是这个目的设计出来的。
52+
结果相同的情况下, 我们没有必要多次执行,只需要把执行第一次的结果保存下来,之后多次调用直接返回即可,Lazy 就是这个目的设计出来的。
5353

5454
- [Property](https://github.com/lokic/java-plus/tree/master/src/main/java/com/github/lokic/javaplus/property)
5555
:在定义枚举类之后,经常需要基于枚举类的某个字段作为key来查询枚举,抽象出这个模块来实现key到枚举的映射和转换逻辑,[示例](https://github.com/lokic/java-plus/tree/master/src/test/java/com/github/lokic/javaplus/property)
@@ -69,3 +69,18 @@
6969
- Collectors.Reversed:倒序相关
7070
- Collectors.Distinct:去重相关
7171

72+
- [Join](https://github.com/lokic/java-plus/tree/master/src/main/java/com/github/lokic/javaplus/join/Join.java)
73+
:一种类似SQL中join的操作,可以把内存中的Stream流像操作数据库中的表一样进行各种join
74+
75+
```java
76+
Stream<Integer> streamA = Stream.of(1, 2, 3, 4);
77+
Stream<String> streamB = Stream.of("1", "2", "3");
78+
79+
Join.stream(streamA)
80+
.leftOuterJoin(streamB, Join.on(a -> String.valueOf(a), b -> b)
81+
.stream() // 转成Stream之后是一个多元组的流,可以结合TupleFunctional进行很多便利的操作
82+
.map(...)
83+
```
84+
85+
86+

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.2.0</version>
9+
<version>0.2.1-SNAPSHOT</version>
1010
<name>java-plus</name>
1111
<description>Provide some useful extensions on the basis of java8 to make java more usable.</description>
1212
<url>https://github.com/lokic/java-plus</url>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.github.lokic.javaplus.functional.function;
2+
3+
import java.util.function.Function;
4+
5+
@FunctionalInterface
6+
public interface Function7<T1, T2, T3, T4, T5, T6, T7, R> {
7+
R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7);
8+
9+
static <T1, T2, T3, T4, T5, T6, T7, R> Function7<T1, T2, T3, T4, T5, T6, T7, R> $1(Function<T1, R> function) {
10+
return (t1, t2, t3, t4, t5, t6, t7) -> function.apply(t1);
11+
}
12+
13+
static <T1, T2, T3, T4, T5, T6, T7, R> Function7<T1, T2, T3, T4, T5, T6, T7, R> $2(Function<T2, R> function) {
14+
return (t1, t2, t3, t4, t5, t6, t7) -> function.apply(t2);
15+
}
16+
17+
static <T1, T2, T3, T4, T5, T6, T7, R> Function7<T1, T2, T3, T4, T5, T6, T7, R> $3(Function<T3, R> function) {
18+
return (t1, t2, t3, t4, t5, t6, t7) -> function.apply(t3);
19+
}
20+
21+
static <T1, T2, T3, T4, T5, T6, T7, R> Function7<T1, T2, T3, T4, T5, T6, T7, R> $4(Function<T4, R> function) {
22+
return (t1, t2, t3, t4, t5, t6, t7) -> function.apply(t4);
23+
}
24+
25+
static <T1, T2, T3, T4, T5, T6, T7, R> Function7<T1, T2, T3, T4, T5, T6, T7, R> $5(Function<T5, R> function) {
26+
return (t1, t2, t3, t4, t5, t6, t7) -> function.apply(t5);
27+
}
28+
29+
static <T1, T2, T3, T4, T5, T6, T7, R> Function7<T1, T2, T3, T4, T5, T6, T7, R> $6(Function<T6, R> function) {
30+
return (t1, t2, t3, t4, t5, t6, t7) -> function.apply(t6);
31+
}
32+
33+
static <T1, T2, T3, T4, T5, T6, T7, R> Function7<T1, T2, T3, T4, T5, T6, T7, R> $7(Function<T7, R> function) {
34+
return (t1, t2, t3, t4, t5, t6, t7) -> function.apply(t7);
35+
}
36+
37+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.github.lokic.javaplus.functional.function;
2+
3+
import java.util.function.Function;
4+
5+
@FunctionalInterface
6+
public interface Function8<T1, T2, T3, T4, T5, T6, T7, T8, R> {
7+
R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8);
8+
9+
static <T1, T2, T3, T4, T5, T6, T7, T8, R> Function8<T1, T2, T3, T4, T5, T6, T7, T8, R> $1(Function<T1, R> function) {
10+
return (t1, t2, t3, t4, t5, t6, t7, t8) -> function.apply(t1);
11+
}
12+
13+
static <T1, T2, T3, T4, T5, T6, T7, T8, R> Function8<T1, T2, T3, T4, T5, T6, T7, T8, R> $2(Function<T2, R> function) {
14+
return (t1, t2, t3, t4, t5, t6, t7, t8) -> function.apply(t2);
15+
}
16+
17+
static <T1, T2, T3, T4, T5, T6, T7, T8, R> Function8<T1, T2, T3, T4, T5, T6, T7, T8, R> $3(Function<T3, R> function) {
18+
return (t1, t2, t3, t4, t5, t6, t7, t8) -> function.apply(t3);
19+
}
20+
21+
static <T1, T2, T3, T4, T5, T6, T7, T8, R> Function8<T1, T2, T3, T4, T5, T6, T7, T8, R> $4(Function<T4, R> function) {
22+
return (t1, t2, t3, t4, t5, t6, t7, t8) -> function.apply(t4);
23+
}
24+
25+
static <T1, T2, T3, T4, T5, T6, T7, T8, R> Function8<T1, T2, T3, T4, T5, T6, T7, T8, R> $5(Function<T5, R> function) {
26+
return (t1, t2, t3, t4, t5, t6, t7, t8) -> function.apply(t5);
27+
}
28+
29+
static <T1, T2, T3, T4, T5, T6, T7, T8, R> Function8<T1, T2, T3, T4, T5, T6, T7, T8, R> $6(Function<T6, R> function) {
30+
return (t1, t2, t3, t4, t5, t6, t7, t8) -> function.apply(t6);
31+
}
32+
33+
static <T1, T2, T3, T4, T5, T6, T7, T8, R> Function8<T1, T2, T3, T4, T5, T6, T7, T8, R> $7(Function<T7, R> function) {
34+
return (t1, t2, t3, t4, t5, t6, t7, t8) -> function.apply(t7);
35+
}
36+
37+
static <T1, T2, T3, T4, T5, T6, T7, T8, R> Function8<T1, T2, T3, T4, T5, T6, T7, T8, R> $8(Function<T8, R> function) {
38+
return (t1, t2, t3, t4, t5, t6, t7, t8) -> function.apply(t8);
39+
}
40+
41+
42+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.github.lokic.javaplus.functional.function;
2+
3+
import java.util.function.Function;
4+
5+
@FunctionalInterface
6+
public interface Function9<T1, T2, T3, T4, T5, T6, T7, T8, T9, R> {
7+
R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9);
8+
9+
static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> Function9<T1, T2, T3, T4, T5, T6, T7, T8, T9, R> $1(Function<T1, R> function) {
10+
return (t1, t2, t3, t4, t5, t6, t7, t8, t9) -> function.apply(t1);
11+
}
12+
13+
static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> Function9<T1, T2, T3, T4, T5, T6, T7, T8, T9, R> $2(Function<T2, R> function) {
14+
return (t1, t2, t3, t4, t5, t6, t7, t8, t9) -> function.apply(t2);
15+
}
16+
17+
static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> Function9<T1, T2, T3, T4, T5, T6, T7, T8, T9, R> $3(Function<T3, R> function) {
18+
return (t1, t2, t3, t4, t5, t6, t7, t8, t9) -> function.apply(t3);
19+
}
20+
21+
static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> Function9<T1, T2, T3, T4, T5, T6, T7, T8, T9, R> $4(Function<T4, R> function) {
22+
return (t1, t2, t3, t4, t5, t6, t7, t8, t9) -> function.apply(t4);
23+
}
24+
25+
static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> Function9<T1, T2, T3, T4, T5, T6, T7, T8, T9, R> $5(Function<T5, R> function) {
26+
return (t1, t2, t3, t4, t5, t6, t7, t8, t9) -> function.apply(t5);
27+
}
28+
29+
static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> Function9<T1, T2, T3, T4, T5, T6, T7, T8, T9, R> $6(Function<T6, R> function) {
30+
return (t1, t2, t3, t4, t5, t6, t7, t8, t9) -> function.apply(t6);
31+
}
32+
33+
static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> Function9<T1, T2, T3, T4, T5, T6, T7, T8, T9, R> $7(Function<T7, R> function) {
34+
return (t1, t2, t3, t4, t5, t6, t7, t8, t9) -> function.apply(t7);
35+
}
36+
37+
static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> Function9<T1, T2, T3, T4, T5, T6, T7, T8, T9, R> $8(Function<T8, R> function) {
38+
return (t1, t2, t3, t4, t5, t6, t7, t8, t9) -> function.apply(t8);
39+
}
40+
41+
static <T1, T2, T3, T4, T5, T6, T7, T8, T9, R> Function9<T1, T2, T3, T4, T5, T6, T7, T8, T9, R> $9(Function<T9, R> function) {
42+
return (t1, t2, t3, t4, t5, t6, t7, t8, t9) -> function.apply(t9);
43+
}
44+
45+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.github.lokic.javaplus.functional.predicate;
2+
3+
4+
import java.util.function.Predicate;
5+
6+
@FunctionalInterface
7+
public interface Predicate4<T1, T2, T3, T4> {
8+
boolean test(T1 t1, T2 t2, T3 t3, T4 t4);
9+
10+
static <T1, T2, T3, T4> Predicate4<T1, T2, T3, T4> $1(Predicate<T1> predicate) {
11+
return (t1, t2, t3, t4) -> predicate.test(t1);
12+
}
13+
14+
static <T1, T2, T3, T4> Predicate4<T1, T2, T3, T4> $2(Predicate<T2> predicate) {
15+
return (t1, t2, t3, t4) -> predicate.test(t2);
16+
}
17+
18+
static <T1, T2, T3, T4> Predicate4<T1, T2, T3, T4> $3(Predicate<T3> predicate) {
19+
return (t1, t2, t3, t4) -> predicate.test(t3);
20+
}
21+
22+
static <T1, T2, T3, T4> Predicate4<T1, T2, T3, T4> $4(Predicate<T4> predicate) {
23+
return (t1, t2, t3, t4) -> predicate.test(t4);
24+
}
25+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.github.lokic.javaplus.functional.sneakythrows;
2+
3+
import com.github.lokic.javaplus.functional.consumer.Consumer2;
4+
import com.github.lokic.javaplus.functional.throwable.ThrowsConsumer2;
5+
import lombok.SneakyThrows;
6+
7+
@FunctionalInterface
8+
public interface SneakyThrowsConsumer2<T1, T2> extends Consumer2<T1, T2>, ThrowsConsumer2<T1, T2> {
9+
10+
@SneakyThrows
11+
@Override
12+
default void accept(T1 t1, T2 t2) {
13+
throwableAccept(t1, t2);
14+
}
15+
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.github.lokic.javaplus.functional.sneakythrows;
2+
3+
import com.github.lokic.javaplus.functional.consumer.Consumer3;
4+
import com.github.lokic.javaplus.functional.throwable.ThrowsConsumer3;
5+
import lombok.SneakyThrows;
6+
7+
@FunctionalInterface
8+
public interface SneakyThrowsConsumer3<T1, T2, T3> extends Consumer3<T1, T2, T3>, ThrowsConsumer3<T1, T2, T3> {
9+
10+
@SneakyThrows
11+
@Override
12+
default void accept(T1 t1, T2 t2, T3 t3) {
13+
throwableAccept(t1, t2, t3);
14+
}
15+
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.github.lokic.javaplus.functional.sneakythrows;
2+
3+
import com.github.lokic.javaplus.functional.consumer.Consumer4;
4+
import com.github.lokic.javaplus.functional.throwable.ThrowsConsumer4;
5+
import lombok.SneakyThrows;
6+
7+
@FunctionalInterface
8+
public interface SneakyThrowsConsumer4<T1, T2, T3, T4> extends Consumer4<T1, T2, T3, T4>, ThrowsConsumer4<T1, T2, T3, T4> {
9+
10+
@SneakyThrows
11+
@Override
12+
default void accept(T1 t1, T2 t2, T3 t3, T4 t4) {
13+
throwableAccept(t1, t2, t3, t4);
14+
}
15+
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.github.lokic.javaplus.functional.sneakythrows;
2+
3+
import com.github.lokic.javaplus.functional.throwable.ThrowsFunction4;
4+
import com.github.lokic.javaplus.functional.tuple.TupleFunction4;
5+
import lombok.SneakyThrows;
6+
7+
@FunctionalInterface
8+
public interface SneakyThrowsFunction4<T1, T2, T3, T4, R> extends TupleFunction4<T1, T2, T3, T4, R>, ThrowsFunction4<T1, T2, T3, T4, R> {
9+
10+
@SneakyThrows
11+
@Override
12+
default R apply(T1 t1, T2 t2, T3 t3, T4 t4) {
13+
return throwableApply(t1, t2, t3, t4);
14+
}
15+
16+
}

0 commit comments

Comments
 (0)