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

import java.util.Comparator;

public class SpecialSearchQueryPriorityQueue 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) {

        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) {
        for (int i = this.size(); i > 0; i--) {
            if (searchQuery.getDestination() == element().getDestination()
                    && element().isBackward() == false
                    && searchQuery.getSource() == element().getSource()) {
                this.remove();
            }
        }

    }

}

@@ -980,39 +980,28 @@
 or (
-int i = this.size(); i %3E 0; i--
+SearchQuery q : this
 ) %7B%0A
@@ -1044,33 +1044,25 @@
 nation() == 
-element()
+q
 .getDestinat
@@ -1070,41 +1070,13 @@
 on()
-%0A                    && element()
+ && q
 .isB
@@ -1148,17 +1148,9 @@
  == 
-element()
+q
 .get
@@ -1185,24 +1185,25 @@
 this.remove(
+q
 );%0A         

change the code for(;;) -> for(SearchQuery q : this) and remove() -> remove(q) in SpecialSearchQueryPriorityQueue