diff --git a/src/main/java/com/commafeed/backend/FixedSizeSortedSet.java b/src/main/java/com/commafeed/backend/FixedSizeSortedSet.java index f0a597ee..a23362dc 100644 --- a/src/main/java/com/commafeed/backend/FixedSizeSortedSet.java +++ b/src/main/java/com/commafeed/backend/FixedSizeSortedSet.java @@ -1,15 +1,13 @@ package com.commafeed.backend; -import java.util.Collection; import java.util.Comparator; import java.util.List; -import java.util.TreeSet; - -import org.apache.commons.collections.CollectionUtils; +import java.util.PriorityQueue; +import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -public class FixedSizeSortedSet extends TreeSet { +public class FixedSizeSortedSet extends PriorityQueue { private static final long serialVersionUID = 1L; @@ -17,7 +15,7 @@ public class FixedSizeSortedSet extends TreeSet { private final int maxSize; public FixedSizeSortedSet(int maxSize, Comparator comparator) { - super(comparator); + super(maxSize, comparator); this.maxSize = maxSize; this.comparator = comparator; } @@ -38,19 +36,10 @@ public class FixedSizeSortedSet extends TreeSet { } } - @Override - public boolean addAll(Collection c) { - if (CollectionUtils.isEmpty(c)) { - return false; - } - - boolean success = true; - for (E e : c) { - success &= add(e); - } - return success; + public E last() { + return Iterables.getLast(this); } - + public boolean isFull() { return size() == maxSize; }