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