SmartHashSet extends THashSet<T> { @NotNull @Override public Iterator<T> iterator() { if (theElement != null) { return new SingletonIteratorBase<T>() { @Override protected void checkCoModification() { if (theElement == null) { throw new ConcurrentModificationException(); } } @Override protected T getElement() { return theElement; } @Override public void remove() { checkCoModification(); clear(); } }; } return super.iterator(); } SmartHashSet();  SmartHashSet(@NotNull TObjectHashingStrategy<T> strategy);  SmartHashSet(int initialCapacity);  SmartHashSet(int initialCapacity, TObjectHashingStrategy<T> strategy);  SmartHashSet(int initialCapacity, float loadFactor);  SmartHashSet(int initialCapacity, float loadFactor, TObjectHashingStrategy<T> strategy);  SmartHashSet(Collection<? extends T> collection);  SmartHashSet(Collection<? extends T> collection, TObjectHashingStrategy<T> strategy); @Override boolean contains(@NotNull Object obj); @Override boolean add(@NotNull T obj); @Override boolean equals(@NotNull Object other); @Override int hashCode(); @Override void clear(); @Override int size(); @Override boolean isEmpty(); @Override boolean remove(@NotNull Object obj); @NotNull @Override Iterator<T> iterator(); @Override boolean forEach(@NotNull TObjectProcedure<T> procedure); @NotNull @Override Object[] toArray(); @NotNull @Override T[] toArray(@NotNull T[] a);  }
@Test public void testIterator() { Set<Integer> set = new SmartHashSet<Integer>(); set.add(30); Iterator<Integer> iterator = set.iterator(); assertEquals((int)iterator.next(), 30); assertFalse(iterator.hasNext()); assertFalse(set.isEmpty()); iterator.remove(); assertTrue(set.isEmpty()); }