IDEA-181743 IntelliJ suggests bad refactoring for compareTo with Optionals

Reference expressions are compared instead of variables now
This commit is contained in:
Tagir Valeev
2017-11-10 16:35:26 +07:00
parent f01391541f
commit 5bd30e691d
3 changed files with 142 additions and 66 deletions

View File

@@ -0,0 +1,21 @@
// "Replace Optional.isPresent() condition with functional style expression" "true"
import java.util.Optional;
class Trip implements Comparable<Trip> {
Optional<Integer> originId;
public Trip(Optional<Integer> originId) {
this.originId = originId;
}
public Optional<Integer> getOriginId() {
return originId;
}
@Override
public int compareTo(Trip o) {
return this.originId.isPresent() ?
(o.originId.is<caret>Present() ? Integer.compare(this.originId.get(), o.originId.get()) : -1) :
(o.originId.isPresent() ? 1 : 0);
}
}