set initial capacity to minimum if unknown capacity

This commit is contained in:
Athou
2013-07-24 17:33:36 +02:00
parent 1a720e6a29
commit d212e96664
2 changed files with 6 additions and 6 deletions

View File

@@ -12,11 +12,11 @@ public class FixedSizeSortedSet<E> extends PriorityQueue<E> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final Comparator<? super E> comparator; private final Comparator<? super E> comparator;
private final int maxSize; private final int capacity;
public FixedSizeSortedSet(int maxSize, Comparator<? super E> comparator) { public FixedSizeSortedSet(int capacity, Comparator<? super E> comparator) {
super(maxSize, comparator); super(Math.max(1, capacity), comparator);
this.maxSize = maxSize; this.capacity = capacity < 0 ? Integer.MAX_VALUE : capacity;
this.comparator = comparator; this.comparator = comparator;
} }
@@ -41,7 +41,7 @@ public class FixedSizeSortedSet<E> extends PriorityQueue<E> {
} }
public boolean isFull() { public boolean isFull() {
return size() == maxSize; return size() == capacity;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@@ -219,7 +219,7 @@ public class FeedEntryStatusDAO extends GenericDAO<FeedEntryStatus> {
Comparator<FeedEntryStatus> comparator = order == ReadingOrder.desc ? STATUS_COMPARATOR_DESC Comparator<FeedEntryStatus> comparator = order == ReadingOrder.desc ? STATUS_COMPARATOR_DESC
: STATUS_COMPARATOR_ASC; : STATUS_COMPARATOR_ASC;
FixedSizeSortedSet<FeedEntryStatus> set = new FixedSizeSortedSet<FeedEntryStatus>( FixedSizeSortedSet<FeedEntryStatus> set = new FixedSizeSortedSet<FeedEntryStatus>(
capacity < 0 ? Integer.MAX_VALUE : capacity, comparator); capacity, comparator);
for (FeedSubscription sub : subscriptions) { for (FeedSubscription sub : subscriptions) {
Date last = (order != null && set.isFull()) ? set.last() Date last = (order != null && set.isFull()) ? set.last()
.getEntryUpdated() : null; .getEntryUpdated() : null;