@Test public void flatten() { LetterSource letterA1 = TestUtil.createLetterSource("A"); letterA1.displayName = "Alice"; LetterSource letterA2 = TestUtil.createLetterSource("A"); letterA2.displayName = "Amy"; LetterSource letterB = TestUtil.createLetterSource("B"); letterB.displayName = "Belinda"; List<LetterSource> sources = Arrays.asList(letterA2, letterB, letterA1); AvailableLetters availableLetters = new AvailableLetters(sources); assertEquals(2, availableLetters.size()); assertNotNull(availableLetters.get("A")); assertEquals(2, availableLetters.get("A").size()); assertNotNull(availableLetters.get("B")); assertEquals(1, availableLetters.get("B").size()); assertNull(availableLetters.get("C")); List<LetterSource> flattened = availableLetters.getFlatList(); assertEquals(3, flattened.size()); assertEquals(letterA1, flattened.get(0)); assertEquals(letterA2, flattened.get(1)); assertEquals(letterB, flattened.get(2)); }
public List<LetterSource> getFlatList() { ArrayList<LetterSource> flattened = new ArrayList<>(); for (List<LetterSource> letterSources : values()) { flattened.addAll(letterSources); } Collections.sort(flattened, COMPARATOR); return flattened; }
AvailableLetters extends HashMap<String, List<LetterSource>> { public List<LetterSource> getFlatList() { ArrayList<LetterSource> flattened = new ArrayList<>(); for (List<LetterSource> letterSources : values()) { flattened.addAll(letterSources); } Collections.sort(flattened, COMPARATOR); return flattened; } }
AvailableLetters extends HashMap<String, List<LetterSource>> { public List<LetterSource> getFlatList() { ArrayList<LetterSource> flattened = new ArrayList<>(); for (List<LetterSource> letterSources : values()) { flattened.addAll(letterSources); } Collections.sort(flattened, COMPARATOR); return flattened; } AvailableLetters(List<LetterSource> letters); }
AvailableLetters extends HashMap<String, List<LetterSource>> { public List<LetterSource> getFlatList() { ArrayList<LetterSource> flattened = new ArrayList<>(); for (List<LetterSource> letterSources : values()) { flattened.addAll(letterSources); } Collections.sort(flattened, COMPARATOR); return flattened; } AvailableLetters(List<LetterSource> letters); List<LetterSource> getFlatList(); }
AvailableLetters extends HashMap<String, List<LetterSource>> { public List<LetterSource> getFlatList() { ArrayList<LetterSource> flattened = new ArrayList<>(); for (List<LetterSource> letterSources : values()) { flattened.addAll(letterSources); } Collections.sort(flattened, COMPARATOR); return flattened; } AvailableLetters(List<LetterSource> letters); List<LetterSource> getFlatList();  }