src/share/classes/java/util/AbstractList.java

Print this page




 546      * This implementation uses exactly the code that is used to define the
 547      * list hash function in the documentation for the {@link List#hashCode}
 548      * method.
 549      *
 550      * @return the hash code value for this list
 551      */
 552     public int hashCode() {
 553         int hashCode = 1;
 554         for (E e : this)
 555             hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
 556         return hashCode;
 557     }
 558 
 559     /**
 560      * Removes from this list all of the elements whose index is between
 561      * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
 562      * Shifts any succeeding elements to the left (reduces their index).
 563      * This call shortens the list by {@code (toIndex - fromIndex)} elements.
 564      * (If {@code toIndex==fromIndex}, this operation has no effect.)
 565      *
 566      * <p>This method is called by the {@code clear} operation on this list

 567      * and its subLists.  Overriding this method to take advantage of
 568      * the internals of the list implementation can <i>substantially</i>
 569      * improve the performance of the {@code clear} operation on this list
 570      * and its subLists.
 571      *
 572      * @implSpec
 573      * This implementation gets a list iterator positioned before
 574      * {@code fromIndex}, and repeatedly calls {@code ListIterator.next}
 575      * followed by {@code ListIterator.remove} until the entire range has
 576      * been removed.  <b>Note: if {@code ListIterator.remove} requires linear
 577      * time, this implementation requires quadratic time.</b>
 578      *
 579      * @param fromIndex index of first element to be removed
 580      * @param toIndex index after last element to be removed




 581      */
 582     protected void removeRange(int fromIndex, int toIndex) {
 583         ListIterator<E> it = listIterator(fromIndex);
 584         for (int i=0, n=toIndex-fromIndex; i<n; i++) {
 585             it.next();
 586             it.remove();
 587         }
 588     }
 589 
 590     /**
 591      * The number of times this list has been <i>structurally modified</i>.
 592      * Structural modifications are those that change the size of the
 593      * list, or otherwise perturb it in such a fashion that iterations in
 594      * progress may yield incorrect results.
 595      *
 596      * <p>This field is used by the iterator and list iterator implementation
 597      * returned by the {@code iterator} and {@code listIterator} methods.
 598      * If the value of this field changes unexpectedly, the iterator (or list
 599      * iterator) will throw a {@code ConcurrentModificationException} in
 600      * response to the {@code next}, {@code remove}, {@code previous},




 546      * This implementation uses exactly the code that is used to define the
 547      * list hash function in the documentation for the {@link List#hashCode}
 548      * method.
 549      *
 550      * @return the hash code value for this list
 551      */
 552     public int hashCode() {
 553         int hashCode = 1;
 554         for (E e : this)
 555             hashCode = 31*hashCode + (e==null ? 0 : e.hashCode());
 556         return hashCode;
 557     }
 558 
 559     /**
 560      * Removes from this list all of the elements whose index is between
 561      * {@code fromIndex}, inclusive, and {@code toIndex}, exclusive.
 562      * Shifts any succeeding elements to the left (reduces their index).
 563      * This call shortens the list by {@code (toIndex - fromIndex)} elements.
 564      * (If {@code toIndex==fromIndex}, this operation has no effect.)
 565      *
 566      * @implSpec
 567      * This method is called by the {@code clear} operation on this list
 568      * and its subLists.  Overriding this method to take advantage of
 569      * the internals of the list implementation can <i>substantially</i>
 570      * improve the performance of the {@code clear} operation on this list
 571      * and its subLists.
 572      *
 573      * <p>This implementation gets a list iterator positioned before

 574      * {@code fromIndex}, and repeatedly calls {@code ListIterator.next}
 575      * followed by {@code ListIterator.remove} until the entire range has
 576      * been removed.  <b>Note: if {@code ListIterator.remove} requires linear
 577      * time, this implementation requires quadratic time.</b>
 578      *
 579      * @param fromIndex index of first element to be removed
 580      * @param toIndex index after last element to be removed
 581      *
 582      * @throws IndexOutOfBoundsException if {@code (fromIndex < 0 ||
 583      *         fromIndex > size())}
 584      * @throws NoSuchElementException if {@code (toIndex > size())}
 585      */
 586     protected void removeRange(int fromIndex, int toIndex) {
 587         ListIterator<E> it = listIterator(fromIndex);
 588         for (int i=0, n=toIndex-fromIndex; i<n; i++) {
 589             it.next();
 590             it.remove();
 591         }
 592     }
 593 
 594     /**
 595      * The number of times this list has been <i>structurally modified</i>.
 596      * Structural modifications are those that change the size of the
 597      * list, or otherwise perturb it in such a fashion that iterations in
 598      * progress may yield incorrect results.
 599      *
 600      * <p>This field is used by the iterator and list iterator implementation
 601      * returned by the {@code iterator} and {@code listIterator} methods.
 602      * If the value of this field changes unexpectedly, the iterator (or list
 603      * iterator) will throw a {@code ConcurrentModificationException} in
 604      * response to the {@code next}, {@code remove}, {@code previous},