class BoundedPriorityList implements Collection {
  protected final List fulllist;
  protected ArrayList worklist;

  public BoundedPriorityList(List list) {
    this.fulllist = list;
    this.worklist = new ArrayList(list);
  }

  public boolean isEmpty() {
    return worklist.isEmpty();
  }

  public Object removeFirst() {
    return worklist.remove(0);
  }

  public boolean add(Object toadd) {
    if (contains(toadd)) {
      return false;
    }

    /* it is not added to the end, but keep it in the order */
    int index = fulllist.indexOf(toadd);

    for (ListIterator worklistIter = worklist.listIterator(); worklistIter.hasNext();) {
      Object tocomp = worklistIter.next();
      int tmpidx = fulllist.indexOf(tocomp);
      if (index < tmpidx) {
        worklistIter.add(toadd);
        return true;
      }
    }

    return false;
  }

  // rest is only necessary to implement the Collection interface

  /**
   * {@inheritDoc}
   */
  public boolean addAll(Collection c) {<FILL_FUNCTION_BODY>}

  /**
   * {@inheritDoc}
   */
  public boolean addAll(int index, Collection c) {
    throw new RuntimeException("Not supported. You should use addAll(Collection) to keep priorities.");
  }

  /**
   * {@inheritDoc}
   */
  public void clear() {
    worklist.clear();
  }

  /**
   * {@inheritDoc}
   */
  public boolean contains(Object o) {
    return worklist.contains(o);
  }

  /**
   * {@inheritDoc}
   */
  public boolean containsAll(Collection c) {
    return worklist.containsAll(c);
  }

  /**
   * {@inheritDoc}
   */
  public Iterator iterator() {
    return worklist.iterator();
  }

  /**
   * {@inheritDoc}
   */
  public boolean remove(Object o) {
    return worklist.remove(o);
  }

  /**
   * {@inheritDoc}
   */
  public boolean removeAll(Collection c) {
    return worklist.removeAll(c);
  }

  /**
   * {@inheritDoc}
   */
  public boolean retainAll(Collection c) {
    return worklist.retainAll(c);
  }

  /**
   * {@inheritDoc}
   */
  public int size() {
    return worklist.size();
  }

  /**
   * {@inheritDoc}
   */
  public Object[] toArray() {
    return worklist.toArray();
  }

  /**
   * {@inheritDoc}
   */
  public Object[] toArray(Object[] a) {
    return worklist.toArray(a);
  }

  /**
   * {@inheritDoc}
   */
  public String toString() {
    return worklist.toString();
  }

  /**
   * {@inheritDoc}
   */
  public boolean equals(Object obj) {
    return worklist.equals(obj);
  }

  /**
   * {@inheritDoc}
   */
  public int hashCode() {
    return worklist.hashCode();
  }
}

    boolean addedSomething = false;
    for (Iterator iter = c.iterator(); iter.hasNext();) {
      Object o = iter.next();
      addedSomething |= add(o);
    }
    return addedSomething;
  
<no_super_class>