private void updateMinimum ( Node node ) { // Check if a comparator was set. if ( entryComparator != null ) { // Use the comparator to compare the candidate new minimum with the current one and check if the new one // should be set. if ( entryComparator . compare ( node . element , minNode . element ) < 0 ) { // Update the minimum node. minNode = node ; } } // No comparator was set so use the natural ordering. else { // Cast the candidate new minimum element into a Comparable and compare it with the existing minimum // to check if the new one should be set. if ( ( ( Comparable ) node . element ) . compareTo ( minNode . element ) < 0 ) { // Update the minimum node. minNode = node ; } } }
Compares the specified node with the minimum and updates the minimum if neccessary . If a comparator was used to create this heap then this comparator is used to perform the comparison . If no comparator was set then the natural ordering of the element type is used . The element must implement the Comparable interface to support a natural ordering . If it does not there will be a class cast exception thrown .