Skip to content

Conversation

mohamedsamehsalah
Copy link
Contributor

@mohamedsamehsalah mohamedsamehsalah commented Aug 1, 2024

I think this is a candidate for "combinations of operators that don't make sense".

I tried to extend the rule with rules like

  static final class SetStreamFilter<T> {
    @BeforeTemplate
    Stream<?> before(Set<T> set, Predicate<T> predicate) {
      return set.stream().filter(predicate).distinct();
    }

    @AfterTemplate
    Stream<?> after(Set<T> set, Predicate<T> predicate) {
      return set.stream().filter(predicate);
    }
  }

But the number of permutations of different operators before using #distinct is a lot.

Suggested commit message

Rely on Set's property to preserve distinct elements when streaming

Copy link

github-actions bot commented Aug 1, 2024

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a commit.

Suggested commit message:

Introduce `SetStream` Refaster rule (#1264)

}
}

/** Rely on Set's property to preserve distinct elements. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does assume that the set doesn't use a custom equality, like a SortedSet might. Will add a note:

Suggested change
/** Rely on Set's property to preserve distinct elements. */
/** Don't unnecessarily call {@link Stream#distinct()} on an already-unique stream of elements. */
// XXX: This rule assumes that the `Set` relies on `Object#equals`, rather than a custom
// equivalence relation.
// XXX: Expressions that drop or reorder elements from the stream, such as `.filter`, `.skip` and
// `sorted`, can similarly be simplified. Covering all cases is better done using an Error Prone
// check.

(I'm not too worried about false positives: it's likely rare that there is code that wants cares about both types of deduplication in a single context.)

@Stephan202 Stephan202 added this to the 0.18.0 milestone Aug 4, 2024
@Stephan202 Stephan202 changed the title Rely on Set's property to preserve distinct elements when streaming Introduce SetStream Refaster rule Aug 4, 2024
Copy link

github-actions bot commented Aug 4, 2024

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.


/** Rely on Set's property to preserve distinct elements. */
/** Don't unnecessarily call {@link Stream#distinct()} on an already-unique stream of elements. */
// XXX: This rule assumes that the `Set` relies on `Object#equals`, rather than a custom
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧠

@rickie rickie force-pushed the mohamedsamehsalah/set-stream-distinct-operator branch from e8e702c to e04b23c Compare August 5, 2024 09:26
Copy link

github-actions bot commented Aug 5, 2024

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@rickie
Copy link
Member

rickie commented Aug 5, 2024

@hpnog Any additions from your side :)?

@mohamedsamehsalah
Copy link
Contributor Author

@hpnog Any additions from your side :)?

Discussed offline: We can proceed without @hpnog 's input.

@mohamedsamehsalah mohamedsamehsalah removed the request for review from hpnog August 5, 2024 11:03
@rickie rickie force-pushed the mohamedsamehsalah/set-stream-distinct-operator branch from e04b23c to a00559f Compare August 6, 2024 08:56
Copy link

github-actions bot commented Aug 6, 2024

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link

sonarqubecloud bot commented Aug 6, 2024

@rickie rickie merged commit a687f09 into master Aug 6, 2024
@rickie rickie deleted the mohamedsamehsalah/set-stream-distinct-operator branch August 6, 2024 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants