Skip to content

Commit

Permalink
Update FlagFactory.java
Browse files Browse the repository at this point in the history
  • Loading branch information
3rats authored Jun 28, 2024
1 parent 616f7e8 commit a4a0491
Showing 1 changed file with 13 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,20 @@
public class FlagFactory {

// tag::getFlag[]
private static Map<Nationality, List<Color>> FLAGS =
new HashMap<Nationality, List<Color>>();

static {
FLAGS.put(DUTCH, Arrays.asList(Color.RED, Color.WHITE, Color.BLUE));
FLAGS.put(GERMAN, Arrays.asList(Color.BLACK, Color.RED, Color.YELLOW));
FLAGS.put(BELGIAN, Arrays.asList(Color.BLACK, Color.YELLOW, Color.RED));
FLAGS.put(FRENCH, Arrays.asList(Color.BLUE, Color.WHITE, Color.RED));
FLAGS.put(ITALIAN, Arrays.asList(Color.GREEN, Color.WHITE, Color.RED));
}

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 Estonia:
result = Arrays.asList(, Color.BLUE, color.BLACK, Color.WHITE);
break;
case UNCLASSIFIED:
default:
result = Arrays.asList(Color.GRAY);
break;
}
return result;
List<Color> colors = FLAGS.get(nationality);
return colors != null ? colors : Arrays.asList(Color.GRAY);
}
// end::getFlag[]

Expand Down

0 comments on commit a4a0491

Please sign in to comment.