From a4a049194fd1210dd9face4d7c1975f34d9e6799 Mon Sep 17 00:00:00 2001 From: 3rats Date: Fri, 28 Jun 2024 12:09:53 +0200 Subject: [PATCH] Update FlagFactory.java --- .../ch03-complexity/flags/FlagFactory.java | 54 +++++-------------- 1 file changed, 13 insertions(+), 41 deletions(-) diff --git a/training-assignments/src/java/eu/sig/training/ch03-complexity/flags/FlagFactory.java b/training-assignments/src/java/eu/sig/training/ch03-complexity/flags/FlagFactory.java index 62a3e03..127e7f4 100755 --- a/training-assignments/src/java/eu/sig/training/ch03-complexity/flags/FlagFactory.java +++ b/training-assignments/src/java/eu/sig/training/ch03-complexity/flags/FlagFactory.java @@ -7,48 +7,20 @@ public class FlagFactory { // tag::getFlag[] + private static Map> FLAGS = + new HashMap>(); + + 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 getFlagColors(Nationality nationality) { - List 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 colors = FLAGS.get(nationality); + return colors != null ? colors : Arrays.asList(Color.GRAY); } // end::getFlag[]