Class DefaultComparator<E>

java.lang.Object
com.zybooks.dsaj.util.DefaultComparator<E>
Type Parameters:
E - an element type
All Implemented Interfaces:
Comparator<E>

public class DefaultComparator<E> extends Object implements Comparator<E>
Comparator based on the compareTo method of a Comparable element type.
  • Constructor Details

    • DefaultComparator

      public DefaultComparator()
  • Method Details

    • compare

      public int compare(E a, E b) throws ClassCastException
      Compares two elements.
      Specified by:
      compare in interface Comparator<E>
      Parameters:
      a - the first of two elements to compare
      b - the second of two elements to compare
      Returns:
      a negative integer if a is less than b, zero if a equals b, or a positive integer if a is greater than b
      Throws:
      ClassCastException