Skip to content

Commit

Permalink
migrate to Java 17 switch semantics: extras (#575)
Browse files Browse the repository at this point in the history
* migrate to Java 17 switch semantics: extras

replace legacy switch block with java 17 semantics:
1. short-circuit initialization in the switch expression
2. default case match with the original initialization
3. reduce complex boolean expression to an elegant form

Refs: #570 (review)
  • Loading branch information
gireeshpunathil committed Apr 13, 2023
1 parent 263fc98 commit d0a3839
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public SizeFilter(final int width, final int widthType, final int height, final
public boolean accept(final ImageElement element) {


boolean accept = true & switch (mWidthType) {
case TYPE_EXACT -> (element.getImageData().width == mWidth);
case TYPE_BIGGER_EQUALS -> (element.getImageData().width >= mWidth);
case TYPE_SMALLER_EQUALS -> (element.getImageData().width <= mWidth);
boolean accept = switch (mWidthType) {
case TYPE_EXACT -> element.getImageData().width == mWidth;
case TYPE_BIGGER_EQUALS -> element.getImageData().width >= mWidth;
case TYPE_SMALLER_EQUALS -> element.getImageData().width <= mWidth;
default -> true;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,12 @@ private void parse() throws Exception {
continue;
}

int opcode = 0;

opcode = switch (token) {
case T_AND -> opcode = OP_AND;
int opcode = switch (token) {
case T_AND -> OP_AND;
case T_OR -> OP_OR;
case T_EQ -> OP_EQ;
case T_NEQ -> OP_NEQ;
default -> opcode;
default -> 0;
};
if (opcode != 0) {
pushNode(opcode);
Expand Down

0 comments on commit d0a3839

Please sign in to comment.