[POO] simplified enums fromString
This commit is contained in:
parent
a158929283
commit
0aca8a95f2
|
@ -4,9 +4,9 @@ public enum EngineType {
|
|||
FUEL, ELECTRIC;
|
||||
|
||||
public static EngineType fromString(String string) {
|
||||
return switch (string) {
|
||||
case "FUEL", "Fuel", "fuel" -> EngineType.FUEL;
|
||||
case "ELECTRIC", "Electric", "electric" -> EngineType.ELECTRIC;
|
||||
return switch (string.toUpperCase()) {
|
||||
case "FUEL" -> FUEL;
|
||||
case "ELECTRIC" -> ELECTRIC;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@ public enum AlimentType {
|
|||
MEAT, FISH, CEREAL, VEGETABLE;
|
||||
|
||||
public static AlimentType fromString(String string) {
|
||||
return switch (string) {
|
||||
case "MEAT", "Meat", "meat" -> MEAT;
|
||||
case "FISH", "Fish", "fish" -> FISH;
|
||||
case "CEREAL", "Cereal", "cereal" -> CEREAL;
|
||||
case "VEGETABLE", "Vegetable", "vegetable" -> VEGETABLE;
|
||||
return switch (string.toUpperCase()) {
|
||||
case "MEAT"-> MEAT;
|
||||
case "FISH" -> FISH;
|
||||
case "CEREAL" -> CEREAL;
|
||||
case "VEGETABLE" -> VEGETABLE;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@ public enum DishType {
|
|||
NORMAL, VEGAN, DIET;
|
||||
|
||||
public static DishType fromString(String string) {
|
||||
return switch (string) {
|
||||
case "NORMAL", "Normal", "normal" -> NORMAL;
|
||||
case "VEGAN", "Vegan", "vegan" -> VEGAN;
|
||||
case "DIET", "Diet", "diet" -> DIET;
|
||||
return switch (string.toUpperCase()) {
|
||||
case "NORMAL" -> NORMAL;
|
||||
case "VEGAN" -> VEGAN;
|
||||
case "DIET" -> DIET;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@ public enum FishState {
|
|||
FRESH, FROZEN;
|
||||
|
||||
public static FishState fromString(String string) {
|
||||
return switch (string) {
|
||||
case "FRESH", "Fresh", "fresh" -> FRESH;
|
||||
case "FROZEN", "Frozen", "frozen" -> FROZEN;
|
||||
return switch (string.toUpperCase()) {
|
||||
case "FRESH"-> FRESH;
|
||||
case "FROZEN" -> FROZEN;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@ public enum MeatType {
|
|||
COW, PORK, TURKEY, CHICKEN;
|
||||
|
||||
public static MeatType fromString(String string) {
|
||||
return switch (string) {
|
||||
case "COW", "Cow", "cow" -> COW;
|
||||
case "PORK", "Pork", "pork" -> PORK;
|
||||
case "TURKEY", "Turkey", "turkey" -> TURKEY;
|
||||
case "CHICKEN", "Chicken", "chicken" -> CHICKEN;
|
||||
return switch (string.toUpperCase()) {
|
||||
case "COW" -> COW;
|
||||
case "PORK" -> PORK;
|
||||
case "TURKEY" -> TURKEY;
|
||||
case "CHICKEN" -> CHICKEN;
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue