ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/DelayQueue.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/DelayQueue.java (file contents):
Revision 1.16 by dl, Mon Sep 15 12:02:46 2003 UTC vs.
Revision 1.17 by dl, Sun Oct 5 23:00:18 2003 UTC

# Line 197 | Line 197 | public class DelayQueue<E extends Delaye
197          }
198      }
199  
200 +    public int drainTo(Collection<? super E> c) {
201 +        if (c == null)
202 +            throw new NullPointerException();
203 +        if (c == this)
204 +            throw new IllegalArgumentException();
205 +        lock.lock();
206 +        try {
207 +            int n = 0;
208 +            for (;;) {
209 +                E first = q.peek();
210 +                if (first == null || first.getDelay(TimeUnit.NANOSECONDS) > 0)
211 +                    break;
212 +                c.add(q.poll());
213 +                ++n;
214 +            }
215 +            if (n > 0)
216 +                available.signalAll();
217 +            return n;
218 +        } finally {
219 +            lock.unlock();
220 +        }
221 +    }
222 +
223 +    public int drainTo(Collection<? super E> c, int maxElements) {
224 +        if (c == null)
225 +            throw new NullPointerException();
226 +        if (c == this)
227 +            throw new IllegalArgumentException();
228 +        if (maxElements <= 0)
229 +            return 0;
230 +        lock.lock();
231 +        try {
232 +            int n = 0;
233 +            while (n < maxElements) {
234 +                E first = q.peek();
235 +                if (first == null || first.getDelay(TimeUnit.NANOSECONDS) > 0)
236 +                    break;
237 +                c.add(q.poll());
238 +                ++n;
239 +            }
240 +            if (n > 0)
241 +                available.signalAll();
242 +            return n;
243 +        } finally {
244 +            lock.unlock();
245 +        }
246 +    }
247 +
248      /**
249       * Atomically removes all of the elements from this delay queue.
250       * The queue will be empty after this call returns.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines