EnumColors { @NotNull public Color getColor(@NotNull E type) { List<Color> colorList = myColors.get(type); if (colorList == null) { throw new IllegalStateException("No colors for value " + type); } return colorList.get(myColorIndex % colorList.size()); } EnumColors(@NotNull Map<E, Color> colors); private  EnumColors(@NotNull Builder<E> builder); @NotNull Color getColor(@NotNull E type); void setColorIndex(int colorIndex);  }
@Test public void createSimpleColorGroupUsingMap() throws Exception { ImmutableMap<TestStates, Color> colorMap = ImmutableMap.<TestStates, Color>builder() .put(TestStates.A, COLOR_A_0) .put(TestStates.B, COLOR_B_0) .put(TestStates.C, COLOR_C_0) .build(); EnumColors<TestStates> g = new EnumColors<>(colorMap); assertThat(g.getColor(TestStates.A)).isEqualTo(COLOR_A_0); assertThat(g.getColor(TestStates.B)).isEqualTo(COLOR_B_0); assertThat(g.getColor(TestStates.C)).isEqualTo(COLOR_C_0); }
@Test public void createSimpleColorGroupUsingBuilder() throws Exception { EnumColors<TestStates> g = new EnumColors.Builder<TestStates>(1) .add(TestStates.A, COLOR_A_0) .add(TestStates.B, COLOR_B_0) .add(TestStates.C, COLOR_C_0) .build(); assertThat(g.getColor(TestStates.A)).isEqualTo(COLOR_A_0); assertThat(g.getColor(TestStates.B)).isEqualTo(COLOR_B_0); assertThat(g.getColor(TestStates.C)).isEqualTo(COLOR_C_0); }