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 |
|
|
8 |
|
import android.content.Context; |
9 |
|
import android.content.res.AssetManager; |
10 |
|
|
|
|
| 86,7% |
Uncovered Elements: 8 (60) |
Complexity: 15 |
Complexity Density: 0,37 |
|
11 |
|
public class LoadDataFromTextFile implements Runnable { |
12 |
|
Context context; |
13 |
|
float[][] db; |
14 |
|
static Integer lineCount = 0; |
15 |
|
Boolean finished; |
16 |
|
float threadTime = 0; |
17 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
18 |
1
|
public LoadDataFromTextFile(Context context, float[][] db) {... |
19 |
1
|
this.context = context; |
20 |
1
|
this.db = db; |
21 |
|
} |
22 |
|
|
|
|
| 88,6% |
Uncovered Elements: 4 (35) |
Complexity: 7 |
Complexity Density: 0,28 |
|
23 |
1
|
public void run() {... |
24 |
|
|
25 |
1
|
long start = System.currentTimeMillis(); |
26 |
131
|
for (int i = 0; i < db.length; i++) |
27 |
1065350
|
for (int j = 0; j < db[i].length; j++) |
28 |
1065220
|
db[i][j] = -1; |
29 |
|
|
30 |
1
|
AssetManager am = context.getAssets(); |
31 |
1
|
BufferedReader br = null; |
32 |
1
|
try { |
33 |
1
|
InputStream is = am.open("DATA__3.txt"); |
34 |
1
|
br = new BufferedReader(new InputStreamReader(is, "UTF-8")); |
35 |
|
|
36 |
1
|
String holder = ""; |
37 |
?
|
while ((holder = br.readLine()) != null) { |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
578642
|
String[] values = holder.split("~"); |
43 |
578642
|
db[doInt(values[1])][doInt(values[0])] = (float) (doDouble(values[2])); |
44 |
|
|
45 |
578642
|
if (lineCount++ % 1000 == 10) { |
46 |
579
|
WhatYouEat.mHandler.post(new Runnable() { |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0,5 |
|
47 |
579
|
public void run() {... |
48 |
579
|
int pgrs = (int) (100.0 * lineCount / 578642); |
49 |
579
|
if (pgrs > 97) |
50 |
11
|
pgrs = 100; |
51 |
579
|
WhatYouEat.pb |
52 |
|
.setProgress(pgrs); |
53 |
|
} |
54 |
|
}); |
55 |
579
|
Thread.yield(); |
56 |
|
} |
57 |
|
} |
58 |
1
|
br.close(); |
59 |
|
} catch (IOException e) { |
60 |
|
|
61 |
0
|
e.printStackTrace(); |
62 |
|
} |
63 |
|
|
64 |
1
|
WhatYouEat.calculateHighlightNumbers(); |
65 |
|
|
66 |
|
|
67 |
1
|
WhatYouEat._loaded = true; |
68 |
1
|
if(WhatYouEat.needToSetSearchFoods){ |
69 |
1
|
WhatYouEat.setFoodsIds(); |
70 |
|
} |
71 |
1
|
threadTime = (float) ((System.currentTimeMillis() - start) / 1000.0); |
72 |
1
|
lineCount = 0; |
73 |
1
|
System.out.println("----------DATA BASE LOADED IN----------------->" |
74 |
|
+ threadTime); |
75 |
|
|
76 |
|
} |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
@param |
83 |
|
|
|
|
| 62,5% |
Uncovered Elements: 3 (8) |
Complexity: 3 |
Complexity Density: 0,5 |
|
84 |
578642
|
public static double doDouble(String value) {... |
85 |
578642
|
try { |
86 |
578642
|
double val = Double.parseDouble(value); |
87 |
578642
|
if (val == val) |
88 |
|
|
89 |
578642
|
return val; |
90 |
|
else |
91 |
0
|
return -0.0000001; |
92 |
|
} catch (Exception e) { |
93 |
|
|
94 |
0
|
return -0.0000001; |
95 |
|
} |
96 |
|
} |
97 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
|
98 |
1157284
|
public static int doInt(String value) {... |
99 |
1157284
|
try { |
100 |
1157284
|
int val = Integer.parseInt(value); |
101 |
1157284
|
return val; |
102 |
|
} catch (Exception e) { |
103 |
0
|
return -Integer.MAX_VALUE; |
104 |
|
} |
105 |
|
} |
106 |
|
|
107 |
|
} |