salvo.jesus.util
Class HeapNodeComparator
java.lang.Object
salvo.jesus.util.HeapNodeComparator
- All Implemented Interfaces:
- java.io.Serializable, java.util.Comparator
public class HeapNodeComparator
- extends java.lang.Object
- implements java.util.Comparator, java.io.Serializable
A Comparator to compare HeapNodes based on their priority.
Two HeapNodes are the same if they have the same priority,
regardless of the object encaspulated by the HeapNodes.
- Author:
- Jesus M. Salvo Jr.
- See Also:
- Serialized Form
Field Summary |
(package private) int |
order
Control how compare() return its value. |
Constructor Summary |
HeapNodeComparator(int order)
Creates an instance of HeapNodeComparator |
Method Summary |
int |
compare(java.lang.Object o1,
java.lang.Object o2)
Compares two HeapNode objects. |
boolean |
equals(java.lang.Object obj)
|
Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
order
int order
- Control how compare() return its value. If order is < 0,
then compare() will return -1 if the priority of the first heap node
argument is numerically less than the priority of the second heap node argument.
If order >= 0, then compare() will return -1 if the priority of the first heap node
argument is numerically greater than priority of the second heap node argument.
HeapNodeComparator
public HeapNodeComparator(int order)
- Creates an instance of HeapNodeComparator
compare
public int compare(java.lang.Object o1,
java.lang.Object o2)
- Compares two HeapNode objects.
- Specified by:
compare
in interface java.util.Comparator
- Parameters:
o1
- Must be an instance of HeapNodeo2
- Must be an instance of HeapNode
equals
public boolean equals(java.lang.Object obj)
- Specified by:
equals
in interface java.util.Comparator
- Overrides:
equals
in class java.lang.Object