50 |
|
|
51 |
|
/** Doubly-linked list node class */ |
52 |
|
static final class Node<E> { |
53 |
< |
E item; |
53 |
> |
E item; |
54 |
|
Node<E> prev; |
55 |
|
Node<E> next; |
56 |
|
Node(E x, Node<E> p, Node<E> n) { |
157 |
|
return null; |
158 |
|
Node<E> n = f.next; |
159 |
|
first = n; |
160 |
< |
if (n == null) |
160 |
> |
if (n == null) |
161 |
|
last = null; |
162 |
< |
else |
162 |
> |
else |
163 |
|
n.prev = null; |
164 |
|
--count; |
165 |
|
notFull.signal(); |
175 |
|
return null; |
176 |
|
Node<E> p = l.prev; |
177 |
|
last = p; |
178 |
< |
if (p == null) |
178 |
> |
if (p == null) |
179 |
|
first = null; |
180 |
< |
else |
180 |
> |
else |
181 |
|
p.next = null; |
182 |
|
--count; |
183 |
|
notFull.signal(); |
191 |
|
Node<E> p = x.prev; |
192 |
|
Node<E> n = x.next; |
193 |
|
if (p == null) { |
194 |
< |
if (n == null) |
194 |
> |
if (n == null) |
195 |
|
first = last = null; |
196 |
|
else { |
197 |
|
n.prev = null; |
230 |
|
} |
231 |
|
} |
232 |
|
|
233 |
< |
public void addFirst(E e) { |
233 |
> |
public void addFirst(E e) { |
234 |
|
if (!offerFirst(e)) |
235 |
|
throw new IllegalStateException("Deque full"); |
236 |
|
} |
237 |
|
|
238 |
< |
public void addLast(E e) { |
238 |
> |
public void addLast(E e) { |
239 |
|
if (!offerLast(e)) |
240 |
|
throw new IllegalStateException("Deque full"); |
241 |
|
} |
365 |
|
lock.unlock(); |
366 |
|
} |
367 |
|
} |
368 |
< |
|
368 |
> |
|
369 |
|
public boolean offerLast(E o, long timeout, TimeUnit unit) |
370 |
|
throws InterruptedException { |
371 |
|
if (o == null) throw new NullPointerException(); |
384 |
|
} |
385 |
|
} |
386 |
|
|
387 |
< |
public E pollFirst(long timeout, TimeUnit unit) |
387 |
> |
public E pollFirst(long timeout, TimeUnit unit) |
388 |
|
throws InterruptedException { |
389 |
|
lock.lockInterruptibly(); |
390 |
|
try { |
402 |
|
} |
403 |
|
} |
404 |
|
|
405 |
< |
public E pollLast(long timeout, TimeUnit unit) |
405 |
> |
public E pollLast(long timeout, TimeUnit unit) |
406 |
|
throws InterruptedException { |
407 |
|
lock.lockInterruptibly(); |
408 |
|
try { |
479 |
|
if (o == null) return false; |
480 |
|
lock.lock(); |
481 |
|
try { |
482 |
< |
for (Node<E> p = first; p != null; p = p.next) |
482 |
> |
for (Node<E> p = first; p != null; p = p.next) |
483 |
|
if (o.equals(p.item)) |
484 |
|
return true; |
485 |
|
return false; |
544 |
|
try { |
545 |
|
Object[] a = new Object[count]; |
546 |
|
int k = 0; |
547 |
< |
for (Node<E> p = first; p != null; p = p.next) |
547 |
> |
for (Node<E> p = first; p != null; p = p.next) |
548 |
|
a[k++] = p.item; |
549 |
|
return a; |
550 |
|
} finally { |
562 |
|
); |
563 |
|
|
564 |
|
int k = 0; |
565 |
< |
for (Node<E> p = first; p != null; p = p.next) |
565 |
> |
for (Node<E> p = first; p != null; p = p.next) |
566 |
|
a[k++] = (T)p.item; |
567 |
|
if (a.length > k) |
568 |
|
a[k] = null; |
603 |
|
throw new IllegalArgumentException(); |
604 |
|
lock.lock(); |
605 |
|
try { |
606 |
< |
for (Node<E> p = first; p != null; p = p.next) |
606 |
> |
for (Node<E> p = first; p != null; p = p.next) |
607 |
|
c.add(p.item); |
608 |
|
int n = count; |
609 |
|
count = 0; |
680 |
|
/** |
681 |
|
* Advance next, or if not yet initialized, set to first node. |
682 |
|
*/ |
683 |
< |
private void advance() { |
683 |
> |
private void advance() { |
684 |
|
final ReentrantLock lock = LinkedBlockingDeque.this.lock; |
685 |
|
lock.lock(); |
686 |
|
try { |
758 |
|
add(item); |
759 |
|
} |
760 |
|
} |
761 |
< |
|
761 |
> |
|
762 |
|
} |