private int compare ( Node node1 , Node node2 ) { // Check if a comparator was set. if ( entryComparator != null ) { // Use the comparator to compare. return entryComparator . compare ( node1 . element , node2 . element ) ; } // No comparator was set so use the natural ordering. else { // Cast one of the elements into a Comparable and compare it with the other. return ( ( Comparable ) node1 . element ) . compareTo ( node2 . element ) ; } }
Compares two heap nodes . The comparison performed is dependant on whether a comparator has been set or the natural ordering is to be used .