Class BinaryHeap
- java.lang.Object
 - 
- java.util.AbstractCollection
 - 
- org.apache.commons.collections.BinaryHeap
 
 
 
- 
- All Implemented Interfaces:
 java.lang.Iterable,java.util.Collection,Buffer,PriorityQueue
public final class BinaryHeap extends java.util.AbstractCollection implements PriorityQueue, Buffer
Deprecated.Replaced by PriorityBuffer in buffer subpackage. Due to be removed in v4.0.Binary heap implementation ofPriorityQueue.The
PriorityQueueinterface has now been replaced for most uses by theBufferinterface. This class and the interface are retained for backwards compatibility. The intended replacement isPriorityBuffer.The removal order of a binary heap is based on either the natural sort order of its elements or a specified
Comparator. Thepop()method always returns the first element as determined by the sort order. (TheisMinHeapflag in the constructors can be used to reverse the sort order, in which casepop()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
insert(Object)andpop()operations perform in logarithmic time. Thepeek()operation performs in constant time. All other operations perform in linear time or worse.Note that this implementation is not synchronized. Use SynchronizedPriorityQueue to provide synchronized access to a
BinaryHeap:PriorityQueue heap = new SynchronizedPriorityQueue(new BinaryHeap());
- Since:
 - Commons Collections 1.0
 
 
- 
- 
Constructor Summary
Constructors Constructor Description BinaryHeap()Deprecated.Constructs a new minimum binary heap.BinaryHeap(boolean isMinHeap)Deprecated.Constructs a new minimum or maximum binary heapBinaryHeap(boolean isMinHeap, java.util.Comparator comparator)Deprecated.Constructs a newBinaryHeap.BinaryHeap(int capacity)Deprecated.Constructs a new minimum binary heap with the specified initial capacity.BinaryHeap(int capacity, boolean isMinHeap)Deprecated.Constructs a new minimum or maximum binary heap with the specified initial capacity.BinaryHeap(int capacity, boolean isMinHeap, java.util.Comparator comparator)Deprecated.Constructs a newBinaryHeap.BinaryHeap(int capacity, java.util.Comparator comparator)Deprecated.Constructs a newBinaryHeap.BinaryHeap(java.util.Comparator comparator)Deprecated.Constructs a newBinaryHeapthat will use the given comparator to order its elements. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanadd(java.lang.Object object)Deprecated.Adds an object to this heap.voidclear()Deprecated.Clears all elements from queue.java.lang.Objectget()Deprecated.Returns the priority element.voidinsert(java.lang.Object element)Deprecated.Inserts an element into queue.booleanisEmpty()Deprecated.Tests if queue is empty.booleanisFull()Deprecated.Tests if queue is full.java.util.Iteratoriterator()Deprecated.Returns an iterator over this heap's elements.java.lang.Objectpeek()Deprecated.Returns the element on top of heap but don't remove it.java.lang.Objectpop()Deprecated.Returns the element on top of heap and remove it.java.lang.Objectremove()Deprecated.Removes the priority element.intsize()Deprecated.Returns the number of elements in this heap.java.lang.StringtoString()Deprecated.Returns a string representation of this heap.- 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray 
- 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait 
 - 
 
 - 
 
- 
- 
Constructor Detail
- 
BinaryHeap
public BinaryHeap()
Deprecated.Constructs a new minimum binary heap. 
- 
BinaryHeap
public BinaryHeap(java.util.Comparator comparator)
Deprecated.Constructs a newBinaryHeapthat will use the given comparator to order its elements.- Parameters:
 comparator- the comparator used to order the elements, null means use natural order
 
- 
BinaryHeap
public BinaryHeap(int capacity)
Deprecated.Constructs a new minimum binary heap with the specified initial capacity.- Parameters:
 capacity- The initial capacity for the heap. This value must be greater than zero.- Throws:
 java.lang.IllegalArgumentException- ifcapacityis <=0
 
- 
BinaryHeap
public BinaryHeap(int capacity, java.util.Comparator comparator)Deprecated.Constructs a newBinaryHeap.- Parameters:
 capacity- the initial capacity for the heapcomparator- the comparator used to order the elements, null means use natural order- Throws:
 java.lang.IllegalArgumentException- ifcapacityis <=0
 
- 
BinaryHeap
public BinaryHeap(boolean isMinHeap)
Deprecated.Constructs a new minimum or maximum binary heap- Parameters:
 isMinHeap- iftruethe heap is created as a minimum heap; otherwise, the heap is created as a maximum heap
 
- 
BinaryHeap
public BinaryHeap(boolean isMinHeap, java.util.Comparator comparator)Deprecated.Constructs a newBinaryHeap.- Parameters:
 isMinHeap- true to use the order imposed by the given comparator; false to reverse that ordercomparator- the comparator used to order the elements, null means use natural order
 
- 
BinaryHeap
public BinaryHeap(int capacity, boolean isMinHeap)Deprecated.Constructs a new minimum or maximum binary heap with the specified initial capacity.- Parameters:
 capacity- the initial capacity for the heap. This value must be greater than zero.isMinHeap- iftruethe heap is created as a minimum heap; otherwise, the heap is created as a maximum heap.- Throws:
 java.lang.IllegalArgumentException- ifcapacityis<= 0
 
- 
BinaryHeap
public BinaryHeap(int capacity, boolean isMinHeap, java.util.Comparator comparator)Deprecated.Constructs a newBinaryHeap.- Parameters:
 capacity- the initial capacity for the heapisMinHeap- true to use the order imposed by the given comparator; false to reverse that ordercomparator- the comparator used to order the elements, null means use natural order- Throws:
 java.lang.IllegalArgumentException- ifcapacityis<= 0
 
 - 
 
- 
Method Detail
- 
clear
public void clear()
Deprecated.Clears all elements from queue.- Specified by:
 clearin interfacejava.util.Collection- Specified by:
 clearin interfacePriorityQueue- Overrides:
 clearin classjava.util.AbstractCollection
 
- 
isEmpty
public boolean isEmpty()
Deprecated.Tests if queue is empty.- Specified by:
 isEmptyin interfacejava.util.Collection- Specified by:
 isEmptyin interfacePriorityQueue- Overrides:
 isEmptyin classjava.util.AbstractCollection- Returns:
 trueif queue is empty;falseotherwise.
 
- 
isFull
public boolean isFull()
Deprecated.Tests if queue is full.- Returns:
 trueif queue is full;falseotherwise.
 
- 
insert
public void insert(java.lang.Object element)
Deprecated.Inserts an element into queue.- Specified by:
 insertin interfacePriorityQueue- Parameters:
 element- the element to be inserted
 
- 
peek
public java.lang.Object peek() throws java.util.NoSuchElementExceptionDeprecated.Returns the element on top of heap but don't remove it.- Specified by:
 peekin interfacePriorityQueue- Returns:
 - the element at top of heap
 - Throws:
 java.util.NoSuchElementException- ifisEmpty() == true
 
- 
pop
public java.lang.Object pop() throws java.util.NoSuchElementExceptionDeprecated.Returns the element on top of heap and remove it.- Specified by:
 popin interfacePriorityQueue- Returns:
 - the element at top of heap
 - Throws:
 java.util.NoSuchElementException- ifisEmpty() == true
 
- 
toString
public java.lang.String toString()
Deprecated.Returns a string representation of this heap. The returned string is similar to those produced by standard JDK collections.- Overrides:
 toStringin classjava.util.AbstractCollection- Returns:
 - a string representation of this heap
 
 
- 
iterator
public java.util.Iterator iterator()
Deprecated.Returns an iterator over this heap's elements.- Specified by:
 iteratorin interfacejava.util.Collection- Specified by:
 iteratorin interfacejava.lang.Iterable- Specified by:
 iteratorin classjava.util.AbstractCollection- Returns:
 - an iterator over this heap's elements
 
 
- 
add
public boolean add(java.lang.Object object)
Deprecated.Adds an object to this heap. Same asinsert(Object).- Specified by:
 addin interfacejava.util.Collection- Overrides:
 addin classjava.util.AbstractCollection- Parameters:
 object- the object to add- Returns:
 - true, always
 
 
- 
get
public java.lang.Object get()
Deprecated.Returns the priority element. Same aspeek().- Specified by:
 getin interfaceBuffer- Returns:
 - the priority element
 - Throws:
 BufferUnderflowException- if this heap is empty
 
- 
remove
public java.lang.Object remove()
Deprecated.Removes the priority element. Same aspop().- Specified by:
 removein interfaceBuffer- Returns:
 - the removed priority element
 - Throws:
 BufferUnderflowException- if this heap is empty
 
- 
size
public int size()
Deprecated.Returns the number of elements in this heap.- Specified by:
 sizein interfacejava.util.Collection- Specified by:
 sizein classjava.util.AbstractCollection- Returns:
 - the number of elements in this heap
 
 
 - 
 
 -