IDEA-178242 Extract Set from comparison chain: find duplicates within class

This commit is contained in:
Tagir Valeev
2017-08-30 14:29:54 +07:00
parent f8c753ff81
commit ca9fffa746
4 changed files with 184 additions and 38 deletions
@@ -0,0 +1,35 @@
// "Extract Set from comparison chain" "true"
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
public class Test {
private static final Set<Status> STATUSES = Collections.unmodifiableSet(EnumSet.of(Status.VALID, Status.PENDING));
enum Status {
VALID, PENDING, INVALID, UNKNOWN;
}
void test1(Status status) {
if(STATUSES.contains(status)) {
System.out.println("ok");
}
}
static class Another {
static final String STATUSES = "";
void test2(Status st) {
if(st == null || Test.STATUSES.contains(st) || Math.random() > 0.5) {
System.out.println("Replace here as well");
}
}
void test3(Status st2) {
if(st2 == Status.VALID || st2 == Status.PENDING || st2 == Status.UNKNOWN) {
System.out.println("Do not replace as we test three statuses");
}
}
}
}
@@ -0,0 +1,29 @@
// "Extract Set from comparison chain" "true"
public class Test {
enum Status {
VALID, PENDING, INVALID, UNKNOWN;
}
void test1(Status status) {
if(status =<caret>= Status.VALID || status == Status.PENDING) {
System.out.println("ok");
}
}
static class Another {
static final String STATUSES = "";
void test2(Status st) {
if(st == null || Status.PENDING == st || Status.VALID == st || Math.random() > 0.5) {
System.out.println("Replace here as well");
}
}
void test3(Status st2) {
if(st2 == Status.VALID || st2 == Status.PENDING || st2 == Status.UNKNOWN) {
System.out.println("Do not replace as we test three statuses");
}
}
}
}