generated from clean-code-workshop/sigrid-training-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
19 additions
and
48 deletions.
There are no files selected for viewing
67 changes: 19 additions & 48 deletions
67
training-assignments/src/java/eu/sig/training/ch03-complexity/flags/FlagFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,26 @@ | ||
package eu.sig.training.ch03; | ||
|
||
import java.awt.Color; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Collections; | ||
import static java.util.Map.entry; | ||
|
||
public class FlagFactory { | ||
private static final Map<Nationality, List<Color>> FLAG_COLORS = Map.ofEntries( | ||
entry(Nationality.DUTCH, List.of(Color.RED, Color.WHITE, Color.BLUE)), | ||
entry(Nationality.GERMAN, List.of(Color.BLACK, Color.RED, Color.YELLOW)), | ||
entry(Nationality.BELGIAN, List.of(Color.BLACK, Color.YELLOW, Color.RED)), | ||
entry(Nationality.FRENCH, List.of(Color.BLUE, Color.WHITE, Color.RED)), | ||
entry(Nationality.ITALIAN, List.of(Color.GREEN, Color.WHITE, Color.RED)), | ||
entry(Nationality.ROMANIA, List.of(Color.BLUE, Color.YELLOW, Color.RED)), | ||
entry(Nationality.IRELAND, List.of(Color.GREEN, Color.WHITE, Color.ORANGE)), | ||
entry(Nationality.HUNGARIAN, List.of(Color.RED, Color.WHITE, Color.GREEN)), | ||
entry(Nationality.BULGARIAN, List.of(Color.WHITE, Color.GREEN, Color.RED)), | ||
entry(Nationality.RUSSIA, List.of(Color.WHITE, Color.BLUE, Color.RED)), | ||
entry(Nationality.UKRAINE, List.of(Color.BLUE, Color.YELLOW)) | ||
); | ||
|
||
private static final List<Color> DEFAULT_FLAG = List.of(Color.GRAY); | ||
|
||
// tag::getFlag[] | ||
public List<Color> getFlagColors(Nationality nationality) { | ||
List<Color> result; | ||
switch (nationality) { | ||
case DUTCH: | ||
result = Arrays.asList(Color.RED, Color.WHITE, Color.BLUE); | ||
break; | ||
case GERMAN: | ||
result = Arrays.asList(Color.BLACK, Color.RED, Color.YELLOW); | ||
break; | ||
case BELGIAN: | ||
result = Arrays.asList(Color.BLACK, Color.YELLOW, Color.RED); | ||
break; | ||
case FRENCH: | ||
result = Arrays.asList(Color.BLUE, Color.WHITE, Color.RED); | ||
break; | ||
case ITALIAN: | ||
result = Arrays.asList(Color.GREEN, Color.WHITE, Color.RED); | ||
break; | ||
case ROMANIA: | ||
result = Arrays.asList(Color.BLUE, Color.YELLOW, Color.RED); | ||
break; | ||
case IRELAND: | ||
result = Arrays.asList(Color.GREEN, Color.WHITE, Color.ORANGE); | ||
break; | ||
case HUNGARIAN: | ||
result = Arrays.asList(Color.RED, Color.WHITE, Color.GREEN); | ||
break; | ||
case BULGARIAN: | ||
result = Arrays.asList(Color.WHITE, Color.GREEN, Color.RED); | ||
break; | ||
case RUSSIA: | ||
result = Arrays.asList(Color.WHITE, Color.BLUE, Color.RED); | ||
break; | ||
case UKRAINE: | ||
result = Arrays.asList(Color.BLUE, Color.YELLOW); | ||
break; | ||
case UNCLASSIFIED: | ||
default: | ||
result = Arrays.asList(Color.GRAY); | ||
break; | ||
} | ||
return result; | ||
return FLAG_COLORS.getOrDefault(nationality, DEFAULT_FLAG); | ||
} | ||
// end::getFlag[] | ||
|
||
} |