2007-07-20 00:18:47 +00:00
|
|
|
package java.lang.ref;
|
|
|
|
|
2007-07-20 03:18:25 +00:00
|
|
|
public class ReferenceQueue<T> {
|
2007-07-20 00:18:47 +00:00
|
|
|
private Reference<? extends T> front;
|
|
|
|
private Reference<? extends T> rear;
|
|
|
|
|
|
|
|
public Reference<? extends T> poll() {
|
|
|
|
Reference<? extends T> r = front;
|
|
|
|
if (front != null) {
|
|
|
|
if (front == front.next) {
|
|
|
|
front = rear = null;
|
|
|
|
} else {
|
|
|
|
front = front.next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
void add(Reference<? extends T> r) {
|
|
|
|
r.next = r;
|
|
|
|
if (front == null) {
|
2007-07-20 01:07:30 +00:00
|
|
|
front = r;
|
2007-07-20 00:18:47 +00:00
|
|
|
} else {
|
|
|
|
rear.next = r;
|
|
|
|
}
|
2007-07-20 01:07:30 +00:00
|
|
|
rear = r;
|
2007-07-20 00:18:47 +00:00
|
|
|
}
|
|
|
|
}
|