code: public static <E> Counter<E> asCounter(FixedPrioritiesPriorityQueue<E> p) {
      FixedPrioritiesPriorityQueue<E> pq = p.clone();
      ClassicCounter<E> counter = new ClassicCounter<E>();
      while (pq.hasNext()) {
        double priority = pq.getPriority();
        E element = pq.next();
        counter.incrementCount(element, priority);
      }
      return counter;
    }
docs: Returns a counter whose keys are the elements in this priority queue, and
  whose counts are the priorities in this queue. In the event there are
  multiple instances of the same element in the queue, the counter's count
  will be the sum of the instances' priorities.