/**
   This version of the Triple class
   implements the Comparable<T> interface.

   A generic sorting algorithm can use
   Triple's compareTo() method to sort
   a list of Triple objects.
*/
public class Triple implements Comparable<Triple>
{
   public int x, y, z;

   public Triple(int x, int y, int z)
   {
      this.x = x;
      this.y = y;
      this.z = z;
   }


   @Override public String toString()
   {
      return "<" + x + ", " + y + ", " + z + ">";
   }


   /**
      If you change the definition of this compareTo() method,
      then you change the way a generic soring method will sort
      lists of Triple objects.
   */
   @Override public int compareTo(Triple that)
   {
      if (this.x != that.x)
      {
         return this.x - that.x;
      }
      else if (this.y != that.y)
      {
         return this.y - that.y;
      }
      else
      {
         return this.z - that.z;
      }
   }
}
