.
, ,
import static <pkg>.StringUtils.isEmpty;
if (bothEmpty(A,B)) {
System.out.println("Case 4");
} else if (isEmpty(A)) {
System.out.println("Case 2");
} else if (isEmpty(B)) {
System.out.println("Case 3");
} else {
System.out.println("Case 1");
}
boolean bothEmpty(String A, String B){
return isEmpty(A) && isEmpty(B);
}
I usually return a value if the condition is satisfied. This avoids some duplication cases and nested if-else cases.
public originalAction(String A, String B){
System.out.println(value(A,B));
}
String value(String A, String B){
if (bothEmpty(A,B)) return "Case 4";
if (isEmpty(A)) return "Case 2";
if (isEmpty(B)) return "Case 3";
return "Case 1";
}
boolean bothEmpty(String A, String B){
return isEmpty(A) && isEmpty(B);
}
source
share