Skip to content

Commit

Permalink
Update FlagFactory.java
Browse files Browse the repository at this point in the history
  • Loading branch information
JitseGoutbeek authored Jun 28, 2024
1 parent 95cd4d1 commit eb38b90
Showing 1 changed file with 24 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,54 +1,35 @@
package eu.sig.training.ch03;
import static eu.sig.training.ch03.Nationality.BELGIAN;
import static eu.sig.training.ch03.Nationality.DUTCH;
import static eu.sig.training.ch03.Nationality.FRENCH;
import static eu.sig.training.ch03.Nationality.GERMAN;
import static eu.sig.training.ch03.Nationality.ITALIAN;
import static eu.sig.training.ch03.Nationality.UKRAINE;


import java.awt.Color;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FlagFactory {
public class FlagFactoryWithMap {

// 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));
FLAGS.put(UKRAINE, Arrays.asList(Color.BLUE, Color.YELLOW));
}

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;
List<Color> colors = FLAGS.get(nationality);
return colors != null ? colors : Arrays.asList(Color.GRAY);
}
// end::getFlag[]

Expand Down

0 comments on commit eb38b90

Please sign in to comment.