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

import java.util.Comparator;
import java.util.PriorityQueue;
import kr.ac.kaist.ds.groupd.search.SearchQuery;

public class SpecialSearchQueryPriorityQueue<E> extends SearchQueryPriorityQueue<SearchQuery> {

    private static final long serialVersionUID = 1L;

    private final int fixedSizeOfQueue;

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

    @Override
    public boolean offer(SearchQuery searchQuery) {

        for (int i = 0; i < this.size(); i++)
            deleteUnnecessarySearchQuery(searchQuery);

        if (this.size() >= fixedSizeOfQueue) {
            SearchQuery element = remove();
            if (this.comparator().compare(element, searchQuery) == -1)
                return super.offer(searchQuery);

            return false;
        }

        return super.offer(searchQuery);
    }

    private void deleteUnnecessarySearchQuery(SearchQuery searchQuery) {
        if (searchQuery.getDestination() == element().getDestination()
                && element().isBackward() == false
                && searchQuery.getSource() == element().getSource()) {

            this.remove();
        }

    }

}

@@ -629,58 +629,8 @@
  %7B%0A%0A
-        for (int i = 0; i %3C this.size(); i++)%0A    
     
@@ -1043,24 +1043,76 @@
 rchQuery) %7B%0A
+        for (int i = this.size(); i %3E 0; i--) %7B%0A    
         if (
@@ -1186,16 +1186,20 @@
         
+    
 && eleme
@@ -1241,16 +1241,20 @@
         
+   
+ 
 && searc
@@ -1309,24 +1309,28 @@
             
+    
 this.remove(
@@ -1324,32 +1324,46 @@
  this.remove();%0A
+            %7D%0A
         %7D%0A%0A    %7D

change the check loop in the deleteUnnecessarySearchQuery