FoldedTreeSet implements SortedSet<E> { @Override public Iterator<E> iterator() { return new TreeSetIterator<>(this); } FoldedTreeSet();  FoldedTreeSet(Comparator<E> comparator); @Override Comparator<? super E> comparator(); @Override SortedSet<E> subSet(E fromElement, E toElement); @Override SortedSet<E> headSet(E toElement); @Override SortedSet<E> tailSet(E fromElement); @Override E first(); @Override E last(); @Override int size(); @Override boolean isEmpty(); E get(Object obj, Comparator<?> cmp); E get(E entry); @Override @SuppressWarnings("unchecked") boolean contains(Object obj); @Override Iterator<E> iterator(); @Override Object[] toArray(); @Override @SuppressWarnings("unchecked") T[] toArray(T[] a); E addOrReplace(E entry); @Override boolean add(E entry); boolean addSortedLast(E entry); E removeAndGet(Object obj, Comparator<?> cmp); E removeAndGet(Object obj); boolean remove(Object obj, Comparator<?> cmp); @Override boolean remove(Object obj); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends E> c); @Override boolean retainAll(Collection<?> c); @Override boolean removeAll(Collection<?> c); @Override void clear(); double fillRatio(); boolean compact(long timeout);  }
@Test public void testIterator() { for (int iter = 0; iter < 10; iter++) { FoldedTreeSet<Holder> set = new FoldedTreeSet<>(); long[] longs = new long[64723]; for (int i = 0; i < longs.length; i++) { Holder val = new Holder(srand.nextLong()); while (set.contains(val)) { val = new Holder(srand.nextLong()); } longs[i] = val.getId(); set.add(val); } assertEquals(longs.length, set.size()); Arrays.sort(longs); Iterator<Holder> it = set.iterator(); for (int i = 0; i < longs.length; i++) { assertTrue(it.hasNext()); Holder val = it.next(); assertEquals(longs[i], val.getId()); if (srand.nextBoolean()) { it.remove(); } } } }