Skip to content

Commit

Permalink
refactor: use switch expression for the sake of more compact code
Browse files Browse the repository at this point in the history
  • Loading branch information
aoles committed May 21, 2024
1 parent d0ccc4a commit 6c4583a
Showing 1 changed file with 22 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public enum SurfaceType {

private final byte value;

private static final SurfaceType values[] = values();
private static final SurfaceType[] values = values();

private SurfaceType(int value) {
this.value = (byte) value;
}

public byte value() {
public byte value() {
return value;
}

Expand All @@ -54,54 +54,26 @@ public static SurfaceType getFromString(String surface) {

if (surface.contains(";"))
surface = surface.split(";")[0];
if (surface.contains(":"))
surface = surface.split(":")[0];

switch (surface.toLowerCase()) {
case "paved":
return SurfaceType.PAVED;
case "unpaved", "woodchips":
return SurfaceType.UNPAVED;
case "asphalt":
return SurfaceType.ASPHALT;
case "concrete":
case "concrete:lanes":
case "concrete:plates":
return SurfaceType.CONCRETE;
case "paving_stones":
case "paving_stones:20":
case "paving_stones:30":
case "paving_stones:50":
case "paved_stones":
case "cobblestone:flattened":
case "sett":
case "cobblestone":
return SurfaceType.PAVING_STONE;
case "metal":
return SurfaceType.METAL;
case "wood":
return SurfaceType.WOOD;
case "compacted":
case "pebblestone":
return SurfaceType.COMPACTED_GRAVEL;
case "fine_gravel":
case "gravel":
return SurfaceType.GRAVEL;
case "dirt":
return SurfaceType.DIRT;
case "ground":
case "earth":
case "mud":
return SurfaceType.GROUND;
case "ice":
case "snow":
return SurfaceType.ICE;
case "sand":
return SurfaceType.SAND;
case "grass":
return SurfaceType.GRASS;
case "grass_paver":
return SurfaceType.GRASS_PAVER;
}

return SurfaceType.UNKNOWN;
return switch (surface.toLowerCase()) {
case "paved" -> SurfaceType.PAVED;
case "unpaved", "woodchips" -> SurfaceType.UNPAVED;
case "asphalt" -> SurfaceType.ASPHALT;
case "concrete" -> SurfaceType.CONCRETE;
case "paving_stones", "paved_stones", "sett", "cobblestone" -> SurfaceType.PAVING_STONE;
case "metal" -> SurfaceType.METAL;
case "wood" -> SurfaceType.WOOD;
case "compacted", "pebblestone" -> SurfaceType.COMPACTED_GRAVEL;
case "gravel", "fine_gravel" -> SurfaceType.GRAVEL;
case "dirt" -> SurfaceType.DIRT;
case "ground", "earth", "mud" -> SurfaceType.GROUND;
case "ice", "snow" -> SurfaceType.ICE;
case "sand" -> SurfaceType.SAND;
case "grass" -> SurfaceType.GRASS;
case "grass_paver" -> SurfaceType.GRASS_PAVER;
default -> SurfaceType.UNKNOWN;
};
}
}

0 comments on commit 6c4583a

Please sign in to comment.