01
package org.shirdrn.dm.clustering.common;
02
03
public class Point2D {
04
05
protected final Double x;
06
protected final Double y;
07
08
public Point2D(Double x, Double y) {
09
super();
10
this.x = x;
11
this.y = y;
12
}
13
14
@Override
15
public int hashCode() {
16
return 31 * x.hashCode() + 31 * y.hashCode();
17
}
18
19
@Override
20
public boolean equals(Object obj) {
21
Point2D other = (Point2D) obj;
22
return this.x.doubleValue() == other.x.doubleValue() && this.y.doubleValue() == other.y.doubleValue();
23
}
24
25
public Double getX() {
26
return x;
27
}
28
29
public Double getY() {
30
return y;
31
}
32
33
@Override
34
public String toString() {
35
return "(" + x + ", " + y + ")";
36
}
37
38
}
我们可以将解析后的点的对象放到一个List<Point2D> allPoints集合里面,以便后续使用时迭代集合。在计算两点之间的欧几
里德距离时,需要迭代前面生成的Point2D的集合,计算欧几里德距离,实现方法如下所示: