StreamRules
SUGGESTION
Simplification
Suppression
Disable all rules by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$).*as compiler argument.
Table of contents
- Joining
- EmptyStream
- StreamOfNullable
- StreamOfArray
- ConcatOneStream
- ConcatTwoStreams
- FilterOuterStreamAfterFlatMap
- MapOuterStreamAfterFlatMap
- FlatMapOuterStreamAfterFlatMap
- StreamFilterSorted
- StreamFilterSortedWithComparator
- StreamMapFirst
- StreamFindAnyIsEmpty
- StreamFindAnyIsPresent
- StreamMapFilter
- StreamMin
- StreamMinNaturalOrder
- StreamMax
- StreamMaxNaturalOrder
- StreamNoneMatch
- StreamNoneMatch2
- StreamAnyMatch
- StreamAllMatch
- StreamAllMatch2
- StreamMapToIntSum
- StreamMapToDoubleSum
- StreamMapToLongSum
- StreamMapToIntSummaryStatistics
- StreamMapToDoubleSummaryStatistics
- StreamMapToLongSummaryStatistics
- StreamCount
- StreamReduce
- StreamReduceWithIdentity
- StreamFilterCollect
- StreamMapCollect
- StreamFlatMapCollect
- StreamsConcat
- StreamTakeWhile
- StreamIterate
- StreamOf1
- StreamOf2
- StreamOf3
- StreamOf4
- StreamOf5
Joining
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("Joining")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$Joining).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
String testJoining() {
- return Stream.of("foo").collect(joining(""));
+ return Stream.of("foo").collect(joining());
}EmptyStream
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("EmptyStream")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$EmptyStream).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Stream<?>> testEmptyStream() {
return ImmutableSet.of(
- Stream.of(),
- Optional.empty().stream(),
- ImmutableList.of().stream(),
+ Stream.empty(),
+ Stream.empty(),
+ Stream.empty(),
ImmutableList.of("foo").reverse().stream(),
- Streams.stream((Iterable<String>) ImmutableSet.<String>of()),
+ Stream.empty(),
Streams.stream(ImmutableSet.of("bar")::iterator),
- Streams.stream(ImmutableSet.of().iterator()),
+ Stream.empty(),
Streams.stream(ImmutableSet.of("baz").iterator()),
- Arrays.stream(new String[0]),
+ Stream.empty(),
Arrays.stream(new String[] {"qux"}));
}StreamOfNullable
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamOfNullable")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamOfNullable).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Stream<String>> testStreamOfNullable() {
- return ImmutableSet.of(
- Stream.of("a").filter(Objects::nonNull), Optional.ofNullable("b").stream());
+ return ImmutableSet.of(Stream.ofNullable("a"), Stream.ofNullable("b"));
}StreamOfArray
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamOfArray")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamOfArray).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<String> testStreamOfArray() {
- return Stream.of(new String[] {"foo", "bar"});
+ return Arrays.stream(new String[] {"foo", "bar"});
}ConcatOneStream
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ConcatOneStream")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$ConcatOneStream).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testConcatOneStream() {
- return Streams.concat(Stream.of(1));
+ return Stream.of(1);
}ConcatTwoStreams
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ConcatTwoStreams")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$ConcatTwoStreams).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testConcatTwoStreams() {
- return Streams.concat(Stream.of(1), Stream.of(2));
+ return Stream.concat(Stream.of(1), Stream.of(2));
}FilterOuterStreamAfterFlatMap
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("FilterOuterStreamAfterFlatMap")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$FilterOuterStreamAfterFlatMap).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testFilterOuterStreamAfterFlatMap() {
- return Stream.of("foo").flatMap(v -> Stream.of(v.length()).filter(len -> len > 0));
+ return Stream.of("foo").flatMap(v -> Stream.of(v.length())).filter(len -> len > 0);
}MapOuterStreamAfterFlatMap
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("MapOuterStreamAfterFlatMap")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$MapOuterStreamAfterFlatMap).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testMapOuterStreamAfterFlatMap() {
- return Stream.of("foo").flatMap(v -> Stream.of(v.length()).map(len -> len * 0));
+ return Stream.of("foo").flatMap(v -> Stream.of(v.length())).map(len -> len * 0);
}FlatMapOuterStreamAfterFlatMap
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("FlatMapOuterStreamAfterFlatMap")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$FlatMapOuterStreamAfterFlatMap).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testFlatMapOuterStreamAfterFlatMap() {
- return Stream.of("foo").flatMap(v -> Stream.of(v.length()).flatMap(Stream::of));
+ return Stream.of("foo").flatMap(v -> Stream.of(v.length())).flatMap(Stream::of);
}StreamFilterSorted
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamFilterSorted")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamFilterSorted).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamFilterSorted() {
- return Stream.of(1, 4, 3, 2).sorted().filter(i -> i % 2 == 0);
+ return Stream.of(1, 4, 3, 2).filter(i -> i % 2 == 0).sorted();
}StreamFilterSortedWithComparator
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamFilterSortedWithComparator")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamFilterSortedWithComparator).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamFilterSortedWithComparator() {
- return Stream.of(1, 4, 3, 2).sorted(reverseOrder()).filter(i -> i % 2 == 0);
+ return Stream.of(1, 4, 3, 2).filter(i -> i % 2 == 0).sorted(reverseOrder());
}StreamMapFirst
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamMapFirst")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamMapFirst).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Optional<Integer>> testStreamMapFirst() {
return ImmutableSet.of(
- Stream.of("foo").map(s -> s.length()).findFirst(),
- Stream.of("bar").map(String::length).findFirst());
+ Stream.of("foo").findFirst().map(s -> s.length()),
+ Stream.of("bar").findFirst().map(String::length));
}StreamFindAnyIsEmpty
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamFindAnyIsEmpty")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamFindAnyIsEmpty).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testStreamFindAnyIsEmpty() {
return ImmutableSet.of(
- Stream.of(1).count() == 0,
- Stream.of(2).count() <= 0,
- Stream.of(3).count() < 1,
- Stream.of(4).findFirst().isEmpty(),
- Stream.of(5).collect(toImmutableSet()).isEmpty(),
- Stream.of(6).collect(collectingAndThen(toImmutableList(), List::isEmpty)),
- Stream.of(7).collect(collectingAndThen(toImmutableList(), ImmutableList::isEmpty)),
- Stream.of(8).collect(collectingAndThen(toImmutableMap(k -> k, v -> v), Map::isEmpty)),
- Stream.of(9)
- .collect(collectingAndThen(toImmutableMap(k -> k, v -> v), ImmutableMap::isEmpty)),
- Stream.of(10).count() != 0,
- Stream.of(11).count() > 0,
- Stream.of(12).count() >= 1);
+ Stream.of(1).findAny().isEmpty(),
+ Stream.of(2).findAny().isEmpty(),
+ Stream.of(3).findAny().isEmpty(),
+ Stream.of(4).findAny().isEmpty(),
+ Stream.of(5).findAny().isEmpty(),
+ Stream.of(6).findAny().isEmpty(),
+ Stream.of(7).findAny().isEmpty(),
+ Stream.of(8).findAny().isEmpty(),
+ Stream.of(9).findAny().isEmpty(),
+ !Stream.of(10).findAny().isEmpty(),
+ !Stream.of(11).findAny().isEmpty(),
+ !Stream.of(12).findAny().isEmpty());
}StreamFindAnyIsPresent
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamFindAnyIsPresent")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamFindAnyIsPresent).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
boolean testStreamFindAnyIsPresent() {
- return Stream.of(1).findFirst().isPresent();
+ return Stream.of(1).findAny().isPresent();
}StreamMapFilter
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamMapFilter")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamMapFilter).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamMapFilter() {
- return Stream.of("foo")
- .filter(ImmutableMap.of(1, 2)::containsKey)
- .map(ImmutableMap.of(1, 2)::get);
+ return Stream.of("foo").map(ImmutableMap.of(1, 2)::get).filter(Objects::nonNull);
}StreamMin
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamMin")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamMin).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Optional<String>> testStreamMin() {
return ImmutableSet.of(
- Stream.of("foo").max(comparingInt(String::length).reversed()),
- Stream.of("bar").sorted(comparingInt(String::length)).findFirst(),
- Stream.of("baz").collect(minBy(comparingInt(String::length))));
+ Stream.of("foo").min(comparingInt(String::length)),
+ Stream.of("bar").min(comparingInt(String::length)),
+ Stream.of("baz").min(comparingInt(String::length)));
}StreamMinNaturalOrder
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamMinNaturalOrder")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamMinNaturalOrder).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Optional<String>> testStreamMinNaturalOrder() {
return ImmutableSet.of(
- Stream.of("foo").max(reverseOrder()), Stream.of("bar").sorted().findFirst());
+ Stream.of("foo").min(naturalOrder()), Stream.of("bar").min(naturalOrder()));
}StreamMax
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamMax")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamMax).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Optional<String>> testStreamMax() {
return ImmutableSet.of(
- Stream.of("foo").min(comparingInt(String::length).reversed()),
- Streams.findLast(Stream.of("bar").sorted(comparingInt(String::length))),
- Stream.of("baz").collect(maxBy(comparingInt(String::length))));
+ Stream.of("foo").max(comparingInt(String::length)),
+ Stream.of("bar").max(comparingInt(String::length)),
+ Stream.of("baz").max(comparingInt(String::length)));
}StreamMaxNaturalOrder
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamMaxNaturalOrder")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamMaxNaturalOrder).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Optional<String>> testStreamMaxNaturalOrder() {
return ImmutableSet.of(
- Stream.of("foo").min(reverseOrder()), Streams.findLast(Stream.of("bar").sorted()));
+ Stream.of("foo").max(naturalOrder()), Stream.of("bar").max(naturalOrder()));
}StreamNoneMatch
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamNoneMatch")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamNoneMatch).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testStreamNoneMatch() {
Predicate<String> pred = String::isBlank;
Function<String, Boolean> toBooleanFunction = Boolean::valueOf;
return ImmutableSet.of(
- !Stream.of("foo").anyMatch(s -> s.length() > 1),
- Stream.of("bar").allMatch(not(String::isBlank)),
- Stream.of("baz").allMatch(pred.negate()),
- Stream.of("qux").filter(String::isEmpty).findAny().isEmpty(),
- Stream.of("quux").map(s -> s.isBlank()).noneMatch(Boolean::booleanValue),
- Stream.of("quuz").map(Boolean::valueOf).noneMatch(r -> r),
+ Stream.of("foo").noneMatch(s -> s.length() > 1),
+ Stream.of("bar").noneMatch(String::isBlank),
+ Stream.of("baz").noneMatch(pred),
+ Stream.of("qux").noneMatch(String::isEmpty),
+ Stream.of("quux").noneMatch(s -> s.isBlank()),
+ Stream.of("quuz").noneMatch(Boolean::valueOf),
Stream.of("corge").map(toBooleanFunction).noneMatch(Boolean::booleanValue));
}StreamNoneMatch2
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamNoneMatch2")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamNoneMatch2).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testStreamNoneMatch2() {
return ImmutableSet.of(
- Stream.of("foo").allMatch(s -> !s.isBlank()), Stream.of(Boolean.TRUE).allMatch(b -> !b));
+ Stream.of("foo").noneMatch(s -> s.isBlank()), Stream.of(Boolean.TRUE).noneMatch(b -> b));
}StreamAnyMatch
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamAnyMatch")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamAnyMatch).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testStreamAnyMatch() {
Function<String, Boolean> toBooleanFunction = Boolean::valueOf;
return ImmutableSet.of(
- !Stream.of("foo").noneMatch(s -> s.length() > 1),
- Stream.of("bar").filter(String::isEmpty).findAny().isPresent(),
- Stream.of("baz").map(s -> s.isBlank()).anyMatch(Boolean::booleanValue),
- Stream.of("qux").map(Boolean::valueOf).anyMatch(r -> r),
+ Stream.of("foo").anyMatch(s -> s.length() > 1),
+ Stream.of("bar").anyMatch(String::isEmpty),
+ Stream.of("baz").anyMatch(s -> s.isBlank()),
+ Stream.of("qux").anyMatch(Boolean::valueOf),
Stream.of("quux").map(toBooleanFunction).anyMatch(Boolean::booleanValue));
}StreamAllMatch
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamAllMatch")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamAllMatch).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testStreamAllMatch() {
Predicate<String> pred = String::isBlank;
Function<String, Boolean> toBooleanFunction = Boolean::valueOf;
return ImmutableSet.of(
- Stream.of("foo").noneMatch(not(String::isBlank)),
- Stream.of("bar").noneMatch(pred.negate()),
- Stream.of("baz").map(s -> s.isBlank()).allMatch(Boolean::booleanValue),
- Stream.of("qux").map(Boolean::valueOf).allMatch(r -> r),
+ Stream.of("foo").allMatch(String::isBlank),
+ Stream.of("bar").allMatch(pred),
+ Stream.of("baz").allMatch(s -> s.isBlank()),
+ Stream.of("qux").allMatch(Boolean::valueOf),
Stream.of("quux").map(toBooleanFunction).anyMatch(Boolean::booleanValue));
}StreamAllMatch2
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamAllMatch2")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamAllMatch2).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
boolean testStreamAllMatch2() {
- return Stream.of("foo").noneMatch(s -> !s.isBlank());
+ return Stream.of("foo").allMatch(s -> s.isBlank());
}StreamMapToIntSum
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamMapToIntSum")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamMapToIntSum).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Integer> testStreamMapToIntSum() {
Function<String, Integer> parseIntFunction = Integer::parseInt;
return ImmutableSet.of(
- Stream.of("1").collect(summingInt(Integer::parseInt)),
- Stream.of(2).map(i -> i * 2).reduce(0, Integer::sum),
- Stream.of("3").map(Integer::parseInt).reduce(0, Integer::sum),
+ Stream.of("1").mapToInt(Integer::parseInt).sum(),
+ Stream.of(2).mapToInt(i -> i * 2).sum(),
+ Stream.of("3").mapToInt(Integer::parseInt).sum(),
Stream.of("4").map(parseIntFunction).reduce(0, Integer::sum));
}StreamMapToDoubleSum
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamMapToDoubleSum")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamMapToDoubleSum).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Double> testStreamMapToDoubleSum() {
Function<String, Double> parseDoubleFunction = Double::parseDouble;
return ImmutableSet.of(
- Stream.of("1").collect(summingDouble(Double::parseDouble)),
- Stream.of(2).map(i -> i * 2.0).reduce(0.0, Double::sum),
- Stream.of("3").map(Double::parseDouble).reduce(0.0, Double::sum),
+ Stream.of("1").mapToDouble(Double::parseDouble).sum(),
+ Stream.of(2).mapToDouble(i -> i * 2.0).sum(),
+ Stream.of("3").mapToDouble(Double::parseDouble).sum(),
Stream.of("4").map(parseDoubleFunction).reduce(0.0, Double::sum));
}StreamMapToLongSum
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamMapToLongSum")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamMapToLongSum).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Long> testStreamMapToLongSum() {
Function<String, Long> parseLongFunction = Long::parseLong;
return ImmutableSet.of(
- Stream.of("1").collect(summingLong(Long::parseLong)),
- Stream.of(2).map(i -> i * 2L).reduce(0L, Long::sum),
- Stream.of("3").map(Long::parseLong).reduce(0L, Long::sum),
+ Stream.of("1").mapToLong(Long::parseLong).sum(),
+ Stream.of(2).mapToLong(i -> i * 2L).sum(),
+ Stream.of("3").mapToLong(Long::parseLong).sum(),
Stream.of("4").map(parseLongFunction).reduce(0L, Long::sum));
}StreamMapToIntSummaryStatistics
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamMapToIntSummaryStatistics")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamMapToIntSummaryStatistics).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
IntSummaryStatistics testStreamMapToIntSummaryStatistics() {
- return Stream.of("1").collect(summarizingInt(Integer::parseInt));
+ return Stream.of("1").mapToInt(Integer::parseInt).summaryStatistics();
}StreamMapToDoubleSummaryStatistics
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamMapToDoubleSummaryStatistics")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamMapToDoubleSummaryStatistics).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
DoubleSummaryStatistics testStreamMapToDoubleSummaryStatistics() {
- return Stream.of("1").collect(summarizingDouble(Double::parseDouble));
+ return Stream.of("1").mapToDouble(Double::parseDouble).summaryStatistics();
}StreamMapToLongSummaryStatistics
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamMapToLongSummaryStatistics")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamMapToLongSummaryStatistics).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
LongSummaryStatistics testStreamMapToLongSummaryStatistics() {
- return Stream.of("1").collect(summarizingLong(Long::parseLong));
+ return Stream.of("1").mapToLong(Long::parseLong).summaryStatistics();
}StreamCount
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamCount")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamCount).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Long testStreamCount() {
- return Stream.of(1).collect(counting());
+ return Stream.of(1).count();
}StreamReduce
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamReduce")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamReduce).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Optional<Integer> testStreamReduce() {
- return Stream.of(1).collect(reducing(Integer::sum));
+ return Stream.of(1).reduce(Integer::sum);
}StreamReduceWithIdentity
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamReduceWithIdentity")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamReduceWithIdentity).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Integer testStreamReduceWithIdentity() {
- return Stream.of(1).collect(reducing(0, Integer::sum));
+ return Stream.of(1).reduce(0, Integer::sum);
}StreamFilterCollect
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamFilterCollect")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamFilterCollect).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<String> testStreamFilterCollect() {
- return Stream.of("1").collect(filtering(String::isEmpty, toImmutableSet()));
+ return Stream.of("1").filter(String::isEmpty).collect(toImmutableSet());
}StreamMapCollect
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamMapCollect")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamMapCollect).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Integer> testStreamMapCollect() {
- return Stream.of("1").collect(mapping(Integer::parseInt, toImmutableSet()));
+ return Stream.of("1").map(Integer::parseInt).collect(toImmutableSet());
}StreamFlatMapCollect
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamFlatMapCollect")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamFlatMapCollect).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Integer> testStreamFlatMapCollect() {
- return Stream.of(1).collect(flatMapping(n -> Stream.of(n, n), toImmutableSet()));
+ return Stream.of(1).flatMap(n -> Stream.of(n, n)).collect(toImmutableSet());
}StreamsConcat
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamsConcat")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamsConcat).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Stream<Integer>> testStreamsConcat() {
return ImmutableSet.of(
- Stream.of(Stream.of(1), Stream.of(2)).flatMap(identity()),
- Stream.of(Stream.of(3), Stream.of(4)).flatMap(v -> v),
+ Streams.concat(Stream.of(1), Stream.of(2)),
+ Streams.concat(Stream.of(3), Stream.of(4)),
Stream.of(Stream.of(5), Stream.of(6)).flatMap(v -> Stream.empty()));
}StreamTakeWhile
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamTakeWhile")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamTakeWhile).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamTakeWhile() {
- return Stream.of(1, 2, 3).takeWhile(i -> i < 2).filter(i -> i < 2);
+ return Stream.of(1, 2, 3).takeWhile(i -> i < 2);
}StreamIterate
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamIterate")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamIterate).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamIterate() {
- return Stream.iterate(0, i -> i + 1).takeWhile(i -> i < 10);
+ return Stream.iterate(0, i -> i < 10, i -> i + 1);
}StreamOf1
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamOf1")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamOf1).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamOf1() {
- return ImmutableList.of(1).stream();
+ return Stream.of(1);
}StreamOf2
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamOf2")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamOf2).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamOf2() {
- return ImmutableList.of(1, 2).stream();
+ return Stream.of(1, 2);
}StreamOf3
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamOf3")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamOf3).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamOf3() {
- return ImmutableList.of(1, 2, 3).stream();
+ return Stream.of(1, 2, 3);
}StreamOf4
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamOf4")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamOf4).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamOf4() {
- return ImmutableList.of(1, 2, 3, 4).stream();
+ return Stream.of(1, 2, 3, 4);
}StreamOf5
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamOf5")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamOf5).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamOf5() {
- return ImmutableList.of(1, 2, 3, 4, 5).stream();
+ return Stream.of(1, 2, 3, 4, 5);
}