@Test public void testChainedComparator() { sortedList.setComparator(null); Song nookie = new Song("Limp Bizkit", "Nookie"); Song eatYouAlive = new Song("Limp Bizkit", "Eat You Alive"); Song rearranged = new Song("Limp Bizkit", "Rearranged"); Song theUnquestionableTruth = new Song("Limp Bizkit", "The Unquestionable Truth"); Song welcomeToTheFold = new Song("Filter", "Welcome to the Fold"); Song takeAPicture = new Song("Filter", "Take a Picture"); Song missBlue = new Song("Filter", "Miss Blue"); unsortedList.add(nookie); unsortedList.add(eatYouAlive); unsortedList.add(takeAPicture); unsortedList.add(rearranged); unsortedList.add(missBlue); unsortedList.add(theUnquestionableTruth); unsortedList.add(welcomeToTheFold); assertSame(nookie, sortedList.get(0)); assertSame(eatYouAlive, sortedList.get(1)); assertSame(takeAPicture, sortedList.get(2)); assertSame(rearranged, sortedList.get(3)); assertSame(missBlue, sortedList.get(4)); assertSame(theUnquestionableTruth, sortedList.get(5)); assertSame(welcomeToTheFold, sortedList.get(6)); Comparator songComparator = GlazedLists.beanPropertyComparator(Song.class, "artist", "song"); sortedList.setComparator(songComparator); assertSame(missBlue, sortedList.get(0)); assertSame(takeAPicture, sortedList.get(1)); assertSame(welcomeToTheFold, sortedList.get(2)); assertSame(eatYouAlive, sortedList.get(3)); assertSame(nookie, sortedList.get(4)); assertSame(rearranged, sortedList.get(5)); assertSame(theUnquestionableTruth, sortedList.get(6)); }
public void setComparator(Comparator<? super E> comparator) { this.comparator = comparator; SimpleTree previousSorted = sorted; final Comparator treeComparator; if(comparator != null) treeComparator = new ElementComparator(comparator); else treeComparator = new ElementRawOrderComparator(); sorted = new SimpleTree<Element>(treeComparator); if(previousSorted == null && unsorted == null) { unsorted = new SimpleTree<>(); for(int i = 0, n = source.size(); i < n; i++) { Element unsortedNode = unsorted.add(i, EMPTY_ELEMENT, 1); insertByUnsortedNode(unsortedNode); } return; } if(source.isEmpty()) return; for(SimpleTreeIterator<Element> i = new SimpleTreeIterator<>(unsorted); i.hasNext(); ) { i.next(); Element unsortedNode = i.node(); insertByUnsortedNode(unsortedNode); } int[] reorderMap = new int[size()]; int oldSortedIndex = 0; for(SimpleTreeIterator<Element> i = new SimpleTreeIterator<Element>(previousSorted); i.hasNext(); oldSortedIndex++) { i.next(); Element oldSortedNode = i.node(); Element unsortedNode = (Element)oldSortedNode.get(); Element newSortedNode = (Element)unsortedNode.get(); int newSortedIndex = sorted.indexOfNode(newSortedNode, ALL_COLORS); reorderMap[newSortedIndex] = oldSortedIndex; } updates.beginEvent(); updates.reorder(reorderMap); updates.commitEvent(); }
SortedList extends TransformedList<E,E> { public void setComparator(Comparator<? super E> comparator) { this.comparator = comparator; SimpleTree previousSorted = sorted; final Comparator treeComparator; if(comparator != null) treeComparator = new ElementComparator(comparator); else treeComparator = new ElementRawOrderComparator(); sorted = new SimpleTree<Element>(treeComparator); if(previousSorted == null && unsorted == null) { unsorted = new SimpleTree<>(); for(int i = 0, n = source.size(); i < n; i++) { Element unsortedNode = unsorted.add(i, EMPTY_ELEMENT, 1); insertByUnsortedNode(unsortedNode); } return; } if(source.isEmpty()) return; for(SimpleTreeIterator<Element> i = new SimpleTreeIterator<>(unsorted); i.hasNext(); ) { i.next(); Element unsortedNode = i.node(); insertByUnsortedNode(unsortedNode); } int[] reorderMap = new int[size()]; int oldSortedIndex = 0; for(SimpleTreeIterator<Element> i = new SimpleTreeIterator<Element>(previousSorted); i.hasNext(); oldSortedIndex++) { i.next(); Element oldSortedNode = i.node(); Element unsortedNode = (Element)oldSortedNode.get(); Element newSortedNode = (Element)unsortedNode.get(); int newSortedIndex = sorted.indexOfNode(newSortedNode, ALL_COLORS); reorderMap[newSortedIndex] = oldSortedIndex; } updates.beginEvent(); updates.reorder(reorderMap); updates.commitEvent(); } }
SortedList extends TransformedList<E,E> { public void setComparator(Comparator<? super E> comparator) { this.comparator = comparator; SimpleTree previousSorted = sorted; final Comparator treeComparator; if(comparator != null) treeComparator = new ElementComparator(comparator); else treeComparator = new ElementRawOrderComparator(); sorted = new SimpleTree<Element>(treeComparator); if(previousSorted == null && unsorted == null) { unsorted = new SimpleTree<>(); for(int i = 0, n = source.size(); i < n; i++) { Element unsortedNode = unsorted.add(i, EMPTY_ELEMENT, 1); insertByUnsortedNode(unsortedNode); } return; } if(source.isEmpty()) return; for(SimpleTreeIterator<Element> i = new SimpleTreeIterator<>(unsorted); i.hasNext(); ) { i.next(); Element unsortedNode = i.node(); insertByUnsortedNode(unsortedNode); } int[] reorderMap = new int[size()]; int oldSortedIndex = 0; for(SimpleTreeIterator<Element> i = new SimpleTreeIterator<Element>(previousSorted); i.hasNext(); oldSortedIndex++) { i.next(); Element oldSortedNode = i.node(); Element unsortedNode = (Element)oldSortedNode.get(); Element newSortedNode = (Element)unsortedNode.get(); int newSortedIndex = sorted.indexOfNode(newSortedNode, ALL_COLORS); reorderMap[newSortedIndex] = oldSortedIndex; } updates.beginEvent(); updates.reorder(reorderMap); updates.commitEvent(); } SortedList(EventList<E> source);  SortedList(EventList<E> source, Comparator<? super E> comparator); }
SortedList extends TransformedList<E,E> { public void setComparator(Comparator<? super E> comparator) { this.comparator = comparator; SimpleTree previousSorted = sorted; final Comparator treeComparator; if(comparator != null) treeComparator = new ElementComparator(comparator); else treeComparator = new ElementRawOrderComparator(); sorted = new SimpleTree<Element>(treeComparator); if(previousSorted == null && unsorted == null) { unsorted = new SimpleTree<>(); for(int i = 0, n = source.size(); i < n; i++) { Element unsortedNode = unsorted.add(i, EMPTY_ELEMENT, 1); insertByUnsortedNode(unsortedNode); } return; } if(source.isEmpty()) return; for(SimpleTreeIterator<Element> i = new SimpleTreeIterator<>(unsorted); i.hasNext(); ) { i.next(); Element unsortedNode = i.node(); insertByUnsortedNode(unsortedNode); } int[] reorderMap = new int[size()]; int oldSortedIndex = 0; for(SimpleTreeIterator<Element> i = new SimpleTreeIterator<Element>(previousSorted); i.hasNext(); oldSortedIndex++) { i.next(); Element oldSortedNode = i.node(); Element unsortedNode = (Element)oldSortedNode.get(); Element newSortedNode = (Element)unsortedNode.get(); int newSortedIndex = sorted.indexOfNode(newSortedNode, ALL_COLORS); reorderMap[newSortedIndex] = oldSortedIndex; } updates.beginEvent(); updates.reorder(reorderMap); updates.commitEvent(); } SortedList(EventList<E> source);  SortedList(EventList<E> source, Comparator<? super E> comparator); static SortedList<E> create(EventList<E> source); void setMode(int mode); int getMode(); @Override void listChanged(ListEvent<E> listChanges); Comparator<? super E> getComparator(); void setComparator(Comparator<? super E> comparator); @Override int indexOf(Object object); @Override int lastIndexOf(Object object); int sortIndex(Object object); int lastSortIndex(Object object); @Deprecated int indexOfSimulated(Object object); @Override boolean contains(Object object); @Override Iterator<E> iterator(); }
SortedList extends TransformedList<E,E> { public void setComparator(Comparator<? super E> comparator) { this.comparator = comparator; SimpleTree previousSorted = sorted; final Comparator treeComparator; if(comparator != null) treeComparator = new ElementComparator(comparator); else treeComparator = new ElementRawOrderComparator(); sorted = new SimpleTree<Element>(treeComparator); if(previousSorted == null && unsorted == null) { unsorted = new SimpleTree<>(); for(int i = 0, n = source.size(); i < n; i++) { Element unsortedNode = unsorted.add(i, EMPTY_ELEMENT, 1); insertByUnsortedNode(unsortedNode); } return; } if(source.isEmpty()) return; for(SimpleTreeIterator<Element> i = new SimpleTreeIterator<>(unsorted); i.hasNext(); ) { i.next(); Element unsortedNode = i.node(); insertByUnsortedNode(unsortedNode); } int[] reorderMap = new int[size()]; int oldSortedIndex = 0; for(SimpleTreeIterator<Element> i = new SimpleTreeIterator<Element>(previousSorted); i.hasNext(); oldSortedIndex++) { i.next(); Element oldSortedNode = i.node(); Element unsortedNode = (Element)oldSortedNode.get(); Element newSortedNode = (Element)unsortedNode.get(); int newSortedIndex = sorted.indexOfNode(newSortedNode, ALL_COLORS); reorderMap[newSortedIndex] = oldSortedIndex; } updates.beginEvent(); updates.reorder(reorderMap); updates.commitEvent(); } SortedList(EventList<E> source);  SortedList(EventList<E> source, Comparator<? super E> comparator); static SortedList<E> create(EventList<E> source); void setMode(int mode); int getMode(); @Override void listChanged(ListEvent<E> listChanges); Comparator<? super E> getComparator(); void setComparator(Comparator<? super E> comparator); @Override int indexOf(Object object); @Override int lastIndexOf(Object object); int sortIndex(Object object); int lastSortIndex(Object object); @Deprecated int indexOfSimulated(Object object); @Override boolean contains(Object object); @Override Iterator<E> iterator(); static final int STRICT_SORT_ORDER; static final int AVOID_MOVING_ELEMENTS; }