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
- StreamIsEmpty
- StreamIsNotEmpty
- StreamMin
- StreamMinNaturalOrder
- StreamMax
- StreamMaxNaturalOrder
- StreamNoneMatch
- StreamNoneMatch2
- StreamAnyMatch
- StreamAllMatch
- StreamAllMatch2
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.
Stream<String> testEmptyStream() {
- return Stream.of();
+ return 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());
+ 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));
}
StreamIsEmpty
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamIsEmpty")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!(StreamRules\.StreamIsEmpty))
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testStreamIsEmpty() {
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(1).findAny().isEmpty(),
+ Stream.of(2).findAny().isEmpty(),
+ Stream.of(3).findAny().isEmpty(),
+ Stream.of(4).findAny().isEmpty());
}
StreamIsNotEmpty
SUGGESTION
Simplification
Suppression
Suppress false positives by adding the suppression annotation
@SuppressWarnings("StreamIsNotEmpty")
to the enclosing element.Disable this rule by adding
-XepOpt:Refaster:NamePattern=^(?!(StreamRules\.StreamIsNotEmpty))
as compiler argument.
Samples
Shows the difference in example code before and after the Refaster rule is applied.
ImmutableSet<Boolean> testStreamIsNotEmpty() {
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());
}
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("foo").min(comparingInt(String::length)),
+ Stream.of("bar").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("foo").max(comparingInt(String::length)),
+ Stream.of("bar").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;
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));
}
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() {
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));
}
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;
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));
}
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());
}