Repository navigation
Expand file tree
/
Copy pathEdit.java
More file actions
67 lines (60 loc) · 1.53 KB
/
Copy pathEdit.java
File metadata and controls
67 lines (60 loc) · 1.53 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
package mutablealignment;
import mutablealignment.MutableAlignment.EditType;
/**
* class for tracking edits to the alignment
* used to restore an alignment if necessary
**/
class Edit {
EditType type;
int siteNr;
int taxonNr;
Object oldValue;
Object newValue;
Edit(int siteNr, int taxonNr, int oldValue, int newValue) {
this.type = EditType.singleSite;
this.siteNr = siteNr;
this.taxonNr = taxonNr;
this.oldValue = oldValue;
this.newValue = newValue;
}
Edit(int siteNr, int [] oldValue, int [] newValue) {
this.type = EditType.allTaxa;
this.siteNr = siteNr;
this.taxonNr = -1;
this.oldValue = oldValue;
this.newValue = newValue;
}
Edit(int [] oldValue, int taxonNr, int [] newValue) {
this.type = EditType.allSites;
this.siteNr = -1;
this.taxonNr = taxonNr;
this.oldValue = oldValue;
this.newValue = newValue;
}
Edit(int [][] oldValue, int [][] newValue) {
this.type = EditType.all;
this.siteNr = -1;
this.taxonNr = -1;
this.oldValue = oldValue;
this.newValue = newValue;
}
void undo(MutableAlignment mutableAlignment) {
switch(type) {
case singleSite:
mutableAlignment.resetSitePatterns(siteNr, taxonNr, (int) oldValue);
break;
case allTaxa:
mutableAlignment.resetSitePatterns(siteNr, (int[])oldValue);
break;
case allSites:
int [] oldValues = (int[]) oldValue;
for (int i = 0; i < oldValues.length; i++) {
mutableAlignment.resetSitePatterns(i, taxonNr, oldValues[i]);
}
break;
case all:
mutableAlignment.resetSitePatterns((int[][])oldValue);
break;
}
}
}