499 *
500 * This implementation first checks if the specified object is this
501 * list. If so, it returns {@code true}; if not, it checks if the
502 * specified object is a list. If not, it returns {@code false}; if so,
503 * it iterates over both lists, comparing corresponding pairs of elements.
504 * If any comparison returns {@code false}, this method returns
505 * {@code false}. If either iterator runs out of elements before the
506 * other it returns {@code false} (as the lists are of unequal length);
507 * otherwise it returns {@code true} when the iterations complete.
508 *
509 * @param o the object to be compared for equality with this list
510 * @return {@code true} if the specified object is equal to this list
511 */
512 public boolean equals(Object o) {
513 if (o == this)
514 return true;
515 if (!(o instanceof List))
516 return false;
517
518 ListIterator<E> e1 = listIterator();
519 ListIterator e2 = ((List) o).listIterator();
520 while (e1.hasNext() && e2.hasNext()) {
521 E o1 = e1.next();
522 Object o2 = e2.next();
523 if (!(o1==null ? o2==null : o1.equals(o2)))
524 return false;
525 }
526 return !(e1.hasNext() || e2.hasNext());
527 }
528
529 /**
530 * Returns the hash code value for this list.
531 *
532 * <p>This implementation uses exactly the code that is used to define the
533 * list hash function in the documentation for the {@link List#hashCode}
534 * method.
535 *
536 * @return the hash code value for this list
537 */
538 public int hashCode() {
539 int hashCode = 1;
|
499 *
500 * This implementation first checks if the specified object is this
501 * list. If so, it returns {@code true}; if not, it checks if the
502 * specified object is a list. If not, it returns {@code false}; if so,
503 * it iterates over both lists, comparing corresponding pairs of elements.
504 * If any comparison returns {@code false}, this method returns
505 * {@code false}. If either iterator runs out of elements before the
506 * other it returns {@code false} (as the lists are of unequal length);
507 * otherwise it returns {@code true} when the iterations complete.
508 *
509 * @param o the object to be compared for equality with this list
510 * @return {@code true} if the specified object is equal to this list
511 */
512 public boolean equals(Object o) {
513 if (o == this)
514 return true;
515 if (!(o instanceof List))
516 return false;
517
518 ListIterator<E> e1 = listIterator();
519 ListIterator<?> e2 = ((List<?>) o).listIterator();
520 while (e1.hasNext() && e2.hasNext()) {
521 E o1 = e1.next();
522 Object o2 = e2.next();
523 if (!(o1==null ? o2==null : o1.equals(o2)))
524 return false;
525 }
526 return !(e1.hasNext() || e2.hasNext());
527 }
528
529 /**
530 * Returns the hash code value for this list.
531 *
532 * <p>This implementation uses exactly the code that is used to define the
533 * list hash function in the documentation for the {@link List#hashCode}
534 * method.
535 *
536 * @return the hash code value for this list
537 */
538 public int hashCode() {
539 int hashCode = 1;
|