/** Implementation of a priority queue by means of a sorted list */
public class SortedListAdaptablePriorityQueue
  extends SortedListPriorityQueue implements AdaptablePriorityQueue {
  /** Creates the priority queue with the default comparator. */
  public SortedListAdaptablePriorityQueue() { 
    super();
  }
  /** Creates the priority queue with the given comparator. */
  public SortedListAdaptablePriorityQueue(Comparator comp) { 
    super(comp);
  }
  /** Inserts a key-value pair and returns the entry created. */
  public Entry insert (Object k, Object v) throws InvalidKeyException {
    checkKey(k);
    LocationAwareEntry entry = new LocationAwareEntry(k,v);
    insertEntry(entry);
    entry.setLocation(actionPos);
    return entry;
  }
  /** Removes and returns the given entry. */
  public Entry remove(Entry entry) {
    checkEntry(entry);
    LocationAwareEntry e = (LocationAwareEntry) entry;
    Position p = e.location();
    L.remove(p);
    e.setLocation(null);
    return e;
  }
  /** Replaces the key of the given entry. */
  public Object replaceKey(Entry entry, Object k) {
    checkKey(k);
    checkEntry(entry);
    LocationAwareEntry e = (LocationAwareEntry) remove(entry);
    Object oldKey = e.setKey(k);
    insertEntry(e);
    e.setLocation(actionPos);
    return oldKey;
  }