You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ComparablePoint.java 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. Copyright (c) Xerox Corporation 1998-2002. All rights reserved.
  3. Use and copying of this software and preparation of derivative works based
  4. upon this software are permitted. Any distribution of this software or
  5. derivative works must comply with all applicable United States export control
  6. laws.
  7. This software is made available AS IS, and Xerox Corporation makes no warranty
  8. about the software, its performance or its conformity to any specification.
  9. */
  10. package introduction;
  11. public aspect ComparablePoint {
  12. declare parents: Point implements Comparable;
  13. public int Point.compareTo(Object o) {
  14. return (int) (this.getRho() - ((Point)o).getRho());
  15. }
  16. public static void main(String[] args){
  17. Point p1 = new Point();
  18. Point p2 = new Point();
  19. System.out.println("p1 =?= p2 :" + p1.compareTo(p2));
  20. p1.setRectangular(2,5);
  21. p2.setRectangular(2,5);
  22. System.out.println("p1 =?= p2 :" + p1.compareTo(p2));
  23. p2.setRectangular(3,6);
  24. System.out.println("p1 =?= p2 :" + p1.compareTo(p2));
  25. p1.setPolar(Math.PI, 4);
  26. p2.setPolar(Math.PI, 4);
  27. System.out.println("p1 =?= p2 :" + p1.compareTo(p2));
  28. p1.rotate(Math.PI / 4.0);
  29. System.out.println("p1 =?= p2 :" + p1.compareTo(p2));
  30. p1.offset(1,1);
  31. System.out.println("p1 =?= p2 :" + p1.compareTo(p2));
  32. }
  33. }