1 |
|
package co.harlequinmettle.healthfoodconcepts; |
2 |
|
|
3 |
|
import java.io.BufferedReader; |
4 |
|
import java.io.IOException; |
5 |
|
import java.io.InputStream; |
6 |
|
import java.io.InputStreamReader; |
7 |
|
import java.util.ArrayList; |
8 |
|
import java.util.Arrays; |
9 |
|
|
10 |
|
import android.content.Context; |
11 |
|
import android.content.res.AssetManager; |
12 |
|
|
|
|
| 91% |
Uncovered Elements: 7 (78) |
Complexity: 19 |
Complexity Density: 0,35 |
|
13 |
|
public class GeneralLoadingThread implements Runnable { |
14 |
|
Context context; |
15 |
|
String[] info; |
16 |
|
String[] units; |
17 |
|
|
18 |
|
String fromFile; |
19 |
|
int mapID = 0; |
20 |
|
int[][] map; |
21 |
|
int readCount = 0; |
22 |
|
static final int FOOD = 10000203; |
23 |
|
static final int NUTR = 10444443; |
24 |
|
int instanceType; |
25 |
|
ArrayList<ArrayList<Integer>> dynamic = new ArrayList<ArrayList<Integer>>(); |
26 |
|
private int type; |
27 |
|
|
28 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
29 |
1
|
public GeneralLoadingThread(Context context, String[] info, String objFile) {... |
30 |
1
|
this.context = context; |
31 |
1
|
this.info = info; |
32 |
1
|
this.fromFile = objFile; |
33 |
|
} |
34 |
|
|
35 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
36 |
1
|
public GeneralLoadingThread(Context context, String[] info, String[] units,... |
37 |
|
String objFile) { |
38 |
1
|
this.context = context; |
39 |
1
|
this.info = info; |
40 |
1
|
this.units = units; |
41 |
1
|
this.fromFile = objFile; |
42 |
|
|
43 |
|
} |
44 |
|
|
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0,29 |
|
46 |
1
|
public GeneralLoadingThread(Context context, String[] info,... |
47 |
|
int[][] mapping, String objFile, int type) { |
48 |
1
|
this.context = context; |
49 |
1
|
this.info = info; |
50 |
1
|
this.map = mapping; |
51 |
1
|
this.fromFile = objFile; |
52 |
|
|
53 |
26
|
for (int i = 0; i < 25; i++) |
54 |
25
|
dynamic.add(new ArrayList<Integer>()); |
55 |
1
|
instanceType = type; |
56 |
|
} |
57 |
|
|
|
|
| 93,2% |
Uncovered Elements: 3 (44) |
Complexity: 10 |
Complexity Density: 0,33 |
|
58 |
3
|
public void run() {... |
59 |
|
|
60 |
|
|
61 |
3
|
long start = System.currentTimeMillis(); |
62 |
|
|
63 |
3
|
AssetManager am = context.getAssets(); |
64 |
3
|
BufferedReader br = null; |
65 |
3
|
try { |
66 |
3
|
InputStream is = am.open(fromFile); |
67 |
3
|
br = new BufferedReader(new InputStreamReader(is, "UTF-8")); |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
3
|
String holder = ""; |
73 |
?
|
while ((holder = br.readLine()) != null) { |
74 |
|
|
75 |
8347
|
String[] values = holder.split("~"); |
76 |
8347
|
int id = doInt(values[0]); |
77 |
8341
|
if (units == null && map == null) |
78 |
|
|
79 |
25
|
info[id] = values[1]; |
80 |
|
else { |
81 |
8324
|
if (units != null) { |
82 |
130
|
units[id] = values[1]; |
83 |
130
|
info[id] = values[2]; |
84 |
|
|
85 |
|
} else { |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
8194
|
dynamic.get(doInt(values[1])).add(id); |
90 |
|
|
91 |
8194
|
info[id] = values[2]; |
92 |
|
|
93 |
|
} |
94 |
|
} |
95 |
|
|
96 |
8348
|
if (readCount++ % 1000 == 10) { |
97 |
11
|
Thread.yield(); |
98 |
|
} |
99 |
|
} |
100 |
3
|
br.close(); |
101 |
|
} catch (IOException e) { |
102 |
|
|
103 |
0
|
e.printStackTrace(); |
104 |
|
} |
105 |
|
|
106 |
3
|
if (instanceType == FOOD){ |
107 |
26
|
for (int i = 0; i < 25; i++) { |
108 |
25
|
ArrayList<Integer> foods = dynamic.get(i); |
109 |
25
|
map[i] = new int[foods.size()]; |
110 |
8219
|
for (int j = 0; j < foods.size(); j++) { |
111 |
8194
|
map[i][j] = foods.get(j); |
112 |
|
} |
113 |
25
|
Arrays.sort(map[i]); |
114 |
|
|
115 |
|
} |
116 |
|
} |
117 |
3
|
float threadTime = (float) ((System.currentTimeMillis() - start) / 1000.0); |
118 |
3
|
System.out.println(fromFile + "--------------------------->" |
119 |
|
+ threadTime); |
120 |
|
} |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
@param |
127 |
|
|
|
|
| 62,5% |
Uncovered Elements: 3 (8) |
Complexity: 3 |
Complexity Density: 0,5 |
|
128 |
28324
|
public static double doDouble(String value) {... |
129 |
28324
|
try { |
130 |
28324
|
double val = Double.parseDouble(value); |
131 |
28324
|
if (val == val) |
132 |
|
|
133 |
28324
|
return val; |
134 |
|
else |
135 |
0
|
return -0.0000001; |
136 |
|
} catch (Exception e) { |
137 |
0
|
return -0.0000001; |
138 |
|
} |
139 |
|
} |
140 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
|
141 |
30674
|
public static int doInt(String value) {... |
142 |
30671
|
try { |
143 |
30669
|
int val = Integer.parseInt(value); |
144 |
30641
|
return val; |
145 |
|
} catch (Exception e) { |
146 |
0
|
return -Integer.MAX_VALUE; |
147 |
|
} |
148 |
|
} |
149 |
|
|
150 |
|
} |