- public Iterator<Entry<K, V>> iterator () {
- return new NodeIterator<> (this);
- }
-
- static class NodeIterator<K,V> implements Iterator<Entry<K, V>> {
- ListMap<K, V> n;
-
- public NodeIterator (final Node<K, V> n) {
- this.n = n;
- }
-
- @Override
- public boolean hasNext () {
-// return n!= null && n.next != null && !(n.next instanceof EmptyListMap);
- return n!= null && !(n instanceof EmptyListMap);
- }
-
- @Override
- public Entry<K, V> next () {
- if (n instanceof Node) {
- Node<K, V> nn = (Node<K, V>) n;
- Entry<K, V> res = new SimpleImmutableEntry<> (nn.k, nn.v);
- n = n.next;
- return res;
- } else {
- return null;
- }
- }
-
- @Override
- public void remove () {
- throw new RuntimeException("Operation not supported");
+ public Entry<K, V> next() {
+ if (n == null) {
+ throw new NoSuchElementException();