Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
fewer nested ifs
Browse files Browse the repository at this point in the history
  • Loading branch information
Avishai Weissberg committed Oct 21, 2021
1 parent 8450566 commit c0d69a2
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/main/java/com/ecwid/consul/v1/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,20 @@ public String toString() {

public String toEncodedString() {
final String prefix = positive ? "" : ("not" + SPACE);
if (leaf != null) {
if (leaf.value != null) {
if ((leaf.matchingOperator == MatchingOperator.IN) || (leaf.matchingOperator == MatchingOperator.NOT_IN)) {
return prefix + DOUBLEQUOTE + leaf.value + DOUBLEQUOTE + SPACE + leaf.matchingOperator.encoded + SPACE + leaf.selector;
}
return prefix + leaf.selector + SPACE + leaf.matchingOperator.encoded + SPACE + DOUBLEQUOTE + leaf.value + DOUBLEQUOTE;
if (leaf == null) {
final String result = children.stream().map(Filter::toEncodedString).collect(Collectors.joining(SPACE + boolOp + SPACE));
if ((parent == null) && positive) {
return result;
}
return prefix + "(" + result + ")";
}
if (leaf.value == null) {
return prefix + leaf.selector + SPACE + leaf.matchingOperator.encoded;
}

final String result = children.stream().map(Filter::toEncodedString).collect(Collectors.joining(SPACE + boolOp + SPACE));
if ((parent == null) && positive) {
return result;
if ((leaf.matchingOperator == MatchingOperator.IN) || (leaf.matchingOperator == MatchingOperator.NOT_IN)) {
return prefix + DOUBLEQUOTE + leaf.value + DOUBLEQUOTE + SPACE + leaf.matchingOperator.encoded + SPACE + leaf.selector;
}
return prefix + "(" + result + ")";
return prefix + leaf.selector + SPACE + leaf.matchingOperator.encoded + SPACE + DOUBLEQUOTE + leaf.value + DOUBLEQUOTE;
}

private enum BoolOp {
Expand Down

0 comments on commit c0d69a2

Please sign in to comment.