This interface declares the methods needed for a "generic" container of type PriorityQueue. This container is "generic" in the sense that it can hold objects of any type. This is done by declaring the type of the items placed into the queue as Object (see the methods insert()
and removeMin()
). However, even though you could place both a String object and a Double object in this container at the same time, that is not what we want to do. Instead, it is assumed that all of the items in the container have the same type. So you could fill the container with String objects (and then, in a sense, it becomes a "container of Strings") or you could fill the container with Double objects (and then it is, in a sense, a "container of Doubles"). Notice that you cannot fill the container with ints or doubles, since int and double are not object types, they are primitive types (so you need to use "wrapper" classes, like Integer or Double).
This PriorityQueue will order the objects contained in it according to a Comparer object that is associated with the type of the objects in this container. This fact is not discernible by just looking at this interface. This interface never mentions the Comparer, since the use of the comparer will be contained in the implementation of the insert()
and removeMin()
methods. The need for a Comparer object should be made clear in the definition of any class that implements this interface.
Notice that, even though this priority queue refers to removeMin()
, that does not mean that this interface only defines priority queues that compute "minimums". Since the order of items is defined by a generic Comparer, and that Comparer can define any kind of order on the items that it wants, an implementation of this interface can actually compute "maximums".
Method Summary | |
java.lang.Object |
getMin()
Returns a reference to the minimum item in the queue. |
void |
insert(java.lang.Object item)
Inserts the parameter object into the container. |
boolean |
isEmpty()
Determines if the container is empty. |
java.lang.Object |
removeMin()
Returns a reference to the minimum item in the queue and then removes that item from the queue. |
int |
size()
Returns the number of items currently in the container. |
Method Detail |
public java.lang.Object getMin()
Notice that, since the reference returned is of type Object, you cannot do much with the returned reference unless you cast it to the type of the objects that are in the container.
public void insert(java.lang.Object item)
public boolean isEmpty()
public java.lang.Object removeMin()
public int size()