Skip to content

Commit

Permalink
Update FlagFactory.java
Browse files Browse the repository at this point in the history
Het korter maken
  • Loading branch information
JitseGoutbeek authored Jun 28, 2024
1 parent 2ed3f1b commit 2306fbe
Showing 1 changed file with 19 additions and 48 deletions.
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[]

}

0 comments on commit 2306fbe

Please sign in to comment.