1155 |
|
|
1156 |
|
public void forEachRemaining(Consumer<? super E> action) { |
1157 |
|
if (action == null) throw new NullPointerException(); |
1158 |
< |
if (!exhausted) { |
1159 |
< |
exhausted = true; |
1160 |
< |
Node<E> p = current; |
1161 |
< |
current = null; |
1162 |
< |
final LinkedBlockingDeque<E> q = this.queue; |
1163 |
< |
final ReentrantLock lock = q.lock; |
1164 |
< |
do { |
1165 |
< |
E e; |
1166 |
< |
lock.lock(); |
1167 |
< |
try { |
1168 |
< |
if (p == null) |
1169 |
< |
p = q.first; |
1170 |
< |
do { |
1171 |
< |
if (p == null) |
1172 |
< |
return; |
1173 |
< |
e = p.item; |
1174 |
< |
if (p == (p = p.next)) p = q.first; |
1175 |
< |
} while (e == null); |
1176 |
< |
} finally { |
1177 |
< |
lock.unlock(); |
1178 |
< |
} |
1179 |
< |
action.accept(e); |
1180 |
< |
} while (p != null); |
1181 |
< |
} |
1182 |
< |
} |
1183 |
< |
|
1184 |
< |
public boolean tryAdvance(Consumer<? super E> action) { |
1185 |
< |
if (action == null) throw new NullPointerException(); |
1186 |
< |
if (!exhausted) findElement: { |
1187 |
< |
final LinkedBlockingDeque<E> q = this.queue; |
1188 |
< |
final ReentrantLock lock = q.lock; |
1158 |
> |
if (exhausted) |
1159 |
> |
return; |
1160 |
> |
exhausted = true; |
1161 |
> |
final LinkedBlockingDeque<E> q = this.queue; |
1162 |
> |
final ReentrantLock lock = q.lock; |
1163 |
> |
Node<E> p = current; |
1164 |
> |
current = null; |
1165 |
> |
do { |
1166 |
|
E e; |
1190 |
– |
Node<E> p = current; |
1167 |
|
lock.lock(); |
1168 |
|
try { |
1169 |
< |
if (p == null) |
1169 |
> |
if (p == null || (p == p.next)) |
1170 |
|
p = q.first; |
1171 |
|
do { |
1172 |
< |
if (p == null) break findElement; |
1172 |
> |
if (p == null) |
1173 |
> |
return; |
1174 |
|
e = p.item; |
1175 |
< |
if (p == (p = p.next)) p = q.first; |
1175 |
> |
p = p.next; |
1176 |
|
} while (e == null); |
1177 |
|
} finally { |
1178 |
|
lock.unlock(); |
1179 |
|
} |
1180 |
|
action.accept(e); |
1181 |
< |
if ((current = p) == null) |
1182 |
< |
exhausted = true; |
1183 |
< |
return true; |
1181 |
> |
} while (p != null); |
1182 |
> |
} |
1183 |
> |
|
1184 |
> |
public boolean tryAdvance(Consumer<? super E> action) { |
1185 |
> |
if (action == null) throw new NullPointerException(); |
1186 |
> |
if (exhausted) |
1187 |
> |
return false; |
1188 |
> |
final LinkedBlockingDeque<E> q = this.queue; |
1189 |
> |
final ReentrantLock lock = q.lock; |
1190 |
> |
Node<E> p = current; |
1191 |
> |
E e = null; |
1192 |
> |
lock.lock(); |
1193 |
> |
try { |
1194 |
> |
if (p == null || p == p.next) |
1195 |
> |
p = q.first; |
1196 |
> |
do { |
1197 |
> |
if (p == null) |
1198 |
> |
break; |
1199 |
> |
e = p.item; |
1200 |
> |
p = p.next; |
1201 |
> |
} while (e == null); |
1202 |
> |
} finally { |
1203 |
> |
lock.unlock(); |
1204 |
|
} |
1205 |
< |
current = null; |
1206 |
< |
exhausted = true; |
1207 |
< |
return false; |
1205 |
> |
exhausted = ((current = p) == null); |
1206 |
> |
if (e == null) |
1207 |
> |
return false; |
1208 |
> |
action.accept(e); |
1209 |
> |
return true; |
1210 |
|
} |
1211 |
|
|
1212 |
|
public int characteristics() { |