-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConstraint.java
More file actions
64 lines (55 loc) · 1.63 KB
/
Constraint.java
File metadata and controls
64 lines (55 loc) · 1.63 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
import java.util.HashMap;
/** A CONSTRAINT that contains three WIZARDS A, B, and C. WIZARD C cannot be
* between WIZARDS A or B for this constraint to be satisfied.
*/
public class Constraint {
/** Where a, b, c represents WIZARDS. */
private String a, b, c;
/** Constraint Constructor */
public Constraint(String a, String b, String c) {
this.a = a;
this.b = b;
this.c = c;
}
/** Returns WIZARD A. */
public String getA() {
return a;
}
/** Returns WIZARD B. */
public String getB() {
return b;
}
/** Returns WIZARD C. */
public String getC() {
return c;
}
/** Method that swaps locations of WIZARDS X and Y in ORDER. */
public void swap(HashMap<String, Integer> order, String x, String y) {
int temp = order.get(x);
order.put(x, order.get(y));
order.put(y, temp);
}
@Override
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (!(o instanceof Constraint)) {
return false;
}
Constraint c = (Constraint) o;
return c.getC().equals(getC()) &&
((c.getA().equals(getA()) && c.getB().equals(getB())) ||
(c.getA().equals(getB()) && c.getB().equals(getA())));
}
/** Returns 1 if CONSTRAINT is satisfied and 0 otherwise. */
public int satisfy(HashMap<String, Integer> order) {
int aI = order.get(a);
int bI = order.get(b);
int cI = order.get(c);
if ((aI < cI && cI < bI) || (bI < cI && cI < aI)) {
return 0;
}
return 1;
}
}