/**
 * Wrapper class to allow capture of the number of calls to compareTo.
 * @author   Timothy Rolfe
 * @see      "No Borrowed Code"
 */
public class MyComparable <E extends  Comparable<E>>
                           implements Comparable<E>
{
   private static long count = 0;

   private E  value;

   public MyComparable ( E item )
   {  value = item;  }

/**
 * Provide access to the value with proper type.
 *
 * @return     the result of item.toString()
 * @exception  none  no exception thrown
 * @see        "No borrowed code"
 */
   public E getValue()
   {  return value;  }

/**
 * Provide access to the appropriate toString method.
 *
 * @return     the result of item.toString()
 * @exception  none  no exception thrown
 * @see        "No borrowed code"
 */
   public String toString()
   {  return value.toString();  }

/**
 * Count up the number of calls, then return the result of the compareTo.
 *
 * @param     o  Generic object as the right operand in the comparison
 * @return    an integer with the result of the comparison
 * @exception none  no exception thrown
 * @see       "No borrowed code"
 */
   public int compareTo(E o)
   {  MyComparable<E> rt = (MyComparable<E>)o;

      count++;
      return value.compareTo(rt.value);
   }

/**
 * Return the result of the compareTo WITHOUT counting it in.  This can
 * be used if there are utility routines that need to make comparisons
 * but their comparisons should not be included in the statistics.
 *
 * @param     o  Generic object as the right operand in the comparison
 * @return    an integer with the result of the comparison
 * @exception none  no exception thrown
 * @see       "No borrowed code"
 */
   public int freeCompare(E o)
   {
      MyComparable<E> rt = (MyComparable<E>)o;

      return value.compareTo(rt.value);
   }

/**
 * Zero out the counter, and return the number of compareTo calls.
 *
 * @return     long giving the number of compareTo calls
 * @exception  none  no exception thrown
 * @see        "No borrowed code"
 */
   static public long nCompares()
   {
      long hold = count;

      count = 0;
      return hold;
   }
}