/** * <p> * Returns an iterator ranging from <code>head</code> to <code>tail</code>, inclusive. * </p> * * <p> * If <code>tail</code> is the element immediately preceding <code>head</code> in this <code>HashChain</code>, the returned * iterator will iterate 0 times (a special case to allow the specification of an empty range of elements). Otherwise if * <code>tail</code> is not one of the elements following <code>head</code>, the returned iterator will iterate past the * end of the <code>HashChain</code>, provoking a {@link NoSuchElementException}. * </p> * * @throws NoSuchElementException * if <code>head</code> is not an element of the chain. */ @Override @SuppressWarnings("unchecked") public Iterator<E> iterator(E head, E tail) { if (firstItem == null || isEmpty()) { return (Iterator<E>) emptyIterator; } if (head != null && this.getPredOf(head) == tail) { return (Iterator<E>) emptyIterator; } return new LinkIterator<E>(head, tail); }
/** <p>Returns an iterator ranging from <code>head</code> to * <code>tail</code>, inclusive.</p> <p>If <code>tail</code> is the element immediately preceding <code>head</code> in this <code>HashChain</code>, the returned iterator will iterate 0 times (a special case to allow the specification of an empty range of elements). Otherwise if <code>tail</code> is not one of the elements following <code>head</code>, the returned iterator will iterate past the end of the <code>HashChain</code>, provoking a {@link NoSuchElementException}.</p> @throws NoSuchElementException if <code>head</code> is not an element of the chain. */ public Iterator<E> iterator(E head, E tail) { if (head != null && this.getPredOf(head) == tail) { // special case hack, so empty ranges iterate 0 times return new LinkIterator(null, null); } else { return new LinkIterator(head, tail); } }
/** <p>Returns an iterator ranging from <code>head</code> to * <code>tail</code>, inclusive.</p> <p>If <code>tail</code> is the element immediately preceding <code>head</code> in this <code>HashChain</code>, the returned iterator will iterate 0 times (a special case to allow the specification of an empty range of elements). Otherwise if <code>tail</code> is not one of the elements following <code>head</code>, the returned iterator will iterate past the end of the <code>HashChain</code>, provoking a {@link NoSuchElementException}.</p> @throws NoSuchElementException if <code>head</code> is not an element of the chain. */ public Iterator<E> iterator(E head, E tail) { if (head != null && this.getPredOf(head) == tail) { // special case hack, so empty ranges iterate 0 times return new LinkIterator(null, null); } else { return new LinkIterator(head, tail); } }