-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExtendedInteger.java
70 lines (60 loc) · 1.34 KB
/
ExtendedInteger.java
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
package siteswapsuite;
public class ExtendedInteger {
private Integer finiteValue;
private InfinityType infiniteValue;
private boolean isInfinite;
public ExtendedInteger(InfinityType value) {
this.infiniteValue = value;
this.finiteValue = null;
this.isInfinite = true;
}
public ExtendedInteger(int value) {
this.finiteValue = value;
this.infiniteValue = null;
this.isInfinite = false;
}
public boolean isInfinite() {
return this.isInfinite;
}
public Integer finiteValue() {
return this.finiteValue;
}
public InfinityType infiniteValue() {
return this.infiniteValue;
}
public int sign() {
if(this.isInfinite) {
if(this.infiniteValue == InfinityType.POSITIVE_INFINITY)
return 1;
else
return -1;
} else {
if(this.finiteValue > 0)
return 1;
else if(this.finiteValue < 0)
return -1;
else
return 0;
}
}
public void negate() {
if(this.isInfinite) {
if(this.infiniteValue == InfinityType.POSITIVE_INFINITY)
this.infiniteValue = InfinityType.NEGATIVE_INFINITY;
else
this.infiniteValue = InfinityType.POSITIVE_INFINITY;
} else {
this.finiteValue *= -1;
}
}
public String toString() {
if(this.isInfinite) {
if(this.infiniteValue == InfinityType.POSITIVE_INFINITY)
return "&";
else
return "-&";
} else {
return this.finiteValue.toString();
}
}
}