AbstractCollection | +--org.apache.commons.collections.buffer.PriorityBufferAll Implemented Interfaces:
boolean | If true, the first element as determined by the sort order will be returned. |
Comparator | The comparator used to order the elements |
Object[] | The elements in this buffer. |
int | The number of elements currently in this buffer. |
Constructs a new empty buffer that sorts in ascending order by the natural order of the objects added. |
PriorityBuffer(Comparator comparator) Constructs a new empty buffer that sorts in ascending order using the specified comparator. |
PriorityBuffer(boolean ascendingOrder) Constructs a new empty buffer specifying the sort order and using the natural order of the objects added. |
PriorityBuffer(boolean ascendingOrder, Comparator comparator) Constructs a new empty buffer specifying the sort order and comparator. |
PriorityBuffer(int capacity) Constructs a new empty buffer that sorts in ascending order by the natural order of the objects added, specifying an initial capacity. |
PriorityBuffer(int capacity, Comparator comparator) Constructs a new empty buffer that sorts in ascending order using the specified comparator and initial capacity. |
PriorityBuffer(int capacity, boolean ascendingOrder) Constructs a new empty buffer that specifying initial capacity and sort order, using the natural order of the objects added. |
PriorityBuffer(int capacity, boolean ascendingOrder, Comparator comparator) Constructs a new empty buffer that specifying initial capacity, sort order and comparator. |
boolean | add(Object element) Adds an element to the buffer. |
void | clear() Clears all elements from the buffer. |
Comparator | Gets the comparator being used for this buffer, null is natural order. |
int | compare(Object a, Object b) Compares two objects using the comparator if specified, or the natural order otherwise. |
Object | get() Gets the next element to be removed without actually removing it (peek). |
void | grow() Increases the size of the heap to support additional elements |
boolean | Checks whether the heap is ascending or descending order. |
boolean | Tests if the buffer is at capacity. |
Iterator | iterator() Returns an iterator over this heap's elements. |
void | percolateDownMaxHeap(final int index) Percolates element down heap from the position given by the index. |
void | percolateDownMinHeap(final int index) Percolates element down heap from the position given by the index. |
void | percolateUpMaxHeap(final int index) Percolates element up heap from from the position given by the index. |
void | percolateUpMaxHeap(final Object element) Percolates a new element up heap from the bottom. |
void | percolateUpMinHeap(final int index) Percolates element up heap from the position given by the index. |
void | percolateUpMinHeap(final Object element) Percolates a new element up heap from the bottom. |
Object | remove() Gets and removes the next element (pop). |
int | size() Returns the number of elements in this buffer. |
String | toString() Returns a string representation of this heap. |
protected boolean ascendingOrder
protected Comparator comparator
protected Object[] elements
protected int size
public PriorityBuffer()
public PriorityBuffer(boolean ascendingOrder, Comparator comparator)
public PriorityBuffer(boolean ascendingOrder)
public PriorityBuffer(Comparator comparator)
public PriorityBuffer(int capacity, boolean ascendingOrder, Comparator comparator)
- if capacity is <= 0public PriorityBuffer(int capacity, boolean ascendingOrder)
- if capacity is <= 0public PriorityBuffer(int capacity, Comparator comparator)
- if capacity is <= 0public PriorityBuffer(int capacity)
- if capacity is <= 0public boolean add(Object element)
public void clear()
public Comparator comparator()
protected int compare(Object a, Object b)
public Object get()
BufferUnderflowException
- if the buffer is emptyprotected void grow()
public boolean isAscendingOrder()
protected boolean isAtCapacity()
public Iterator iterator()
protected void percolateDownMaxHeap(final int index)
protected void percolateDownMinHeap(final int index)
protected void percolateUpMaxHeap(final int index)
protected void percolateUpMaxHeap(final Object element)
protected void percolateUpMinHeap(final int index)
protected void percolateUpMinHeap(final Object element)
public Object remove()
BufferUnderflowException
- if the buffer is emptypublic int size()
public String toString()
Buffer
that provides for removal based onComparator
ordering. The removal order of a binary heap is based on either the natural sort order of its elements or a specified Comparator. The remove() method always returns the first element as determined by the sort order. (TheascendingOrder
flag in the constructors can be used to reverse the sort order, in which case remove() will always remove the last element.) The removal order is not the same as the order of iteration; elements are returned by the iterator in no particular order. The add(Object) and remove() operations perform in logarithmic time. The get() operation performs in constant time. All other operations perform in linear time or worse. Note that this implementation is not synchronized. Use org.apache.commons.collections.BufferUtils.synchronizedBuffer(Buffer) or org.apache.commons.collections.buffer.SynchronizedBuffer.decorate(Buffer) to provide synchronized access to aPriorityBuffer
: