-
Notifications
You must be signed in to change notification settings - Fork 0
/
InstructionImpl.pde
64 lines (54 loc) · 1.14 KB
/
InstructionImpl.pde
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
class InstructionImpl implements Instruction {
private int lo, hi;
private boolean swap;
private int[] controlPoints;
InstructionImpl(int lo, int hi, boolean swap, int[] controlPoints) {
this.lo = lo;
this.hi = hi;
this.swap = swap;
this.controlPoints = controlPoints;
}
public int lo() {
return this.lo;
}
public int hi() {
return this.hi;
}
public boolean swap() {
return this.swap;
}
public int[] controlPoints() {
return this.controlPoints;
}
public boolean isControlPoint(int n) {
if(controlPoints == null || controlPoints.length == 0) {
return false;
}
for(int i = 0; i < controlPoints.length; i++) {
if(controlPoints[i] == n) {
return true;
}
}
return false;
}
public boolean isBeingSwapped(int i) {
return (i == lo || i == hi) && swap;
}
public void exec(int[] array) {
if(swap()) {
int tmp = array[lo];
array[lo] = array[hi];
array[hi] = tmp;
}
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("compared positions ")
.append(lo)
.append(" and ")
.append(hi)
.append(", swap = ")
.append(swap);
return sb.toString();
}
}