320 public boolean add(E e) {
321 return offer(e);
322 }
323
324 /**
325 * Inserts the specified element into this priority queue.
326 *
327 * @return {@code true} (as specified by {@link Queue#offer})
328 * @throws ClassCastException if the specified element cannot be
329 * compared with elements currently in this priority queue
330 * according to the priority queue's ordering
331 * @throws NullPointerException if the specified element is null
332 */
333 public boolean offer(E e) {
334 if (e == null)
335 throw new NullPointerException();
336 modCount++;
337 int i = size;
338 if (i >= queue.length)
339 grow(i + 1);
340 size = i + 1;
341 if (i == 0)
342 queue[0] = e;
343 else
344 siftUp(i, e);
345 return true;
346 }
347
348 @SuppressWarnings("unchecked")
349 public E peek() {
350 return (size == 0) ? null : (E) queue[0];
351 }
352
353 private int indexOf(Object o) {
354 if (o != null) {
355 for (int i = 0; i < size; i++)
356 if (o.equals(queue[i]))
357 return i;
358 }
359 return -1;
360 }
361
362 /**
363 * Removes a single instance of the specified element from this queue,
364 * if it is present. More formally, removes an element {@code e} such
|
320 public boolean add(E e) {
321 return offer(e);
322 }
323
324 /**
325 * Inserts the specified element into this priority queue.
326 *
327 * @return {@code true} (as specified by {@link Queue#offer})
328 * @throws ClassCastException if the specified element cannot be
329 * compared with elements currently in this priority queue
330 * according to the priority queue's ordering
331 * @throws NullPointerException if the specified element is null
332 */
333 public boolean offer(E e) {
334 if (e == null)
335 throw new NullPointerException();
336 modCount++;
337 int i = size;
338 if (i >= queue.length)
339 grow(i + 1);
340 siftUp(i, e);
341 size = i + 1;
342 return true;
343 }
344
345 @SuppressWarnings("unchecked")
346 public E peek() {
347 return (size == 0) ? null : (E) queue[0];
348 }
349
350 private int indexOf(Object o) {
351 if (o != null) {
352 for (int i = 0; i < size; i++)
353 if (o.equals(queue[i]))
354 return i;
355 }
356 return -1;
357 }
358
359 /**
360 * Removes a single instance of the specified element from this queue,
361 * if it is present. More formally, removes an element {@code e} such
|