-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSensibilityLattice.java
62 lines (51 loc) · 1.8 KB
/
SensibilityLattice.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
package analysis.abstraction;
import heros.solver.Pair;
public enum SensibilityLattice {
BOTTOM(0, 0), NOT_SENSIBLE(1, 0), HIGH(1, 1), MAYBE_SENSIBLE(3, 0);
private final ComparablePair priority;
SensibilityLattice(Integer priority, Integer innerPriority) {
this.priority = new ComparablePair(priority, innerPriority);
}
public static boolean isSensible(SensibilityLattice v) {
return v.equals(HIGH) || v.equals(MAYBE_SENSIBLE);
}
public static SensibilityLattice supremeBetween(SensibilityLattice v1, SensibilityLattice v2) {
if (v1.equals(v2)) {
return v1;
} else if (v1.priority.getO1().equals(v2.priority.getO1())) {
return MAYBE_SENSIBLE;
} else {
return v1.compareTo(v2) == 1 ? v1 : v2;
}
}
public static SensibilityLattice getBottom() {
return BOTTOM;
}
public static SensibilityLattice getTop() {
return MAYBE_SENSIBLE;
}
private class ComparablePair extends Pair<Integer, Integer> implements Comparable {
/**
* Creates a new pair
*
* @param key The key for this pair
* @param value The value to use for this pair
*/
public ComparablePair(Integer key, Integer value) {
super(key, value);
}
@Override
public int compareTo(Object o) {
ComparablePair otherAsPair = (ComparablePair) o;
if (this.getO1().equals(otherAsPair.getO1()) &&
this.getO2().equals(otherAsPair.getO2())) {
return 0;
} else if (this.getO1() < otherAsPair.getO1() ||
this.getO2() < otherAsPair.getO2()) {
return -1;
} else {
return 1;
}
}
}
}