15
15
*/
16
16
package org .jooq .lambda ;
17
17
18
+ import static java .util .Comparator .comparing ;
18
19
import static java .util .Comparator .naturalOrder ;
19
- import static java .util .stream .Collectors .collectingAndThen ;
20
+ import static java .util .stream .Collectors .*;
21
+ import static org .jooq .lambda .tuple .Tuple .collectors ;
20
22
import static org .jooq .lambda .tuple .Tuple .tuple ;
21
23
22
24
import java .util .*;
23
25
import java .util .Map .Entry ;
24
26
import java .util .function .*;
25
27
import java .util .stream .Collector ;
26
- import java .util .stream .Collectors ;
28
+ import java .util .stream .Stream ;
27
29
28
30
import org .jooq .lambda .tuple .Tuple ;
29
31
import org .jooq .lambda .tuple .Tuple2 ;
@@ -62,7 +64,7 @@ public class Agg {
62
64
* (DENSE_RANK FIRST ORDER BY ... ), use {@link #maxAll(Comparator)} instead.
63
65
*/
64
66
public static <T > Collector <T , ?, Optional <T >> first () {
65
- return Collectors . reducing ((v1 , v2 ) -> v1 );
67
+ return reducing ((v1 , v2 ) -> v1 );
66
68
}
67
69
68
70
/**
@@ -75,7 +77,7 @@ public class Agg {
75
77
* (DENSE_RANK LAST ORDER BY ... ), use {@link #minAll(Comparator)} instead.
76
78
*/
77
79
public static <T > Collector <T , ?, Optional <T >> last () {
78
- return Collectors . reducing ((v1 , v2 ) -> v2 );
80
+ return reducing ((v1 , v2 ) -> v2 );
79
81
}
80
82
81
83
/**
@@ -93,7 +95,7 @@ public class Agg {
93
95
l1 .addAll (l2 );
94
96
return l1 ;
95
97
},
96
- l -> Seq . seq ( l )
98
+ Seq :: seq
97
99
);
98
100
}
99
101
@@ -130,7 +132,7 @@ class Accumulator {
130
132
* function.
131
133
*/
132
134
public static <T > Collector <T , ?, Long > count () {
133
- return Collectors . counting ();
135
+ return counting ();
134
136
}
135
137
136
138
/**
@@ -169,7 +171,7 @@ class Accumulator {
169
171
* Get a {@link Collector} that calculates the <code>SUM()</code> for any
170
172
* type of {@link Number}.
171
173
*/
172
- @ SuppressWarnings ({ "rawtypes" , " unchecked" })
174
+ @ SuppressWarnings ({ "unchecked" })
173
175
public static <T , U > Collector <T , ?, Optional <U >> sum (Function <? super T , ? extends U > function ) {
174
176
return Collector .of (() -> (Sum <U >[]) new Sum [1 ],
175
177
(s , v ) -> {
@@ -198,7 +200,7 @@ class Accumulator {
198
200
* Get a {@link Collector} that calculates the <code>AVG()</code> for any
199
201
* type of {@link Number}.
200
202
*/
201
- @ SuppressWarnings ({ "rawtypes" , " unchecked" })
203
+ @ SuppressWarnings ({ "unchecked" })
202
204
public static <T , U > Collector <T , ?, Optional <U >> avg (Function <? super T , ? extends U > function ) {
203
205
return Collector .of (
204
206
() -> (Sum <U >[]) new Sum [1 ],
@@ -345,7 +347,7 @@ class Accumulator {
345
347
}
346
348
347
349
return Collector .of (
348
- () -> new Accumulator () ,
350
+ Accumulator :: new ,
349
351
(a , t ) -> {
350
352
U u = function .apply (t );
351
353
@@ -416,7 +418,7 @@ void set(T t, U u) {
416
418
}
417
419
418
420
return Collector .of (
419
- () -> new Accumulator () ,
421
+ Accumulator :: new ,
420
422
(a , t ) -> {
421
423
U u = function .apply (t );
422
424
if (a .u == null ) {
@@ -518,7 +520,7 @@ else if (compare > 0)
518
520
* Get a {@link Collector} that calculates the <code>BIT_AND()</code> for any
519
521
* type of {@link Number}.
520
522
*/
521
- @ SuppressWarnings ({ "rawtypes" , " unchecked" })
523
+ @ SuppressWarnings ({ "unchecked" })
522
524
public static <T , U > Collector <T , ?, Optional <U >> bitAnd (Function <? super T , ? extends U > function ) {
523
525
return Collector .of (() -> (Sum <U >[]) new Sum [1 ],
524
526
(s , v ) -> {
@@ -541,9 +543,7 @@ else if (compare > 0)
541
543
*/
542
544
public static <T , U > Collector <T , ?, Integer > bitAndInt (ToIntFunction <? super T > function ) {
543
545
return Collector .of (() -> new int [] { Integer .MAX_VALUE },
544
- (s , v ) -> {
545
- s [0 ] = s [0 ] & function .applyAsInt (v );
546
- },
546
+ (s , v ) -> s [0 ] = s [0 ] & function .applyAsInt (v ),
547
547
(s1 , s2 ) -> {
548
548
s1 [0 ] = s1 [0 ] & s2 [0 ];
549
549
return s1 ;
@@ -558,9 +558,7 @@ else if (compare > 0)
558
558
*/
559
559
public static <T , U > Collector <T , ?, Long > bitAndLong (ToLongFunction <? super T > function ) {
560
560
return Collector .of (() -> new long [] { Long .MAX_VALUE },
561
- (s , v ) -> {
562
- s [0 ] = s [0 ] & function .applyAsLong (v );
563
- },
561
+ (s , v ) -> s [0 ] = s [0 ] & function .applyAsLong (v ),
564
562
(s1 , s2 ) -> {
565
563
s1 [0 ] = s1 [0 ] & s2 [0 ];
566
564
return s1 ;
@@ -581,7 +579,7 @@ else if (compare > 0)
581
579
* Get a {@link Collector} that calculates the <code>BIT_OR()</code> for any
582
580
* type of {@link Number}.
583
581
*/
584
- @ SuppressWarnings ({ "rawtypes" , " unchecked" })
582
+ @ SuppressWarnings ({ "unchecked" })
585
583
public static <T , U > Collector <T , ?, Optional <U >> bitOr (Function <? super T , ? extends U > function ) {
586
584
return Collector .of (() -> (Sum <U >[]) new Sum [1 ],
587
585
(s , v ) -> {
@@ -604,9 +602,7 @@ else if (compare > 0)
604
602
*/
605
603
public static <T , U > Collector <T , ?, Integer > bitOrInt (ToIntFunction <? super T > function ) {
606
604
return Collector .of (() -> new int [1 ],
607
- (s , v ) -> {
608
- s [0 ] = s [0 ] | function .applyAsInt (v );
609
- },
605
+ (s , v ) -> s [0 ] = s [0 ] | function .applyAsInt (v ),
610
606
(s1 , s2 ) -> {
611
607
s1 [0 ] = s1 [0 ] | s2 [0 ];
612
608
return s1 ;
@@ -621,9 +617,7 @@ else if (compare > 0)
621
617
*/
622
618
public static <T , U > Collector <T , ?, Long > bitOrLong (ToLongFunction <? super T > function ) {
623
619
return Collector .of (() -> new long [1 ],
624
- (s , v ) -> {
625
- s [0 ] = s [0 ] | function .applyAsLong (v );
626
- },
620
+ (s , v ) -> s [0 ] = s [0 ] | function .applyAsLong (v ),
627
621
(s1 , s2 ) -> {
628
622
s1 [0 ] = s1 [0 ] | s2 [0 ];
629
623
return s1 ;
@@ -662,7 +656,7 @@ else if (compare > 0)
662
656
* Get a {@link Collector} that calculates the <code>MODE()</code> function.
663
657
*/
664
658
public static <T , U > Collector <T , ?, Optional <T >> modeBy (Function <? super T , ? extends U > function ) {
665
- return Collectors . collectingAndThen (modeAllBy (function ), s -> s . findFirst () );
659
+ return collectingAndThen (modeAllBy (function ), Stream :: findFirst );
666
660
}
667
661
668
662
/**
@@ -810,9 +804,7 @@ else if (l1[0] == null)
810
804
*/
811
805
public static <T , U > Collector <T , ?, Optional <Double >> percentRankBy (U value , Function <? super T , ? extends U > function , Comparator <? super U > comparator ) {
812
806
return collectingAndThen (
813
- Tuple .collectors (
814
- rankBy (value , function , comparator ),
815
- count ()),
807
+ collectors (rankBy (value , function , comparator ), count ()),
816
808
t -> t .map ((rank , count ) -> rank .map (r -> (double ) r / count ))
817
809
);
818
810
}
@@ -904,7 +896,7 @@ else if (l1[0] == null)
904
896
if (percentile == 0.0 )
905
897
return minBy (function , comparator );
906
898
else if (percentile == 1.0 )
907
- return collectingAndThen (maxAllBy (function , comparator ), s -> s . findLast () );
899
+ return collectingAndThen (maxAllBy (function , comparator ), Seq :: findLast );
908
900
else
909
901
return percentileCollector (
910
902
function ,
@@ -991,7 +983,7 @@ private static <T, U, R> Collector<T, List<Tuple2<T, U>>, R> percentileCollector
991
983
Function <List <Tuple2 <T , U >>, R > finisher
992
984
) {
993
985
return Collector .of (
994
- () -> new ArrayList <>() ,
986
+ ArrayList :: new ,
995
987
(l , v ) -> l .add (tuple (v , function .apply (v ))),
996
988
(l1 , l2 ) -> {
997
989
l1 .addAll (l2 );
@@ -1005,7 +997,7 @@ private static <T, U, R> Collector<T, List<Tuple2<T, U>>, R> percentileCollector
1005
997
else if (size == 1 )
1006
998
return onSingle .apply (l .get (0 ).v1 );
1007
999
1008
- l .sort (Comparator . comparing (t -> t .v2 , comparator ));
1000
+ l .sort (comparing (t -> t .v2 , comparator ));
1009
1001
return finisher .apply (l );
1010
1002
}
1011
1003
);
@@ -1053,8 +1045,8 @@ private static int percentileIndex(double percentile, int size) {
1053
1045
* Get a {@link Collector} that calculates the common prefix of a set of strings.
1054
1046
*/
1055
1047
public static Collector <CharSequence , ?, String > commonPrefix () {
1056
- return Collectors . collectingAndThen (
1057
- Collectors . reducing ((CharSequence s1 , CharSequence s2 ) -> {
1048
+ return collectingAndThen (
1049
+ reducing ((CharSequence s1 , CharSequence s2 ) -> {
1058
1050
if (s1 == null || s2 == null )
1059
1051
return "" ;
1060
1052
@@ -1072,8 +1064,8 @@ private static int percentileIndex(double percentile, int size) {
1072
1064
* Get a {@link Collector} that calculates the common suffix of a set of strings.
1073
1065
*/
1074
1066
public static Collector <CharSequence , ?, String > commonSuffix () {
1075
- return Collectors . collectingAndThen (
1076
- Collectors . reducing ((CharSequence s1 , CharSequence s2 ) -> {
1067
+ return collectingAndThen (
1068
+ reducing ((CharSequence s1 , CharSequence s2 ) -> {
1077
1069
if (s1 == null || s2 == null )
1078
1070
return "" ;
1079
1071
0 commit comments