-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.java
More file actions
41 lines (38 loc) · 1.25 KB
/
Point.java
File metadata and controls
41 lines (38 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.LinkedList;
public class Point {
public int x, y;
//public Point up, left, right, down;
public Point (int x, int y) {
this.x=x;
this.y=y;
//up=null;
//left=null;
//right=null;
//down=null;
}
public LinkedList<Point> neighbors() {
LinkedList<Point> list=new LinkedList<Point>();
list.add(new Point(x-1,y));
list.add(new Point(x+1,y));
list.add(new Point(x,y-1));
list.add(new Point(x,y+1));
list.add(new Point(x+1,y+1));
list.add(new Point(x+1,y-1));
list.add(new Point(x-1,y+1));
list.add(new Point(x-1,y-1));
return list;
}
@Override
public boolean equals (Object o) {
if (o instanceof Point) {
Point p=(Point)o;
return (p.x==x && p.y==y);
}
return false;
}
@Override
public int hashCode() {
//100* to reduce hash collisions - can be any number theoretically
return x+100*y;
}
}