cornell.cs211
Class AbstractHeap<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by cornell.cs211.AbstractHeap<E>
Type Parameters:
E - The type of the elements held in this collection.
All Implemented Interfaces:
Heap<E>, java.lang.Iterable<E>, java.util.Collection<E>
Direct Known Subclasses:
SortedHeap, StdHeap, UnsortedHeap

public abstract class AbstractHeap<E>
extends java.util.AbstractCollection<E>
implements Heap<E>

This class provides skeletal implementations of some Heap operations. It is integrated with Java Collection framework

A Heap implementation that extends this class must miniumally define methods push, pop and top

Author:
Changxi Zheng
See Also:
Heap

Field Summary
protected  java.util.Comparator<? super E> comparator
          The comparator, or null if priority queue uses elements' natural ordering.
 
Constructor Summary
protected AbstractHeap(java.util.Comparator<? super E> comparator)
          Construct with the given comparator which is used to decide the order of elements in the heap
 
Method Summary
 boolean add(E o)
          Adds the specified element to this heap.
 boolean addAll(java.util.Collection<? extends E> c)
          Adds all of the elements in the specified collection to this queue.
 void clear()
          Remove all the elements from the heap.
 
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface cornell.cs211.Heap
pop, push, top
 
Methods inherited from interface java.util.Collection
contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Field Detail

comparator

protected final java.util.Comparator<? super E> comparator
The comparator, or null if priority queue uses elements' natural ordering.

Constructor Detail

AbstractHeap

protected AbstractHeap(java.util.Comparator<? super E> comparator)
Construct with the given comparator which is used to decide the order of elements in the heap

Method Detail

add

public boolean add(E o)
Adds the specified element to this heap.

Specified by:
add in interface java.util.Collection<E>
Overrides:
add in class java.util.AbstractCollection<E>
Returns:
true if add successfully, false otherwise.

clear

public void clear()
Remove all the elements from the heap.

Specified by:
clear in interface java.util.Collection<E>
Overrides:
clear in class java.util.AbstractCollection<E>

addAll

public boolean addAll(java.util.Collection<? extends E> c)
Adds all of the elements in the specified collection to this queue. The current implementation is just to add the elements in the given Collection instance one by one.

Specified by:
addAll in interface java.util.Collection<E>
Overrides:
addAll in class java.util.AbstractCollection<E>
Parameters:
c - collection whose elements are to be added into this heap.
Returns:
true if this collection changed as a result of this call.
Throws:
java.lang.NullPointerException - if the specified collection is null.
java.lang.IllegalArgumentException - if the specified collection is this heap.