@Override
	public ExtendedIterator<T> iterator() {
		// prepare the sorted set
		final Collection<T> sorted;
		if (elements instanceof SortedSet<?> || elements instanceof List<?>) {
			//NOTE: SortedSet.comparator() is null
			sorted = elements;
		} else {
			sorted = new ArrayList<T>(elements);
			Collections.sort((List<T>) sorted);
		}
		
		// iterate over the sorted set
		return new ExtendedIterator<T>() {
			final Iterator<T> itr = sorted.iterator();
			T current;
			{
				current = itr.hasNext() ? itr.next() : null;
			}
			@Override
			public void skipAllBefore(T element) {
				while (element.compareTo(current) > 0) 
					next();
			}
			@Override public boolean hasNext() {
				return current != null;
			}
			@Override public T next() {
				if (!hasNext())
					throw new NoSuchElementException();
				T prev = current;
				current = itr.hasNext() ? itr.next() : null;
				return prev;
			}
			@Override public void remove() {
				throw new UnsupportedOperationException();
			}
		};
	}