Created
April 22, 2022 15:34
-
-
Save otrack/2ff3f7ce148b0cec5638856299211b13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class setsIterator<V> implements Iterator<V> { | |
Iterator<Set<V>> _inUnion; | |
Iterator<V> _inSet; | |
Collection<Set<V>> _elements; | |
public setsIterator(Collection<Set<V>> elts) { | |
_elements = elts; | |
if (_elements.size() > 0) { | |
_inUnion = _elements.iterator(); | |
_inSet = _inUnion.next().iterator(); | |
} | |
} | |
public boolean hasNext() { | |
if (_inUnion == null) return false; | |
if (!_inSet.hasNext()) { | |
do { | |
if (!_inUnion.hasNext()) return false; | |
_inSet = _inUnion.next().iterator(); | |
} | |
while (!_inSet.hasNext()); | |
} | |
return true; | |
} | |
public V next() { | |
if (!_inSet.hasNext()) { | |
do { | |
if (!_inUnion.hasNext()) throw new NoSuchElementException(); | |
_inSet = _inUnion.next().iterator(); | |
} | |
while (!_inSet.hasNext()); | |
} | |
return _inSet.next(); | |
} | |
public void remove() { | |
throw new UnsupportedOperationException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment