
package kr.ac.kaist.ds.groupd.search;

import java.util.Comparator;
import java.util.PriorityQueue;

public class SearchQueryPriorityQueue<E> extends PriorityQueue<E> {
    private static final long serialVersionUID = 1L;

    private final int fixedSizeOfQueue;

    public SearchQueryPriorityQueue(int initialCapacity, Comparator<? super E> comparator) {
        super(initialCapacity, comparator);
        this.fixedSizeOfQueue = initialCapacity;
    }

    @SuppressWarnings("unchecked")
    public E getTail() {
        Object[] queue = this.toArray();
        E tail = (E)queue[0];
        Comparator<? super E> comparator = this.comparator();
        if (comparator != null)
            for (int i = 1; i < this.size(); i++) {
                if (comparator.compare(tail, (E)queue[i]) < 0)
                    tail = (E)queue[i];
            }
        else
            for (int j = 1; j < this.size(); j++)
                if (((Comparable)tail).compareTo(((Comparable)queue[j])) < 0)
                    tail = (E)queue[j];
        return tail;

    }

    public E removeTail() {
        E tail = this.getTail();

        if (this.remove(tail))
            return tail;
        return null;
    }

    @Override
    public boolean add(E e) {
        if (this.size() >= fixedSizeOfQueue) {
            if (null != this.removeTail())
                return super.add(e);
            return false;
        }
        return super.add(e);
    }

}

@@ -455,758 +455,8 @@
  %7D%0A%0A
-    @SuppressWarnings(%22unchecked%22)%0A    public E getTail() %7B%0A        Object%5B%5D queue = this.toArray();%0A        E tail = (E)queue%5B0%5D;%0A        Comparator%3C? super E%3E comparator = this.comparator();%0A        if (comparator != null)%0A            for (int i = 1; i %3C this.size(); i++) %7B%0A                if (comparator.compare(tail, (E)queue%5Bi%5D) %3C 0)%0A                    tail = (E)queue%5Bi%5D;%0A            %7D%0A        else%0A            for (int j = 1; j %3C this.size(); j++)%0A                if (((Comparable)tail).compareTo(((Comparable)queue%5Bj%5D)) %3C 0)%0A                    tail = (E)queue%5Bj%5D;%0A        return tail;%0A%0A    %7D%0A%0A    public E removeTail() %7B%0A        E tail = this.getTail();%0A%0A        if (this.remove(tail))%0A            return tail;%0A        return null;%0A    %7D%0A%0A
     
@@ -465,16 +465,16 @@
 verride%0A
+
     publ
@@ -570,23 +570,14 @@
  != 
-this.
 remove
-Tail
 ())%0A
@@ -678,17 +678,16 @@
 add(e);%0A
+
     %7D%0A
-%0A
 %7D%0A

modify about the deletetail and gettail