1042 |
|
} |
1043 |
|
|
1044 |
|
/** |
1045 |
+ |
* Returns the successor node of the given non-null, but |
1046 |
+ |
* possibly previously deleted, node. |
1047 |
+ |
*/ |
1048 |
+ |
private Node<E> succ(Node<E> n) { |
1049 |
+ |
// Chains of deleted nodes ending in null or self-links |
1050 |
+ |
// are possible if multiple interior nodes are removed. |
1051 |
+ |
for (;;) { |
1052 |
+ |
Node<E> s = nextNode(n); |
1053 |
+ |
if (s == null) |
1054 |
+ |
return null; |
1055 |
+ |
else if (s.item != null) |
1056 |
+ |
return s; |
1057 |
+ |
else if (s == n) |
1058 |
+ |
return firstNode(); |
1059 |
+ |
else |
1060 |
+ |
n = s; |
1061 |
+ |
} |
1062 |
+ |
} |
1063 |
+ |
|
1064 |
+ |
/** |
1065 |
|
* Advances next. |
1066 |
|
*/ |
1067 |
|
void advance() { |
1069 |
|
lock.lock(); |
1070 |
|
try { |
1071 |
|
// assert next != null; |
1072 |
< |
Node<E> s = nextNode(next); |
1053 |
< |
if (s == next) { |
1054 |
< |
next = firstNode(); |
1055 |
< |
} else { |
1056 |
< |
// Skip over removed nodes. |
1057 |
< |
// May be necessary if multiple interior Nodes are removed. |
1058 |
< |
while (s != null && s.item == null) |
1059 |
< |
s = nextNode(s); |
1060 |
< |
next = s; |
1061 |
< |
} |
1072 |
> |
next = succ(next); |
1073 |
|
nextItem = (next == null) ? null : next.item; |
1074 |
|
} finally { |
1075 |
|
lock.unlock(); |