T
- type of items to hold in the collectionpublic class SortedHead<T>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private int |
candidateCount |
private T[] |
candidates |
private java.util.Comparator<? super T> |
comparator |
private T[] |
head |
private T |
limit |
private SimpleArray<T> |
tail |
Modifier | Constructor and Description |
---|---|
|
SortedHead(T[] head,
java.util.Comparator<? super T> comparator)
Create a new collection with an initial head.
|
private |
SortedHead(T[] head,
SimpleArray<T> tail,
java.util.Comparator<? super T> comparator) |
Modifier and Type | Method and Description |
---|---|
void |
addObject(T o)
Add an item to the collection.
|
static <T> void |
addSorted(java.util.Iterator<? extends T> sourceIterator,
T[] fullHead,
SimpleArray<T> tail,
java.util.Comparator<? super T> comparator)
Convenience method for sorting items into a head of fixed size and a growable tail.
|
T[] |
getTail()
Get the tail items.
|
private void |
updateHead() |
private final T[] head
private final T[] candidates
private int candidateCount
private T limit
private final java.util.Comparator<? super T> comparator
private final SimpleArray<T> tail
private SortedHead(T[] head, SimpleArray<T> tail, java.util.Comparator<? super T> comparator)
public SortedHead(T[] head, java.util.Comparator<? super T> comparator)
head
- Head items. The array must contain at least one item but does not need to be
sorted. This array will be sorted every time the collection is added to with
addObject(Object)
.comparator
- comparator to use when sortingpublic T[] getTail()
public void addObject(T o)
o
- item to addprivate void updateHead()
public static <T> void addSorted(java.util.Iterator<? extends T> sourceIterator, T[] fullHead, SimpleArray<T> tail, java.util.Comparator<? super T> comparator)
sourceIterator
- iterator that gives items to sortfullHead
- An array with current head items. The array may be modified by this method.tail
- A growable tail. It may contain items at the start of the method call and items
that do not fit in the head are placed here.comparator
- comparator to use when sorting