Clover Coverage Report - WhatYouEat Coverage Report
Coverage timestamp: sab gen 3 2015 15:14:15 EST
../../../img/srcFileCovDistChart10.png 0% of files have more coverage
54   150   19   9
18   108   0,35   6
6     3,17  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  GeneralLoadingThread       Line # 13 54 19 91% 0.9102564
 
No Tests
 
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   
 
13    public class GeneralLoadingThread implements Runnable {
14    Context context;
15    String[] info;
16    String[] units;
17    // float[] kcalMap;
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    // loads food group name list
 
29  1 toggle 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    // loads nutrient definitions map and nutrient unit mapping
 
36  1 toggle 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    // loads food definitions and foodgroup mapping
 
46  1 toggle 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    // this.kcalMap = kcal;
53  26 for (int i = 0; i < 25; i++)
54  25 dynamic.add(new ArrayList<Integer>());
55  1 instanceType = type;
56    }
57   
 
58  3 toggle 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    // 7~g~Water ---- units info
70    // 9~Fats and Oils ---- info
71    // 4039~19~Ham salad spread ---- mapping info ---- Kcal/100g
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)// first constructor
78    // load foodgroup
79  25 info[id] = values[1];
80    else {
81  8324 if (units != null) {
82  130 units[id] = values[1];// nutrient units
83  130 info[id] = values[2];
84   
85    } else {
86    // food definition with food group and kcal/100g
87    //
88    // 3237~7~Egg, whole, raw, fresh~143
89  8194 dynamic.get(doInt(values[1])).add(id);
90    // map[id] = (byte)doInt((values[1]));
91  8194 info[id] = values[2];
92    // kcalMap[id] = (float)(doDouble(values[ 3]));
93    }
94    }
95   
96  8348 if (readCount++ % 1000 == 10) {
97  11 Thread.yield();
98    }
99    }
100  3 br.close();
101    } catch (IOException e) {
102    // TODO Auto-generated catch block
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    //System.out.println(Arrays.toString(map[i]));
115    }
116    }
117  3 float threadTime = (float) ((System.currentTimeMillis() - start) / 1000.0);
118  3 System.out.println(fromFile + "--------------------------->"
119    + threadTime);
120    }
121   
122    /*
123    * returns the double value of a string and returns -1E-7 if the string
124    * could not be parsed as a double.
125    *
126    * @param value the string that gets converted into a double.
127    */
 
128  28324 toggle public static double doDouble(String value) {
129  28324 try {
130  28324 double val = Double.parseDouble(value);
131  28324 if (val == val)// only return value if its not NaN , NaN==NaN is
132    // false
133  28324 return val;
134    else
135  0 return -0.0000001;
136    } catch (Exception e) {
137  0 return -0.0000001;
138    }
139    }
140   
 
141  30674 toggle 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    }// END FILE LOAD THREAD