-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPoint.java
More file actions
81 lines (64 loc) · 1.93 KB
/
Point.java
File metadata and controls
81 lines (64 loc) · 1.93 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import java.math.BigInteger;
// Classe immutabile che rappresenta
// un punto in una curva ellittica generica
public class Point {
// Coordinate (X,Y)
private BigInteger x;
private BigInteger y;
// Tipo di punto (-1: Non valido, 0: Valido, +1 Punto all'infinito)
private Integer type;
// Definizioni statiche dei due punti invalidi e infinito
public final static Point INVALID = new Point(0,0,-1);
public final static Point INFINITY = new Point(0,0,1);
// Costruttori standard per la classe
public Point(BigInteger x, BigInteger y, Integer type) {
this.x = x;
this.y = y;
this.type = type;
}
public Point(Integer x, Integer y, Integer type) {
this(BigInteger.valueOf(x), BigInteger.valueOf(y), type);
}
// Metodi getter specifici degli attributi
public BigInteger getX() {
return x;
}
public BigInteger getY() {
return y;
}
public Integer getType() {
return type;
}
public Boolean isValid()
{
return this.type >= 0;
}
public Boolean isInfinity()
{
return this.type == 1;
}
@Override
public String toString() {
return "Point{" +
"x=" + x +
", y=" + y +
", type=" + type +
'}';
}
// Confronto di uguaglianza tra punti
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Point point = (Point) o;
// Punti di tipo diverso
if( this.getType() != point.getType() ) return false;
// Se entrambi i punti sono validi, confronto le coordinate
if( this.getType() == 0 )
{
if( this.getX().compareTo(point.getX()) != 0 ) return false;
if( this.getY().compareTo(point.getY()) != 0 ) return false;
}
return true;
}
}