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 |
|
|
|
|
| 0% |
Uncovered Elements: 50 (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 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
58 |
0 |
public SparseCount(int profileSize)... |
59 |
|
{ |
60 |
0 |
this.shortProfile = new SparseShortArray(profileSize); |
61 |
|
} |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
0 |
public SparseCount()... |
68 |
|
{ |
69 |
0 |
this(DEFAULT_PROFILE_SIZE); |
70 |
|
} |
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
@param |
77 |
|
@param |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
79 |
0 |
public int add(int key, int value)... |
80 |
|
{ |
81 |
0 |
int newValue = 0; |
82 |
0 |
if (useInts) |
83 |
|
{ |
84 |
0 |
newValue = intProfile.add(key, value); |
85 |
|
} |
86 |
|
else |
87 |
|
{ |
88 |
0 |
try |
89 |
|
{ |
90 |
0 |
newValue = shortProfile.add(key, value); |
91 |
|
} catch (ArithmeticException e) |
92 |
|
{ |
93 |
0 |
handleOverflow(); |
94 |
0 |
newValue = intProfile.add(key, value); |
95 |
|
} |
96 |
|
} |
97 |
0 |
return newValue; |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
103 |
0 |
synchronized void handleOverflow()... |
104 |
|
{ |
105 |
0 |
int size = shortProfile.size(); |
106 |
0 |
intProfile = new SparseIntArray(size); |
107 |
0 |
for (int i = 0; i < size; i++) |
108 |
|
{ |
109 |
0 |
short key = shortProfile.keyAt(i); |
110 |
0 |
short value = shortProfile.valueAt(i); |
111 |
0 |
intProfile.put(key, value); |
112 |
|
} |
113 |
0 |
shortProfile = null; |
114 |
0 |
useInts = true; |
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
@return |
121 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
122 |
0 |
public int size()... |
123 |
|
{ |
124 |
0 |
return useInts ? intProfile.size() : shortProfile.size(); |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
@param |
131 |
|
@return |
132 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
133 |
0 |
public int get(int key)... |
134 |
|
{ |
135 |
0 |
return useInts ? intProfile.get(key) : shortProfile.get(key); |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
@param |
142 |
|
@param |
143 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
144 |
0 |
public void put(int key, int value)... |
145 |
|
{ |
146 |
0 |
if (useInts) |
147 |
|
{ |
148 |
0 |
intProfile.put(key, value); |
149 |
|
} |
150 |
|
else |
151 |
|
{ |
152 |
0 |
shortProfile.put(key, value); |
153 |
|
} |
154 |
|
} |
155 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
156 |
0 |
public int keyAt(int k)... |
157 |
|
{ |
158 |
0 |
return useInts ? intProfile.keyAt(k) : shortProfile.keyAt(k); |
159 |
|
} |
160 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
161 |
0 |
public int valueAt(int k)... |
162 |
|
{ |
163 |
0 |
return useInts ? intProfile.valueAt(k) : shortProfile.valueAt(k); |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
@return |
171 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
172 |
0 |
boolean isUsingInt()... |
173 |
|
{ |
174 |
0 |
return useInts; |
175 |
|
} |
176 |
|
} |