import java.util.SortedSet;
import java.util.TreeSet;

/**
 *
 * @author ShawTim
 */
public class Main
{
  public static void main (String[] args)
  {
    Obj obj1 = new Obj(0, 1);
    Obj obj2 = new Obj(1, 2);
    Obj obj3 = new Obj(2, 3);
    SortedSet<Obj> set = new TreeSet();
    set.add(obj1);
    set.add(obj2);
    set.add(obj3);
    
    System.out.println(set);
    
    obj1.setA(10);
    
    System.out.println(set);
    
    System.out.println(obj1.compareTo(obj2));
    System.out.println(obj1.compareTo(obj3));
    
    Obj obj4 = new Obj(10, 1);
    set.add(obj4);
    System.out.println(set);
    System.out.println(obj1.equals(obj4));
  }
  
  private static class Obj implements Comparable
  {
    private int a;
    private int b;
    
    public Obj(int a, int b)
    {
      this.setA(a);
      this.setB(b);
    }

    public int getA()
    {
      return a;
    }

    public void setA(int a)
    {
      this.a = a;
    }

    public int getB()
    {
      return b;
    }

    public void setB(int b)
    {
      this.b = b;
    }

    public int compareTo(Object o)
    {
      Obj obj = (Obj) o;
      return this.getA() + this.getB() - obj.getA() - obj.getB();
    }
    
    public String toString()
    {
      return this.getA() + "-" + this.getB();
    }
    
    public boolean equals(Object o)
    {
      return this.compareTo(o) == 0;
    }
  }
}

