StreamRules
SUGGESTION
Simplification
Suppression
Disable all rules by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$).*as compiler argument.
Table of contents
- Joining
- StreamEmpty
- StreamOfNullable
- ArraysStream
- StreamIdentity
- StreamConcat
- StreamFlatMapFilter
- StreamFlatMapMap
- StreamFlatMapFlatMap
- StreamSorted
- StreamFilterSorted
- StreamFilterSortedWithComparator
- StreamDistinctSorted
- StreamDistinctSortedWithComparator
- StreamCollectLeastStream
- StreamCollectLeastNaturalOrderStream
- StreamFindFirstMap
- StreamFindAnyIsEmpty
- StreamFindAnyIsPresent
- StreamFindFirst
- StreamMapMapGetFilterObjectsNonNull
- StreamMin
- StreamMinNaturalOrder
- StreamMax
- StreamMaxNaturalOrder
- StreamNoneMatchWithPredicate
- StreamNoneMatch
- StreamAnyMatch
- StreamAllMatchWithPredicate
- StreamAllMatch
- StreamMapToIntSum
- StreamMapToDoubleSum
- StreamMapToLongSum
- StreamMapToIntSummaryStatistics
- StreamMapToDoubleSummaryStatistics
- StreamMapToLongSummaryStatistics
- StreamCount
- StreamReduce
- StreamReduceWithObject
- StreamFilterCollect
- StreamMapCollect
- StreamFlatMapCollect
- StreamsConcat
- StreamTakeWhile
- StreamIterate
- StreamOf1
- StreamOf2
- StreamOf3
- StreamOf4
- StreamOf5
- StreamsStream
- CollectionParallelStream
- CollectionsNCopiesStream
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());
}StreamEmpty
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamEmpty")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamEmpty).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Stream<?>> testStreamEmpty() {
return ImmutableSet.of(
- Stream.of(),
- Optional.empty().stream(),
+ Stream.empty(),
+ Stream.empty(),
ImmutableList.of("foo").reverse().stream(),
- ImmutableList.of().stream(),
+ Stream.empty(),
Streams.stream(ImmutableSet.of("bar")::iterator),
- Streams.stream((Iterable<String>) ImmutableSet.<String>of()),
+ Stream.empty(),
Streams.stream(ImmutableSet.of("baz").iterator()),
- Streams.stream(ImmutableSet.of().iterator()),
+ Stream.empty(),
Arrays.stream(new String[] {"qux"}),
- Arrays.stream(new String[0]));
+ Stream.empty());
}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(),
- "c" != null ? Stream.of("c") : Stream.empty(),
- "d" == null ? Stream.empty() : Stream.of("d"));
+ Stream.ofNullable("a"),
+ Stream.ofNullable("b"),
+ Stream.ofNullable("c"),
+ Stream.ofNullable("d"));
}ArraysStream
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("ArraysStream")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$ArraysStream).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<String> testArraysStream() {
- return Stream.of(new String[] {"foo", "bar"});
+ return Arrays.stream(new String[] {"foo", "bar"});
}StreamIdentity
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamIdentity")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamIdentity).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamIdentity() {
- return Streams.concat(Stream.of(1));
+ return Stream.of(1);
}StreamConcat
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamConcat")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamConcat).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamConcat() {
- return Streams.concat(Stream.of(1), Stream.of(2));
+ return Stream.concat(Stream.of(1), Stream.of(2));
}StreamFlatMapFilter
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamFlatMapFilter")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamFlatMapFilter).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamFlatMapFilter() {
- 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);
}StreamFlatMapMap
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamFlatMapMap")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamFlatMapMap).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamFlatMapMap() {
- 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);
}StreamFlatMapFlatMap
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamFlatMapFlatMap")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamFlatMapFlatMap).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamFlatMapFlatMap() {
- 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);
}StreamSorted
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamSorted")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamSorted).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamSorted() {
- return Stream.of(1).sorted(naturalOrder());
+ return Stream.of(1).sorted();
}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).sorted().filter(i -> i % 2 == 0);
+ return Stream.of(1).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).sorted(reverseOrder()).filter(i -> i % 2 == 0);
+ return Stream.of(1).filter(i -> i % 2 == 0).sorted(reverseOrder());
}StreamDistinctSorted
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamDistinctSorted")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamDistinctSorted).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamDistinctSorted() {
- return Stream.of(1).sorted().distinct();
+ return Stream.of(1).distinct().sorted();
}StreamDistinctSortedWithComparator
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamDistinctSortedWithComparator")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamDistinctSortedWithComparator).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamDistinctSortedWithComparator() {
- return Stream.of(1).sorted(reverseOrder()).distinct();
+ return Stream.of(1).distinct().sorted(reverseOrder());
}StreamCollectLeastStream
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamCollectLeastStream")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamCollectLeastStream).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamCollectLeastStream() {
- return Stream.of(1).sorted(reverseOrder()).limit(2);
+ return Stream.of(1).collect(least(2, reverseOrder())).stream();
}StreamCollectLeastNaturalOrderStream
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamCollectLeastNaturalOrderStream")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamCollectLeastNaturalOrderStream).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamCollectLeastNaturalOrderStream() {
- return Stream.of(1).sorted().limit(2);
+ return Stream.of(1).collect(least(2, naturalOrder())).stream();
}StreamFindFirstMap
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamFindFirstMap")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamFindFirstMap).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Optional<Integer>> testStreamFindFirstMap() {
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(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());
}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.
ImmutableSet<Boolean> testStreamFindAnyIsPresent() {
return ImmutableSet.of(
- Stream.of(1).count() != 0,
- Stream.of(2).count() > 0,
- Stream.of(3).count() >= 1,
- Stream.of(4).findFirst().isPresent());
+ Stream.of(1).findAny().isPresent(),
+ Stream.of(2).findAny().isPresent(),
+ Stream.of(3).findAny().isPresent(),
+ Stream.of(4).findAny().isPresent());
}StreamFindFirst
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamFindFirst")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamFindFirst).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Optional<Integer>> testStreamFindFirst() {
- return ImmutableSet.of(Stream.of(1).limit(2).findFirst(), Stream.of(3).limit(4).findAny());
+ return ImmutableSet.of(Stream.of(1).findFirst(), Stream.of(3).findFirst());
}StreamMapMapGetFilterObjectsNonNull
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamMapMapGetFilterObjectsNonNull")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamMapMapGetFilterObjectsNonNull).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<Integer> testStreamMapMapGetFilterObjectsNonNull() {
- 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()));
}StreamNoneMatchWithPredicate
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamNoneMatchWithPredicate")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamNoneMatchWithPredicate).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testStreamNoneMatchWithPredicate() {
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("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").map(toBooleanFunction).noneMatch(Boolean::booleanValue),
- Stream.of("corge").map(s -> s.isBlank()).noneMatch(Boolean::booleanValue),
+ Stream.of("corge").noneMatch(s -> s.isBlank()),
Stream.of("grault").map(toBooleanFunction).noneMatch(r -> r),
- Stream.of("garply").map(Boolean::valueOf).noneMatch(r -> r));
+ Stream.of("garply").noneMatch(Boolean::valueOf));
}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() {
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("foo").anyMatch(s -> s.length() > 1),
+ Stream.of("bar").anyMatch(String::isEmpty),
Stream.of("baz").map(toBooleanFunction).anyMatch(Boolean::booleanValue),
- Stream.of("qux").map(s -> s.isBlank()).anyMatch(Boolean::booleanValue),
+ Stream.of("qux").anyMatch(s -> s.isBlank()),
Stream.of("quux").map(toBooleanFunction).anyMatch(r -> r),
- Stream.of("corge").map(Boolean::valueOf).anyMatch(r -> r));
+ Stream.of("corge").anyMatch(Boolean::valueOf));
}StreamAllMatchWithPredicate
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamAllMatchWithPredicate")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamAllMatchWithPredicate).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testStreamAllMatchWithPredicate() {
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("foo").allMatch(String::isBlank),
+ Stream.of("bar").allMatch(pred),
Stream.of("baz").map(toBooleanFunction).allMatch(Boolean::booleanValue),
- Stream.of("qux").map(s -> s.isBlank()).allMatch(Boolean::booleanValue),
+ Stream.of("qux").allMatch(s -> s.isBlank()),
Stream.of("quux").map(toBooleanFunction).allMatch(r -> r),
- Stream.of("corge").map(Boolean::valueOf).allMatch(r -> r));
+ Stream.of("corge").allMatch(Boolean::valueOf));
}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.
boolean testStreamAllMatch() {
- 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("1").mapToInt(Integer::parseInt).sum(),
Stream.of("2").map(parseIntFunction).reduce(0, Integer::sum),
- Stream.of(3).map(i -> i * 2).reduce(0, Integer::sum));
+ Stream.of(3).mapToInt(i -> i * 2).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("1").mapToDouble(Double::parseDouble).sum(),
Stream.of("2").map(parseDoubleFunction).reduce(0.0, Double::sum),
- Stream.of(3).map(i -> i * 2.0).reduce(0.0, Double::sum));
+ Stream.of(3).mapToDouble(i -> i * 2.0).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("1").mapToLong(Long::parseLong).sum(),
Stream.of("2").map(parseLongFunction).reduce(0L, Long::sum),
- Stream.of(3).map(i -> i * 2L).reduce(0L, Long::sum));
+ Stream.of(3).mapToLong(i -> i * 2L).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);
}StreamReduceWithObject
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamReduceWithObject")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamReduceWithObject).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Integer testStreamReduceWithObject() {
- 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(v -> Stream.empty()),
- Stream.of(Stream.of(3), Stream.of(4)).flatMap(identity()));
+ Streams.concat(Stream.of(3), Stream.of(4)));
}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);
}StreamsStream
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamsStream")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$StreamsStream).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<String> testStreamsStream() {
- return StreamSupport.stream(Iterables.cycle("foo").spliterator(), false);
+ return Streams.stream(Iterables.cycle("foo"));
}CollectionParallelStream
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("CollectionParallelStream")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$CollectionParallelStream).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
Stream<String> testCollectionParallelStream() {
- return StreamSupport.stream(ImmutableList.of("foo").spliterator(), true);
+ return ImmutableList.of("foo").parallelStream();
}CollectionsNCopiesStream
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("CollectionsNCopiesStream")to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!StreamRules\$CollectionsNCopiesStream).*as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Stream<String>> testCollectionsNCopiesStream() {
return ImmutableSet.of(
Stream.generate(() -> UUID.randomUUID().toString()).limit(1),
- Stream.generate(() -> "foo").limit(2));
+ Collections.nCopies(2, "foo").stream());
}