Use switch expressions where appropriate

See gh-31527
This commit is contained in:
dreis2211
2022-06-24 15:55:11 +02:00
committed by Andy Wilkinson
parent 836b08f49d
commit 458f989cf3
19 changed files with 136 additions and 252 deletions

View File

@@ -34,20 +34,13 @@ public class Location {
}
public Location getAdjacentLocation(Direction direction) {
switch (direction) {
case NORTH:
return new Location(this.x, this.y - SnakeUtils.GRID_SIZE);
case SOUTH:
return new Location(this.x, this.y + SnakeUtils.GRID_SIZE);
case EAST:
return new Location(this.x + SnakeUtils.GRID_SIZE, this.y);
case WEST:
return new Location(this.x - SnakeUtils.GRID_SIZE, this.y);
case NONE:
// fall through
default:
return this;
}
return switch (direction) {
case NORTH -> new Location(this.x, this.y - SnakeUtils.GRID_SIZE);
case SOUTH -> new Location(this.x, this.y + SnakeUtils.GRID_SIZE);
case EAST -> new Location(this.x + SnakeUtils.GRID_SIZE, this.y);
case WEST -> new Location(this.x - SnakeUtils.GRID_SIZE, this.y);
case NONE -> this;
};
}
@Override

View File

@@ -34,20 +34,13 @@ public class Location {
}
public Location getAdjacentLocation(Direction direction) {
switch (direction) {
case NORTH:
return new Location(this.x, this.y - SnakeUtils.GRID_SIZE);
case SOUTH:
return new Location(this.x, this.y + SnakeUtils.GRID_SIZE);
case EAST:
return new Location(this.x + SnakeUtils.GRID_SIZE, this.y);
case WEST:
return new Location(this.x - SnakeUtils.GRID_SIZE, this.y);
case NONE:
// fall through
default:
return this;
}
return switch (direction) {
case NORTH -> new Location(this.x, this.y - SnakeUtils.GRID_SIZE);
case SOUTH -> new Location(this.x, this.y + SnakeUtils.GRID_SIZE);
case EAST -> new Location(this.x + SnakeUtils.GRID_SIZE, this.y);
case WEST -> new Location(this.x - SnakeUtils.GRID_SIZE, this.y);
case NONE -> this;
};
}
@Override

View File

@@ -34,20 +34,13 @@ public class Location {
}
public Location getAdjacentLocation(Direction direction) {
switch (direction) {
case NORTH:
return new Location(this.x, this.y - SnakeUtils.GRID_SIZE);
case SOUTH:
return new Location(this.x, this.y + SnakeUtils.GRID_SIZE);
case EAST:
return new Location(this.x + SnakeUtils.GRID_SIZE, this.y);
case WEST:
return new Location(this.x - SnakeUtils.GRID_SIZE, this.y);
case NONE:
// fall through
default:
return this;
}
return switch (direction) {
case NORTH -> new Location(this.x, this.y - SnakeUtils.GRID_SIZE);
case SOUTH -> new Location(this.x, this.y + SnakeUtils.GRID_SIZE);
case EAST -> new Location(this.x + SnakeUtils.GRID_SIZE, this.y);
case WEST -> new Location(this.x - SnakeUtils.GRID_SIZE, this.y);
case NONE -> this;
};
}
@Override