Skip to content

Commit 647a664

Browse files
committed
Fixed some IntelliJ inspection warnings
1 parent 1bdd69b commit 647a664

File tree

10 files changed

+74
-90
lines changed

10 files changed

+74
-90
lines changed

jOOL-java-8/src/main/java/org/jooq/lambda/Agg.java

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
*/
1616
package org.jooq.lambda;
1717

18+
import static java.util.Comparator.comparing;
1819
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;
2022
import static org.jooq.lambda.tuple.Tuple.tuple;
2123

2224
import java.util.*;
2325
import java.util.Map.Entry;
2426
import java.util.function.*;
2527
import java.util.stream.Collector;
26-
import java.util.stream.Collectors;
28+
import java.util.stream.Stream;
2729

2830
import org.jooq.lambda.tuple.Tuple;
2931
import org.jooq.lambda.tuple.Tuple2;
@@ -62,7 +64,7 @@ public class Agg {
6264
* (DENSE_RANK FIRST ORDER BY ... ), use {@link #maxAll(Comparator)} instead.
6365
*/
6466
public static <T> Collector<T, ?, Optional<T>> first() {
65-
return Collectors.reducing((v1, v2) -> v1);
67+
return reducing((v1, v2) -> v1);
6668
}
6769

6870
/**
@@ -75,7 +77,7 @@ public class Agg {
7577
* (DENSE_RANK LAST ORDER BY ... ), use {@link #minAll(Comparator)} instead.
7678
*/
7779
public static <T> Collector<T, ?, Optional<T>> last() {
78-
return Collectors.reducing((v1, v2) -> v2);
80+
return reducing((v1, v2) -> v2);
7981
}
8082

8183
/**
@@ -93,7 +95,7 @@ public class Agg {
9395
l1.addAll(l2);
9496
return l1;
9597
},
96-
l -> Seq.seq(l)
98+
Seq::seq
9799
);
98100
}
99101

@@ -130,7 +132,7 @@ class Accumulator {
130132
* function.
131133
*/
132134
public static <T> Collector<T, ?, Long> count() {
133-
return Collectors.counting();
135+
return counting();
134136
}
135137

136138
/**
@@ -169,7 +171,7 @@ class Accumulator {
169171
* Get a {@link Collector} that calculates the <code>SUM()</code> for any
170172
* type of {@link Number}.
171173
*/
172-
@SuppressWarnings({ "rawtypes", "unchecked" })
174+
@SuppressWarnings({ "unchecked" })
173175
public static <T, U> Collector<T, ?, Optional<U>> sum(Function<? super T, ? extends U> function) {
174176
return Collector.of(() -> (Sum<U>[]) new Sum[1],
175177
(s, v) -> {
@@ -198,7 +200,7 @@ class Accumulator {
198200
* Get a {@link Collector} that calculates the <code>AVG()</code> for any
199201
* type of {@link Number}.
200202
*/
201-
@SuppressWarnings({ "rawtypes", "unchecked" })
203+
@SuppressWarnings({ "unchecked" })
202204
public static <T, U> Collector<T, ?, Optional<U>> avg(Function<? super T, ? extends U> function) {
203205
return Collector.of(
204206
() -> (Sum<U>[]) new Sum[1],
@@ -345,7 +347,7 @@ class Accumulator {
345347
}
346348

347349
return Collector.of(
348-
() -> new Accumulator(),
350+
Accumulator::new,
349351
(a, t) -> {
350352
U u = function.apply(t);
351353

@@ -416,7 +418,7 @@ void set(T t, U u) {
416418
}
417419

418420
return Collector.of(
419-
() -> new Accumulator(),
421+
Accumulator::new,
420422
(a, t) -> {
421423
U u = function.apply(t);
422424
if (a.u == null) {
@@ -518,7 +520,7 @@ else if (compare > 0)
518520
* Get a {@link Collector} that calculates the <code>BIT_AND()</code> for any
519521
* type of {@link Number}.
520522
*/
521-
@SuppressWarnings({ "rawtypes", "unchecked" })
523+
@SuppressWarnings({ "unchecked" })
522524
public static <T, U> Collector<T, ?, Optional<U>> bitAnd(Function<? super T, ? extends U> function) {
523525
return Collector.of(() -> (Sum<U>[]) new Sum[1],
524526
(s, v) -> {
@@ -541,9 +543,7 @@ else if (compare > 0)
541543
*/
542544
public static <T, U> Collector<T, ?, Integer> bitAndInt(ToIntFunction<? super T> function) {
543545
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),
547547
(s1, s2) -> {
548548
s1[0] = s1[0] & s2[0];
549549
return s1;
@@ -558,9 +558,7 @@ else if (compare > 0)
558558
*/
559559
public static <T, U> Collector<T, ?, Long> bitAndLong(ToLongFunction<? super T> function) {
560560
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),
564562
(s1, s2) -> {
565563
s1[0] = s1[0] & s2[0];
566564
return s1;
@@ -581,7 +579,7 @@ else if (compare > 0)
581579
* Get a {@link Collector} that calculates the <code>BIT_OR()</code> for any
582580
* type of {@link Number}.
583581
*/
584-
@SuppressWarnings({ "rawtypes", "unchecked" })
582+
@SuppressWarnings({ "unchecked" })
585583
public static <T, U> Collector<T, ?, Optional<U>> bitOr(Function<? super T, ? extends U> function) {
586584
return Collector.of(() -> (Sum<U>[]) new Sum[1],
587585
(s, v) -> {
@@ -604,9 +602,7 @@ else if (compare > 0)
604602
*/
605603
public static <T, U> Collector<T, ?, Integer> bitOrInt(ToIntFunction<? super T> function) {
606604
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),
610606
(s1, s2) -> {
611607
s1[0] = s1[0] | s2[0];
612608
return s1;
@@ -621,9 +617,7 @@ else if (compare > 0)
621617
*/
622618
public static <T, U> Collector<T, ?, Long> bitOrLong(ToLongFunction<? super T> function) {
623619
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),
627621
(s1, s2) -> {
628622
s1[0] = s1[0] | s2[0];
629623
return s1;
@@ -662,7 +656,7 @@ else if (compare > 0)
662656
* Get a {@link Collector} that calculates the <code>MODE()</code> function.
663657
*/
664658
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);
666660
}
667661

668662
/**
@@ -810,9 +804,7 @@ else if (l1[0] == null)
810804
*/
811805
public static <T, U> Collector<T, ?, Optional<Double>> percentRankBy(U value, Function<? super T, ? extends U> function, Comparator<? super U> comparator) {
812806
return collectingAndThen(
813-
Tuple.collectors(
814-
rankBy(value, function, comparator),
815-
count()),
807+
collectors(rankBy(value, function, comparator), count()),
816808
t -> t.map((rank, count) -> rank.map(r -> (double) r / count))
817809
);
818810
}
@@ -904,7 +896,7 @@ else if (l1[0] == null)
904896
if (percentile == 0.0)
905897
return minBy(function, comparator);
906898
else if (percentile == 1.0)
907-
return collectingAndThen(maxAllBy(function, comparator), s -> s.findLast());
899+
return collectingAndThen(maxAllBy(function, comparator), Seq::findLast);
908900
else
909901
return percentileCollector(
910902
function,
@@ -991,7 +983,7 @@ private static <T, U, R> Collector<T, List<Tuple2<T, U>>, R> percentileCollector
991983
Function<List<Tuple2<T, U>>, R> finisher
992984
) {
993985
return Collector.of(
994-
() -> new ArrayList<>(),
986+
ArrayList::new,
995987
(l, v) -> l.add(tuple(v, function.apply(v))),
996988
(l1, l2) -> {
997989
l1.addAll(l2);
@@ -1005,7 +997,7 @@ private static <T, U, R> Collector<T, List<Tuple2<T, U>>, R> percentileCollector
1005997
else if (size == 1)
1006998
return onSingle.apply(l.get(0).v1);
1007999

1008-
l.sort(Comparator.comparing(t -> t.v2, comparator));
1000+
l.sort(comparing(t -> t.v2, comparator));
10091001
return finisher.apply(l);
10101002
}
10111003
);
@@ -1053,8 +1045,8 @@ private static int percentileIndex(double percentile, int size) {
10531045
* Get a {@link Collector} that calculates the common prefix of a set of strings.
10541046
*/
10551047
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) -> {
10581050
if (s1 == null || s2 == null)
10591051
return "";
10601052

@@ -1072,8 +1064,8 @@ private static int percentileIndex(double percentile, int size) {
10721064
* Get a {@link Collector} that calculates the common suffix of a set of strings.
10731065
*/
10741066
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) -> {
10771069
if (s1 == null || s2 == null)
10781070
return "";
10791071

jOOL-java-8/src/main/java/org/jooq/lambda/Blocking.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static <T> BinaryOperator<T> binaryOperator(BinaryOperator<T> binaryOpera
9191
}
9292

9393
public static BooleanSupplier booleanSupplier(BooleanSupplier booleanSupplier) {
94-
return () -> supplier(() -> booleanSupplier.getAsBoolean()).get();
94+
return () -> supplier(booleanSupplier::getAsBoolean).get();
9595
}
9696

9797
public static <T> Consumer<T> consumer(Consumer<? super T> consumer) {
@@ -115,7 +115,7 @@ public static DoublePredicate doublePredicate(DoublePredicate doublePredicate) {
115115
}
116116

117117
public static DoubleSupplier doubleSupplier(DoubleSupplier doubleSupplier) {
118-
return () -> supplier(() -> doubleSupplier.getAsDouble()).get();
118+
return () -> supplier(doubleSupplier::getAsDouble).get();
119119
}
120120

121121
public static DoubleToIntFunction doubleToIntFunction(DoubleToIntFunction doubleToIntFunction) {
@@ -151,7 +151,7 @@ public static IntPredicate intPredicate(IntPredicate intPredicate) {
151151
}
152152

153153
public static IntSupplier intSupplier(IntSupplier intSupplier) {
154-
return () -> supplier(() -> intSupplier.getAsInt()).get();
154+
return () -> supplier(intSupplier::getAsInt).get();
155155
}
156156

157157
public static IntToDoubleFunction intToDoubleFunction(IntToDoubleFunction intToDoubleFunction) {
@@ -183,7 +183,7 @@ public static LongPredicate longPredicate(LongPredicate longPredicate) {
183183
}
184184

185185
public static LongSupplier longSupplier(LongSupplier longSupplier) {
186-
return () -> supplier(() -> longSupplier.getAsLong()).get();
186+
return () -> supplier(longSupplier::getAsLong).get();
187187
}
188188

189189
public static LongToDoubleFunction longToDoubleFunction(LongToDoubleFunction longToDoubleFunction) {

jOOL-java-8/src/main/java/org/jooq/lambda/Partition.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ <R> R cacheIf(BooleanSupplier condition, Supplier<?> key, Supplier<? extends R>
5656
return value.get();
5757
}
5858

59-
@SuppressWarnings("unchecked")
6059
<R> R cache(Object key, Supplier<? extends R> value) {
6160
return cache(() -> key, value);
6261
}

jOOL-java-8/src/main/java/org/jooq/lambda/SeqImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.jooq.lambda;
1717

1818
import static java.util.Comparator.naturalOrder;
19+
import static java.util.stream.Collectors.*;
1920

2021
import java.util.ArrayList;
2122
import java.util.Collection;
@@ -232,17 +233,17 @@ public <U> Optional<U> sum(Function<? super T, ? extends U> function) {
232233

233234
@Override
234235
public int sumInt(ToIntFunction<? super T> function) {
235-
return collect(Collectors.summingInt(function));
236+
return collect(summingInt(function));
236237
}
237238

238239
@Override
239240
public long sumLong(ToLongFunction<? super T> function) {
240-
return collect(Collectors.summingLong(function));
241+
return collect(summingLong(function));
241242
}
242243

243244
@Override
244245
public double sumDouble(ToDoubleFunction<? super T> function) {
245-
return collect(Collectors.summingDouble(function));
246+
return collect(summingDouble(function));
246247
}
247248

248249
@Override

jOOL-java-8/src/main/java/org/jooq/lambda/SeqUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Comparator<? super U> getComparator() {
8484
// optimisations (e.g. to avoid sorting a stream twice in a row)
8585
return (Comparator) delegate.getComparator();
8686
}
87-
}).onClose(() -> stream.close());
87+
}).onClose(stream::close);
8888
}
8989

9090
static <T> Map<?, Partition<T>> partitions(WindowSpecification<T> window, List<Tuple2<T, Long>> input) {
@@ -98,7 +98,7 @@ static <T> Map<?, Partition<T>> partitions(WindowSpecification<T> window, List<T
9898
() -> window.order().isPresent()
9999
? new TreeSet<>(comparing((Tuple2<T, Long> t) -> t.v1, window.order().get()).thenComparing(t -> t.v2))
100100
: new ArrayList<>(),
101-
(s, t) -> s.add(t),
101+
Collection::add,
102102
(s1, s2) -> { s1.addAll(s2); return s1; },
103103
Partition::new
104104
)

0 commit comments

Comments
 (0)