package com.rscd.model; import java.util.HashMap; //supports ONLY positive numbers public final class Point { private static HashMap points = new HashMap(); private int x; private int y; public static Point location(int x, int y) { if (x < 0 || y < 0) { throw new IllegalArgumentException("Point may not contain non negative values x:" + x + " y:" + y); } int hashcode = x << 16 | y; Point p = points.get(hashcode); if (p == null) { p = new Point(x, y); points.put(hashcode, p); } return p; } private Point(int x, int y) { this.x = x; this.y = y; } public final int getY() { return y; } public final int getX() { return x; } public final boolean equals(Object o) { if (o instanceof Point) { return this.x == ((Point) o).x && this.y == ((Point) o).y; } return false; } public int hashCode() { return x << 16 | y; } }