Fixed size priority queue I've tried implementing priority queue with fixed size in Java using TreeSet and overriding add() method:

public class FixedSizePriorityQueue&lt;E&gt; extends TreeSet&lt;E&gt; {
    private final int capacity;

    public FixedSizePriorityQueue(final int capacity) {
        this.capacity = capacity;
    }

    public FixedSizePriorityQueue(
            final int capacity,
            final Comparator&lt;? super E&gt; comparator) {

        super(comparator);
        this.capacity = capacity;
    }

    @Override
    public boolean add(final E e) {
        // initialized with 0 or less than zero capacity
        if (capacity &lt;= 0) {
            return false;
        }

        // keep adding until we fill the queue
        if (size() &lt; capacity) {
            return super.add(e);
        }

        if (comparator() != null
                &amp;&amp; comparator().compare(this.last(), e) &lt; 0) {
            pollLast();
            return super.add(e);
        }

        return false;
    }
}


I would really appreciate your thoughts, hints and comments.
Two thoughts:


If there is other code and you need all the features of a TreeSet great, otherwise delegate to a TreeSet member variable.
Your code if (capacity &lt;= 0) is somewhat superfluous because of the next test if (size() &lt; capacity)