| 417 | } |
| 418 | |
| 419 | @Override |
| 420 | Iterator<Entry<E>> entryIterator() { |
| 421 | return new Iterator<Entry<E>>() { |
| 422 | AvlNode<E> current = firstNode(); |
| 423 | |
| 424 | Entry<E> prevEntry; |
| 425 | |
| 426 | @Override |
| 427 | public boolean hasNext() { |
| 428 | if (current == null) { |
| 429 | return false; |
| 430 | } else if (range.tooHigh(current.getElement())) { |
| 431 | current = null; |
| 432 | return false; |
| 433 | } else { |
| 434 | return true; |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | @Override |
| 439 | public Entry<E> next() { |
| 440 | if (!hasNext()) { |
| 441 | throw new NoSuchElementException(); |
| 442 | } |
| 443 | Entry<E> result = wrapEntry(current); |
| 444 | prevEntry = result; |
| 445 | if (current.succ == header) { |
| 446 | current = null; |
| 447 | } else { |
| 448 | current = current.succ; |
| 449 | } |
| 450 | return result; |
| 451 | } |
| 452 | |
| 453 | @Override |
| 454 | public void remove() { |
| 455 | checkRemove(prevEntry != null); |
| 456 | setCount(prevEntry.getElement(), 0); |
| 457 | prevEntry = null; |
| 458 | } |
| 459 | }; |
| 460 | } |
| 461 | |
| 462 | @Override |
| 463 | Iterator<Entry<E>> descendingEntryIterator() { |