719 |
|
/* -------------- Traversal methods -------------- */ |
720 |
|
|
721 |
|
/** |
722 |
– |
* Returns the successor of p, or the head node if p.next has been |
723 |
– |
* linked to self, which will only be true if traversing with a |
724 |
– |
* stale pointer that is now off the list. |
725 |
– |
*/ |
726 |
– |
final Node succ(Node p) { |
727 |
– |
Node next = p.next; |
728 |
– |
return (p == next) ? head : next; |
729 |
– |
} |
730 |
– |
|
731 |
– |
/** |
722 |
|
* Returns the first unmatched data node, or null if none. |
723 |
|
* Callers must recheck if the returned node is unmatched |
724 |
|
* before using. |
1468 |
|
*/ |
1469 |
|
public boolean contains(Object o) { |
1470 |
|
if (o != null) { |
1471 |
< |
for (Node p = head; p != null; p = succ(p)) { |
1471 |
> |
for (Node p = head; p != null; ) { |
1472 |
|
Object item = p.item; |
1473 |
|
if (p.isData) { |
1474 |
|
if (item != null && o.equals(item)) |
1476 |
|
} |
1477 |
|
else if (item == null) |
1478 |
|
break; |
1479 |
+ |
if (p == (p = p.next)) |
1480 |
+ |
p = head; |
1481 |
|
} |
1482 |
|
} |
1483 |
|
return false; |