1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.util; |
22 |
|
|
23 |
|
import jalview.ext.android.SparseIntArray; |
24 |
|
import jalview.ext.android.SparseShortArray; |
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
@author |
33 |
|
|
34 |
|
|
|
|
| 84% |
Uncovered Elements: 8 (50) |
Complexity: 18 |
Complexity Density: 0.69 |
|
35 |
|
public class SparseCount |
36 |
|
{ |
37 |
|
private static final int DEFAULT_PROFILE_SIZE = 2; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
private SparseShortArray shortProfile; |
44 |
|
|
45 |
|
private SparseIntArray intProfile; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
private boolean useInts; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
@param |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
58 |
436 |
public SparseCount(int profileSize)... |
59 |
|
{ |
60 |
436 |
this.shortProfile = new SparseShortArray(profileSize); |
61 |
|
} |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
431 |
public SparseCount()... |
68 |
|
{ |
69 |
431 |
this(DEFAULT_PROFILE_SIZE); |
70 |
|
} |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
@param |
77 |
|
@param |
78 |
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
79 |
9345 |
public int add(int key, int value)... |
80 |
|
{ |
81 |
9345 |
int newValue = 0; |
82 |
9345 |
if (useInts) |
83 |
|
{ |
84 |
0 |
newValue = intProfile.add(key, value); |
85 |
|
} |
86 |
|
else |
87 |
|
{ |
88 |
9345 |
try |
89 |
|
{ |
90 |
9345 |
newValue = shortProfile.add(key, value); |
91 |
|
} catch (ArithmeticException e) |
92 |
|
{ |
93 |
2 |
handleOverflow(); |
94 |
2 |
newValue = intProfile.add(key, value); |
95 |
|
} |
96 |
|
} |
97 |
9345 |
return newValue; |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
103 |
2 |
synchronized void handleOverflow()... |
104 |
|
{ |
105 |
2 |
int size = shortProfile.size(); |
106 |
2 |
intProfile = new SparseIntArray(size); |
107 |
4 |
for (int i = 0; i < size; i++) |
108 |
|
{ |
109 |
2 |
short key = shortProfile.keyAt(i); |
110 |
2 |
short value = shortProfile.valueAt(i); |
111 |
2 |
intProfile.put(key, value); |
112 |
|
} |
113 |
2 |
shortProfile = null; |
114 |
2 |
useInts = true; |
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
@return |
121 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
122 |
1098 |
public int size()... |
123 |
|
{ |
124 |
1098 |
return useInts ? intProfile.size() : shortProfile.size(); |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
@param |
131 |
|
@return |
132 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
133 |
9 |
public int get(int key)... |
134 |
|
{ |
135 |
9 |
return useInts ? intProfile.get(key) : shortProfile.get(key); |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
@param |
142 |
|
@param |
143 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
144 |
12 |
public void put(int key, int value)... |
145 |
|
{ |
146 |
12 |
if (useInts) |
147 |
|
{ |
148 |
0 |
intProfile.put(key, value); |
149 |
|
} |
150 |
|
else |
151 |
|
{ |
152 |
12 |
shortProfile.put(key, value); |
153 |
|
} |
154 |
|
} |
155 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
156 |
320 |
public int keyAt(int k)... |
157 |
|
{ |
158 |
320 |
return useInts ? intProfile.keyAt(k) : shortProfile.keyAt(k); |
159 |
|
} |
160 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
161 |
606 |
public int valueAt(int k)... |
162 |
|
{ |
163 |
606 |
return useInts ? intProfile.valueAt(k) : shortProfile.valueAt(k); |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
@return |
171 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
172 |
4 |
boolean isUsingInt()... |
173 |
|
{ |
174 |
4 |
return useInts; |
175 |
|
} |
176 |
|
} |