Use switch expressions where appropriate
See gh-31527
This commit is contained in:
committed by
Andy Wilkinson
parent
836b08f49d
commit
458f989cf3
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user