Код из java.util.AbstractList:
copy to clipboardподсветка кода- /**
- * Compares the specified object with this list for equality. Returns
- * {@code true} if and only if the specified object is also a list, both
- * lists have the same size, and all corresponding pairs of elements in
- * the two lists are equal. (Two elements {@code e1} and
- * {@code e2} are equal if {@code (e1==null ? e2==null :
- * e1.equals(e2))}.) In other words, two lists are defined to be
- * equal if they contain the same elements in the same order.
- *
- * This implementation first checks if the specified object is this
- * list. If so, it returns {@code true}; if not, it checks if the
- * specified object is a list. If not, it returns {@code false}; if so,
- * it iterates over both lists, comparing corresponding pairs of elements.
- * If any comparison returns {@code false}, this method returns
- * {@code false}. If either iterator runs out of elements before the
- * other it returns {@code false} (as the lists are of unequal length);
- * otherwise it returns {@code true} when the iterations complete.
- *
- * @param o the object to be compared for equality with this list
- * @return {@code true} if the specified object is equal to this list
- */
- public boolean equals(Object o) {
- if (o == this)
- return true;
- if (!(o instanceof List))
- return false;
-
- ListIterator e1 = listIterator();
- ListIterator e2 = ((List) o).listIterator();
- while(e1.hasNext() && e2.hasNext()) {
- E o1 = e1.next();
- Object o2 = e2.next();
- if (!(o1==null ? o2==null : o1.equals(o2)))
- return false;
- }
- return !(e1.hasNext() || e2.hasNext());
- }
P. S.: сделано
http://aivolkov.ru/online-syntax-highlighter/