1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.commands; |
22 |
|
|
23 |
|
import jalview.datamodel.AlignmentI; |
24 |
|
import jalview.datamodel.SequenceI; |
25 |
|
|
26 |
|
import java.util.List; |
27 |
|
|
|
|
| 0% |
Uncovered Elements: 60 (60) |
Complexity: 23 |
Complexity Density: 0.64 |
|
28 |
|
public class ChangeCaseCommand implements CommandI |
29 |
|
{ |
30 |
|
String description; |
31 |
|
|
32 |
|
public static int TO_LOWER = 0; |
33 |
|
|
34 |
|
public static int TO_UPPER = 1; |
35 |
|
|
36 |
|
public static int TOGGLE_CASE = 2; |
37 |
|
|
38 |
|
int caseChange = -1; |
39 |
|
|
40 |
|
SequenceI[] seqs; |
41 |
|
|
42 |
|
List<int[]> regions; |
43 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
44 |
0 |
public ChangeCaseCommand(String description, SequenceI[] seqs,... |
45 |
|
List<int[]> regions, int caseChange) |
46 |
|
{ |
47 |
0 |
this.description = description; |
48 |
0 |
this.seqs = seqs; |
49 |
0 |
this.regions = regions; |
50 |
0 |
this.caseChange = caseChange; |
51 |
0 |
doCommand(null); |
52 |
|
} |
53 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
0 |
public String getDescription()... |
55 |
|
{ |
56 |
0 |
return description; |
57 |
|
} |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
0 |
public int getSize()... |
60 |
|
{ |
61 |
0 |
return 1; |
62 |
|
} |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
0 |
public void doCommand(AlignmentI[] views)... |
65 |
|
{ |
66 |
0 |
changeCase(true); |
67 |
|
} |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
69 |
0 |
public void undoCommand(AlignmentI[] views)... |
70 |
|
{ |
71 |
0 |
changeCase(false); |
72 |
|
} |
73 |
|
|
|
|
| 0% |
Uncovered Elements: 45 (45) |
Complexity: 18 |
Complexity Density: 0.67 |
|
74 |
0 |
void changeCase(boolean doCommand)... |
75 |
|
{ |
76 |
0 |
String sequence; |
77 |
0 |
int start, end; |
78 |
0 |
char nextChar; |
79 |
0 |
for (int[] r : regions) |
80 |
|
{ |
81 |
0 |
start = r[0]; |
82 |
0 |
for (int s = 0; s < seqs.length; s++) |
83 |
|
{ |
84 |
0 |
sequence = seqs[s].getSequenceAsString(); |
85 |
0 |
StringBuffer newSeq = new StringBuffer(); |
86 |
|
|
87 |
0 |
if (r[1] > sequence.length()) |
88 |
|
{ |
89 |
0 |
end = sequence.length(); |
90 |
|
} |
91 |
|
else |
92 |
|
{ |
93 |
0 |
end = r[1]; |
94 |
|
} |
95 |
|
|
96 |
0 |
if (start > 0) |
97 |
|
{ |
98 |
0 |
newSeq.append(sequence.substring(0, start)); |
99 |
|
} |
100 |
|
|
101 |
0 |
if ((caseChange == TO_UPPER && doCommand) |
102 |
|
|| (caseChange == TO_LOWER && !doCommand)) |
103 |
|
{ |
104 |
0 |
newSeq.append(sequence.substring(start, end).toUpperCase()); |
105 |
|
} |
106 |
|
|
107 |
0 |
else if ((caseChange == TO_LOWER && doCommand) |
108 |
|
|| (caseChange == TO_UPPER && !doCommand)) |
109 |
|
{ |
110 |
0 |
newSeq.append(sequence.substring(start, end).toLowerCase()); |
111 |
|
} |
112 |
|
|
113 |
|
else |
114 |
|
|
115 |
|
{ |
116 |
0 |
for (int c = start; c < end; c++) |
117 |
|
{ |
118 |
0 |
nextChar = sequence.charAt(c); |
119 |
0 |
if ('a' <= nextChar && nextChar <= 'z') |
120 |
|
{ |
121 |
|
|
122 |
0 |
nextChar -= ('a' - 'A'); |
123 |
|
} |
124 |
0 |
else if ('A' <= nextChar && nextChar <= 'Z') |
125 |
|
{ |
126 |
|
|
127 |
0 |
nextChar += ('a' - 'A'); |
128 |
|
} |
129 |
0 |
newSeq.append(nextChar); |
130 |
|
} |
131 |
|
} |
132 |
|
|
133 |
0 |
if (end < sequence.length()) |
134 |
|
{ |
135 |
0 |
newSeq.append(sequence.substring(end)); |
136 |
|
} |
137 |
|
|
138 |
0 |
seqs[s].setSequence(newSeq.toString()); |
139 |
|
} |
140 |
|
} |
141 |
|
} |
142 |
|
|
143 |
|
} |