2
Copyright (c) Xerox Corporation 1998-2002. All rights reserved.
4
Use and copying of this software and preparation of derivative works based
5
upon this software are permitted. Any distribution of this software or
6
derivative works must comply with all applicable United States export control
9
This software is made available AS IS, and Xerox Corporation makes no warranty
10
about the software, its performance or its conformity to any specification.
15
import java.util.Hashtable;
17
public aspect HashablePoint {
19
public int Point.hashCode() {
20
return (int) (getX() + getY() % Integer.MAX_VALUE);
23
public boolean Point.equals(Object o) {
24
if (o == this) { return true; }
25
if (!(o instanceof Point)) { return false; }
26
Point other = (Point)o;
27
return (getX() == other.getX()) && (getY() == other.getY());
30
public static void main(String[] args) {
31
Hashtable h = new Hashtable();
32
Point p1 = new Point();
34
p1.setRectangular(10, 10);
35
Point p2 = new Point();
37
p2.setRectangular(10, 10);
39
System.out.println("p1 = " + p1);
40
System.out.println("p2 = " + p2);
41
System.out.println("p1.hashCode() = " + p1.hashCode());
42
System.out.println("p2.hashCode() = " + p2.hashCode());
45
System.out.println("Got: " + h.get(p2));