### Question:
SeparatorList extends TransformedList<E, E> { public void setComparator(Comparator<E> comparator) { final boolean isEmpty = isEmpty(); if (!isEmpty) { updates.beginEvent(); updates.addDelete(0, size() - 1); } SortedList<E> sortedList = (SortedList<E>)separatorSource.source; sortedList.setComparator(comparator); if (!isEmpty) { rebuildCollapsedElements(); updates.addInsert(0, size() - 1); updates.commitEvent(); } else { separatorSource.grouper.setComparator(comparator); } } SeparatorList(EventList<E> source, Comparator<? super E> comparator, int minimumSizeForSeparator, int defaultLimit); @Override int size(); void setComparator(Comparator<E> comparator); @Override void listChanged(ListEvent<E> listChanges); @Override void dispose();  }### Answer:
@Test public void testSortedSource() { Comparator<String> alphabetical = GlazedLists.comparableComparator(); Comparator<String> length = GlazedLists.reverseComparator(new StringLengthComparator()); BasicEventList<String> unsortedSource = new BasicEventList<>(); SortedList<String> source = new SortedList<>(unsortedSource, null); unsortedSource.addAll(Arrays.asList("apple", "banana", "cat", "dear", "frog", "boat", "car", "jesse", "glazed", "shirt", "hat", "art", "dog", "puppy", "foot")); SeparatorList<String> separatorList = new SeparatorList<>(source, length, 0, Integer.MAX_VALUE); ListConsistencyListener<String> listConsistencyListener = ListConsistencyListener.install(separatorList); listConsistencyListener.setPreviousElementTracked(false); assertEqualsIgnoreSeparators(source, separatorList, length); source.setComparator(alphabetical); assertEqualsIgnoreSeparators(source, separatorList, length); unsortedSource.addAll(Arrays.asList("apple", "banana", "cat", "art", "dog", "puppy", "foot", "carrot", "beer")); assertEqualsIgnoreSeparators(source, separatorList, length); source.setComparator(alphabetical); assertEqualsIgnoreSeparators(source, separatorList, length); }
@Test public void testSetComparator() { EventList<String> source = new BasicEventList<>(); source.addAll(GlazedListsTests.stringToList("AAaaaBBBBbCCCddd")); SeparatorList<String> separatorList = new SeparatorList<>(source, GlazedLists.caseInsensitiveComparator(), 0, Integer.MAX_VALUE); ListConsistencyListener<String> listConsistencyListener = ListConsistencyListener.install(separatorList); listConsistencyListener.setPreviousElementTracked(false); assertSeparatorEquals(separatorList.get(0), 5, "A"); assertSeparatorEquals(separatorList.get(6), 5, "B"); assertSeparatorEquals(separatorList.get(12), 3, "C"); assertSeparatorEquals(separatorList.get(16), 3, "d"); assertEquals(20, separatorList.size()); separatorList.setComparator(new CaseComparator()); assertSeparatorEquals(separatorList.get(0), 7, "a"); assertSeparatorEquals(separatorList.get(8), 9, "A"); assertEquals(18, separatorList.size()); source.addAll(5, GlazedListsTests.stringToList("aaaA")); assertSeparatorEquals(separatorList.get(0), 10, "a"); assertSeparatorEquals(separatorList.get(11), 10, "A"); assertEquals(22, separatorList.size()); separatorList.setComparator(GlazedLists.caseInsensitiveComparator()); assertSeparatorEquals(separatorList.get(0), 9, "A"); assertSeparatorEquals(separatorList.get(10), 5, "B"); assertSeparatorEquals(separatorList.get(16), 3, "C"); assertSeparatorEquals(separatorList.get(20), 3, "d"); assertEquals(24, separatorList.size()); }