Clover Coverage Report - WhatYouEat Coverage Report
Coverage timestamp: sab gen 3 2015 15:14:15 EST
../../../img/srcFileCovDistChart7.png 75% of files have more coverage
372   816   113   12
94   629   0,3   15,5
31     3,65  
2    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  WhatYouEat       Line # 37 356 109 59,7% 0.5966387
  WhatYouEat.SimpleStatsBuilder       Line # 721 16 4 95,2% 0.95238096
 
No Tests
 
1    package co.harlequinmettle.healthfoodconcepts;
2   
3    import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
4    import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
5    import static android.widget.LinearLayout.VERTICAL;
6   
7    import java.io.FileInputStream;
8    import java.io.FileOutputStream;
9    import java.io.IOException;
10    import java.io.ObjectInputStream;
11    import java.io.ObjectOutputStream;
12    import java.util.ArrayList;
13    import java.util.Arrays;
14    import java.util.HashMap;
15    import java.util.HashSet;
16    import java.util.LinkedHashMap;
17    import java.util.Map.Entry;
18    import java.util.TreeMap;
19   
20    import android.app.ActionBar;
21    import android.app.Activity;
22    import android.content.Context;
23    import android.os.Build;
24    import android.os.Bundle;
25    import android.os.Handler;
26    import android.util.DisplayMetrics;
27    import android.view.Gravity;
28    import android.view.MotionEvent;
29    import android.view.View;
30    import android.view.View.OnTouchListener;
31    import android.view.ViewGroup;
32    import android.widget.HorizontalScrollView;
33    import android.widget.LinearLayout;
34    import android.widget.ProgressBar;
35    import android.widget.Toast;
36   
 
37    public class WhatYouEat extends Activity implements OnTouchListener,
38    I_Preferences, HasServingSizeInfo {
39    //
40    static Thread loadingThread;
41    static HorizontalScrollView application;
42    static LinearLayout appAccess;
43    static MenuScroller intro, settings;
44    static ArrayList<TreeMap<Integer, Boolean>> allMyFoods = new ArrayList<TreeMap<Integer, Boolean>>();
45    // static HashMap<String, Integer> searchResults = new HashMap<String,
46    // Integer>();
47    static HashMap<Integer, Float> myFoodQuantities = new HashMap<Integer, Float>();
48    static HashMap<Integer, Integer> myFoodUnitIDs = new HashMap<Integer, Integer>();
49    static HashMap<Integer, String> myFoodUnits = new HashMap<Integer, String>();
50   
51    // static HashMap<Integer, Boolean> myGoodNutrients = new HashMap<Integer,
52    // Boolean>();
53    static boolean[] myGoodNutrients;
54    static float[] goodNutritionGoals;
55    // static float[] defaultNutritionGoals;
56    static Context ctx;
57    // static final int[] CHILD_ID = new int[40];
58    static boolean _loaded = false;
59   
60    static final int USING_KCAL = 200000;
61    static final int USING_SERVING = 400000;
62    static final int USING_GRAMS = 800000;
63   
64    static final int USE_ALL_FOODS = 10000;
65    static final int USE_MY_FOOD_GROUPS = 5000;
66    static final int USE_MY_FOODS = 500;
67    static final int USE_ONE_FOOD_GROUP = 128;
68   
69    static final int SEARCH_TYPE_SUM = 10000002;
70    static final int SEARCH_TYPE_PRODUCT = 10000001;
71   
72    // static final int VIEW_HORIZONTAL = 151516161;
73    static final int VIEW_VERTICAL = 515151661;
74    // PREFERENCE NEEDS TO BE STORED AND RESTORED AS PREFERENCE
75    static int myFoods_View = VIEW_VERTICAL;
76    static int Foods_Search = USE_ALL_FOODS;
77    static int Nutrient_Measure = USING_GRAMS;
78    static int Food_Group = 21;// default irrelevant
79    static int Search_Type = SEARCH_TYPE_PRODUCT;
80   
81    static boolean longLoading = false;
82    static boolean searching = false;
83    static boolean calculatingStats = false;
84    static boolean statsLoaded = false;
85    static float sw, sh;
86    static float[][] db = new float[130][8194];
87    static final int FOOD_COUNT = 8194;// REPLACE ALL APP WIDE INSTANCEES WITH
88    // CONTANT
89   
90    // 4052~23~Honey
91    static String[] foods = new String[8194];
92    // static int[] MY_FOODS;
93    // static byte[] foodGroupMap = new byte[8194];// CHANGE TO BYTE
94    // static float[] kCal ;// CHANGE TO BYTE
95    // 9~Fats and Oils
96    static String[] foodGroups = new String[25];
97    // 5~kcal~Energy
98    static String[] nutrients = new String[130];
99    static String[] units = new String[130];
100   
101    static int[][] foodsByGroup = new int[25][];
102   
103    static String[] searchResults;
104    static int[] foodCodeResults;
105    static final int PROGRESS_BAR_ID = 100010001;
106    static int[] searchTheseFoods;
107   
108    private static final String DATA_100G = "database_object";
109    public static final int USING_NOT_ZEROS = 1024;
110    public static final int USING_ZEROS = 2048;
111    public static int DATA_CHOICES = USING_NOT_ZEROS;
112    // loading definitions:
113    // a - nutrient units
114    // b - foodGroup
115    // c - food foodGroupMap kcalPer100G
116    GeneralLoadingThread a, b, c;
117    public static boolean[] MY_FOOD_GROUPS;
118    public static boolean[] MY_NUTRIENTS;
119    static ProgressBar pb;
120    static Handler mHandler = new Handler();
121   
122    static HashMap<Integer, StatTool> nutritionStats = new HashMap<Integer, StatTool>();
123    static HashMap<Integer, float[]> highlightFactors = new HashMap<Integer, float[]>();
124   
125    // -1 if no serving size info is available
126    static int[] optimalServingId = new int[FOOD_COUNT];
127    // all food ids with servings size info (at least 1)
128    static int[] WITH_SERVING_SIZE = HAS_SERVING_INFO;
129   
130    static String[][] oddUnits = new String[FOOD_COUNT][];// for each food id
131    // list of different
132    // units
133    static float[][] metricConversion = new float[FOOD_COUNT][];// corresponding
134    // grams
135    static float[][] quantityFactor = new float[FOOD_COUNT][];// corresponding
136    // amount of
137    // different
138    // units
139    static final int TEXT_SMALL = 21;
140    static final int TEXT_MED = 25;
141    static final int TEXT_LARGE = 35;
142    static boolean needToSetSearchFoods;
143    public static int save_db = 0;
144    static WhatYouEat _MyApp;
145   
 
146  1 toggle @Override
147    protected void onCreate(Bundle savedInstanceState) {
148  1 super.onCreate(savedInstanceState);
149  1 setDefaults();
150  1 _MyApp = this;
151    // int version = Build.VERSION.SDK_INT;
152    // if(version>10 && version < 14 ){
153    // ActionBar bar = getActionBar();
154    // bar.hide();
155    // }
156    // always set metrics for screen width and height
157  1 DisplayMetrics metrics = new DisplayMetrics();
158  1 getWindowManager().getDefaultDisplay().getMetrics(metrics);
159  1 sw = metrics.widthPixels;
160  1 sh = metrics.heightPixels;
161   
162  1 ctx = this;// field reference to current context
163    // main layout (and its one child) for whole app
164  1 application = new HorizontalScrollView(this);
165  1 appAccess = new LinearLayout(this);// may need to make sure its
166   
167    // try to obtain weather use prefers 100g 100kcal or 'serving'
168  1 Nutrient_Measure = restorePreference("SEARCHUNITS");
169   
170  1 Foods_Search = restorePreference("SEARCHFOODS");//
171   
172  1 save_db = restorePreference("SAVEDB");
173   
174  1 restoreGuidelines();
175   
176  1 restoreMyGoodNutrients();
177   
178  1 restoreMyFoodUnitIds();
179   
180  1 if (!loadMyFoodGroups())
181  1 MY_FOOD_GROUPS = DEFAULT_FOOD_GROUPS;
182   
183  1 if (!loadMyNutrients())
184  1 MY_NUTRIENTS = DEFAULT_NUTRIENTS;
185   
186  8195 for (int i = 0; i < optimalServingId.length; i++) {
187  8194 optimalServingId[i] = -1;
188    }
189    // OPTIONAL TO SAVE AS OBJECTS AND LOAD LIKE DB
190   
191  1 a = new GeneralLoadingThread(this, nutrients, units, "nutr.txt");
192   
193  1 b = new GeneralLoadingThread(this, foodGroups, "group.txt");
194    // KCAL PER100G REPLACE WITH DIRECT REFERENCE TO DB[5]
195  1 c = new GeneralLoadingThread(this, foods, foodsByGroup, "food.txt",
196    GeneralLoadingThread.FOOD);
197    // sorts each foodgroup id after loading
198   
199  1 new Thread(a).start();
200  1 new Thread(b).start();
201  1 new Thread(c).start();
202   
203  1 new Thread(new LoadWeightsConversion()).start();
204    // load database if objects not found automatically lauch text reading
205    // thread
206    // either thread finishes by starting thread to load
207  1 _loaded = false;
208  1 ObjectLoadingThread objLoader = new ObjectLoadingThread(this, db);
209  1 loadingThread = new Thread(objLoader);
210  1 loadingThread.start();
211   
212  1 setFoodsIds();
213   
214  1 restoreQuantities();
215  1 restoreUnits();
216   
217   
218  1 pb = new ProgressBar(this, null,
219    android.R.attr.progressBarStyleHorizontal);
220  1 pb.setId(PROGRESS_BAR_ID);
221  1 intro = new MenuScroller(this, pb, 0);
222   
223  1 appAccess.addView(intro);
224   
225  1 application.addView(appAccess);
226   
227  1 setContentView(application);
228   
229   
230  1 Toast mToast = Toast
231    .makeText(
232    this,
233    "\n\n\n\n\nPlease adjust some settings while database loads\n\n\n\n\n",
234    1);
235  1 mToast.setGravity(Gravity.TOP, 0, 50);
236   
237  1 mToast.show();
238  1 if (!loadMyFoods())
239  26 for (int i = 0; i < 25; i++) {
240  25 allMyFoods.add(new TreeMap<Integer, Boolean>());
241    }
242    // saveObject(0, "SAVEDB");
243    }
244   
 
245  0 toggle public void resetStaticContext() {
246  0 ctx = this;
247    }
248   
 
249  1 toggle private void setDefaults() {
250  8195 for (int i = 0; i < FOOD_COUNT; i++) {
251  8194 oddUnits[i] = new String[1];// for each food id
252  8194 oddUnits[i][0] = "grams"; // list of different
253  8194 metricConversion[i] = new float[1];// corresponding
254  8194 metricConversion[i][0] = 100;// defalut convert 100g into 100g
255  8194 quantityFactor[i] = new float[1];// corresponding
256  8194 quantityFactor[i][0] = 100;
257    }
258    }
259   
 
260  1 toggle private void restoreMyGoodNutrients() {
261  1 int def = 0;
262  1 boolean[] x = null;
263  1 try {
264  1 FileInputStream fis = ctx.openFileInput("GOODNUTR");
265  0 ObjectInputStream objin = new ObjectInputStream(fis);
266  0 x = (boolean[]) objin.readObject();
267  0 objin.close();
268   
269    } catch (Exception ioe) {
270    }
271  1 if (x != null)
272  0 myGoodNutrients = x;
273    else
274  1 myGoodNutrients = DEFAULT_GOOD_NUTRIENTS.clone();
275    }
276   
 
277  1 toggle public static String[] getMyFoodsAsTextArray() {
278  1 ArrayList<String> foodListConstruct = new ArrayList<String>();
279  1 for (TreeMap<Integer, Boolean> foodi : WhatYouEat.allMyFoods) {
280  25 for (Integer i : foodi.keySet()) {
281  3 foodListConstruct.add(foods[i]);
282    }
283    }
284  1 String[] fd = new String[foodListConstruct.size()];
285  4 for (int i = 0; i < fd.length; i++) {
286  3 fd[i] = foodListConstruct.get(i);
287    }
288  1 return fd;
289    }
290   
 
291  1 toggle public static int[] getMyFoodsIdsArray() {
292  1 ArrayList<Integer> foodIdsConstruct = new ArrayList<Integer>();
293  1 for (TreeMap<Integer, Boolean> foodi : WhatYouEat.allMyFoods) {
294  25 for (Integer i : foodi.keySet()) {
295  3 foodIdsConstruct.add(i);
296    }
297    }
298  1 int[] ids = new int[foodIdsConstruct.size()];
299  4 for (int i = 0; i < ids.length; i++) {
300  3 ids[i] = foodIdsConstruct.get(i);
301    }
302  1 return ids;
303    }
304   
 
305  9 toggle public static void setFoodsIds() {
306  9 int[] theseFoods = null;
307  9 switch (Foods_Search) {
308  1 case USE_ALL_FOODS:
309  1 theseFoods = new int[8194];
310  8195 for (int i = 0; i < 8194; i++)
311  8194 theseFoods[i] = i;
312  1 break;
313  0 case USE_MY_FOODS:
314  0 ArrayList<Integer> getMySelectFoods = new ArrayList<Integer>();
315   
316  0 for (TreeMap<Integer, Boolean> amf : allMyFoods) {
317  0 for (Entry<Integer, Boolean> ent : amf.entrySet()) {
318  0 if (ent.getValue())
319  0 getMySelectFoods.add(ent.getKey());
320    }
321    }
322  0 theseFoods = new int[getMySelectFoods.size()];
323  0 for (int i = 0; i < theseFoods.length; i++)
324  0 theseFoods[i] = getMySelectFoods.get(i);
325   
326  0 break;
327  6 case USE_MY_FOOD_GROUPS:
328  6 if (_loaded)
329  5 theseFoods = constructUniqueValuesFromMyFoodGroups();
330    else
331  1 needToSetSearchFoods = true;
332  6 break;
333  2 case USE_ONE_FOOD_GROUP:
334  2 theseFoods = foodsByGroup[Food_Group];
335  2 break;
336  0 default:
337  0 theseFoods = foodsByGroup[Food_Group];
338  0 break;
339    }
340   
341  9 searchTheseFoods = theseFoods;
342    }
343   
 
344  10 toggle public static String getFoodsSearchDescription() {
345   
346  10 switch (Foods_Search) {
347  0 case USE_ALL_FOODS:
348  0 return "all foods in database";
349   
350  0 case USE_MY_FOODS:
351  0 return "My Foods";
352  10 case USE_MY_FOOD_GROUPS:
353  10 return "My Food Groups";
354  0 case USE_ONE_FOOD_GROUP:
355  0 return foodGroups[Food_Group];
356  0 default:
357  0 break;
358    }
359   
360  0 return "";
361    }
362   
 
363  6 toggle private static int[] constructUniqueValuesFromMyFoodGroups() {
364  6 HashSet<Integer> uniqueValues = new HashSet<Integer>();
365  156 for (int i = 0; i < MY_FOOD_GROUPS.length; i++) {
366  150 if (MY_FOOD_GROUPS[i]) {
367  109 for (int j : foodsByGroup[i]) {
368  39369 uniqueValues.add(j);
369    }
370    }
371    }
372  6 int counter = 0;
373  6 int[] uniques = new int[uniqueValues.size()];
374  6 for (int i : uniqueValues) {
375  39369 uniques[counter++] = i;
376    }
377  6 return uniques;
378    }
379   
 
380  0 toggle private static int[] constructUniqueValuesFromMyFoods() {
381  0 HashSet<Integer> uniqueValues = new HashSet<Integer>();
382  0 for (int i = 0; i < allMyFoods.size(); i++) {
383  0 TreeMap<Integer, Boolean> perGroup = allMyFoods.get(i);
384  0 if (MY_FOOD_GROUPS[i]) {
385  0 for (int j : perGroup.keySet()) {
386  0 uniqueValues.add(j);
387    }
388    }
389    }
390  0 int counter = 0;
391  0 int[] uniques = new int[uniqueValues.size()];
392  0 for (int i : uniqueValues) {
393  0 uniques[counter++] = i;
394    }
395  0 return uniques;
396    }
397   
 
398  25 toggle public static int[] getFoodSearchIds() {
399  25 return searchTheseFoods;
400    }
401   
402    // CALL AFTER DATABASE IS LOADED AND AFTER CHANGES TO SETTINGS
 
403  6 toggle public static void calculateHighlightNumbers() {
404  6 new Thread(new SimpleStatsBuilder()).start();
405    }
406   
 
407  3 toggle private int restorePreference(String string) {
408  3 int def = 0;
409  3 try {
410  3 FileInputStream fis = this.openFileInput(string);
411  0 ObjectInputStream objin = new ObjectInputStream(fis);
412  0 def = (Integer) objin.readObject();
413  0 objin.close();
414   
415    } catch (Exception ioe) {
416  3 if (string.equals("SEARCHUNITS"))
417  1 return WhatYouEat.USING_GRAMS;
418  2 else if (string.equals("SEARCHFOODS"))
419  1 return WhatYouEat.USE_MY_FOOD_GROUPS;
420    else
421  1 return 0;
422    }
423  0 return def;
424    }
425   
 
426  1 toggle static void restoreGuidelines() {
427  1 int def = 0;
428  1 float[] x = null;
429  1 try {
430  1 FileInputStream fis = ctx.openFileInput("GOODNUTRGOALS");
431  0 ObjectInputStream objin = new ObjectInputStream(fis);
432  0 x = (float[]) objin.readObject();
433  0 objin.close();
434   
435    } catch (Exception ioe) {
436    }
437  1 if (x != null)
438  0 goodNutritionGoals = x;
439    else
440  1 goodNutritionGoals = DEFAULT_NUTR_GOALS.clone();
441    }
442   
 
443  1 toggle private void restoreUnits() {
444  1 int def = 0;
445  1 HashMap<Integer, String> x = null;
446  1 try {
447  1 FileInputStream fis = this.openFileInput("UNITYMAP");
448  0 ObjectInputStream objin = new ObjectInputStream(fis);
449  0 x = (HashMap<Integer, String>) objin.readObject();
450  0 objin.close();
451   
452    } catch (Exception ioe) {
453    }
454  1 if (x != null)
455  0 myFoodUnits = x;
456    }
457   
 
458  1 toggle private void restoreMyFoodUnitIds() {
459  1 int def = 0;
460  1 HashMap<Integer, Integer> x = null;
461  1 try {
462  1 FileInputStream fis = this.openFileInput("UNITIDMAP");
463  0 ObjectInputStream objin = new ObjectInputStream(fis);
464  0 x = (HashMap<Integer, Integer>) objin.readObject();
465  0 objin.close();
466   
467    } catch (Exception ioe) {
468    }
469  1 if (x != null)
470  0 myFoodUnitIDs = x;
471    }
472   
 
473  1 toggle private void restoreQuantities() {
474  1 int def = 0;
475  1 HashMap<Integer, Float> x = null;
476  1 try {
477  1 FileInputStream fis = this.openFileInput("QUANTITYMAP");
478  0 ObjectInputStream objin = new ObjectInputStream(fis);
479  0 x = (HashMap<Integer, Float>) objin.readObject();
480  0 objin.close();
481   
482    } catch (Exception ioe) {
483    }
484  1 if (x != null)
485  0 myFoodQuantities = x;
486    }
487   
 
488  1 toggle public boolean loadMyFoodGroups() {
489  1 try {
490    // TEST ALTERNATIVE LOAD FROM PRESTORED OBJECTS ASSETMANAGER
491  1 FileInputStream fis = this.openFileInput("MYFOODGROUPS");
492  0 ObjectInputStream objin = new ObjectInputStream(fis);
493  0 MY_FOOD_GROUPS = (boolean[]) objin.readObject();
494  0 objin.close();
495   
496    } catch (Exception ioe) {
497  1 return false;
498    }
499  0 return true;
500    }
501   
 
502  1 toggle public boolean loadMyFoods() {
503  1 try {
504    // TEST ALTERNATIVE LOAD FROM PRESTORED OBJECTS ASSETMANAGER
505  1 FileInputStream fis = this.openFileInput("MYFOODS");
506  0 ObjectInputStream objin = new ObjectInputStream(fis);
507  0 allMyFoods = (ArrayList<TreeMap<Integer, Boolean>>) objin
508    .readObject();
509  0 objin.close();
510   
511    } catch (Exception ioe) {
512  1 return false;
513    }
514  0 return true;
515    }
516   
 
517  1 toggle public boolean loadMyNutrients() {
518  1 try {
519    // TEST ALTERNATIVE LOAD FROM PRESTORED OBJECTS ASSETMANAGER
520  1 FileInputStream fis = this.openFileInput("MYNUTRIENTS");
521  0 ObjectInputStream objin = new ObjectInputStream(fis);
522  0 MY_NUTRIENTS = (boolean[]) objin.readObject();
523  0 objin.close();
524   
525    } catch (Exception ioe) {
526  1 return false;
527    }
528  0 return true;
529    }
530   
 
531  46 toggle public static void saveObject(Object OBJ, String obLocatorName) {
532  46 try {
533  46 FileOutputStream fos = ctx.openFileOutput(obLocatorName,
534    Context.MODE_PRIVATE);
535  46 ObjectOutputStream objout = new ObjectOutputStream(fos);
536  46 objout.writeObject(OBJ);
537  46 objout.flush();
538  46 objout.close();
539   
540    } catch (IOException ioe) {
541    }
542    }
543   
 
544  1 toggle @Override
545    public void onPause() {
546  1 super.onPause();
547    // OTHERWISE OBJECT IS NOT DESTROYED AND GETTING ERROR:
548    // CHILD ALREADY HAS A PARENT ON MENUSCROLLER-ADDKEYWORDSCROLLERS
549   
550    // STORE PREFERENC ARRAYS AS OBJECTS
551   
552    // SAVE OTHER DATA EXPERIMENT
553    }
554   
555    // ///////////////////////////////////////
 
556  0 toggle public LinearLayout basicLinearLayout() {
557  0 LinearLayout basic = new LinearLayout(this);
558  0 ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
559    MATCH_PARENT, WRAP_CONTENT);
560  0 basic.setLayoutParams(params);
561  0 basic.setOrientation(VERTICAL);
562  0 return basic;
563    }
564   
 
565  0 toggle @Override
566    public boolean onTouch(View v, MotionEvent event) {
567   
568  0 float xDown = event.getX();
569  0 float yDown = event.getY();
570  0 switch (event.getActionMasked()) {
571  0 case MotionEvent.ACTION_POINTER_DOWN:
572  0 break;
573  0 case MotionEvent.ACTION_POINTER_UP:
574  0 break;
575  0 case MotionEvent.ACTION_MOVE:
576  0 break;
577  0 case MotionEvent.ACTION_DOWN:
578    // setContentView(_longLayout);
579  0 break;
580  0 case MotionEvent.ACTION_UP:
581   
582  0 break;
583    }
584  0 return true;
585    }// END EVENTS
586   
 
587  4 toggle public static void setSearchResultsFrom(String searchWord, int groups_search) {
588  4 searching = true;
589  4 if (searchWord.length() < 3) {
590  1 searchResults = new String[1];
591  1 foodCodeResults = new int[1];
592  1 searchResults[0] = "Water, tap, drinking";
593  1 foodCodeResults[0] = 8081;
594  1 return;
595    }
596  3 ArrayList<String> results = new ArrayList<String>();
597  3 ArrayList<Long> resultsID = new ArrayList<Long>();
598   
599    // search for search word as one single unit only
600  3 int[] foodIDsToSearch;
601   
602  3 switch (groups_search) {
603  0 case USE_ALL_FOODS:
604  0 foodIDsToSearch = new int[FOOD_COUNT];
605  0 for (int i = 0; i < FOOD_COUNT; i++) {
606  0 foodIDsToSearch[i] = i;
607    }
608  0 break;
609  1 case USE_MY_FOOD_GROUPS:
610  1 foodIDsToSearch = constructUniqueValuesFromMyFoodGroups();
611  1 break;
612  0 case USE_MY_FOODS:
613  0 foodIDsToSearch = constructUniqueValuesFromMyFoods();
614  0 break;
615  0 case USE_ONE_FOOD_GROUP:
616  0 foodIDsToSearch = foodsByGroup[Food_Group];
617  0 break;
618  2 default:
619   
620  2 foodIDsToSearch = foodsByGroup[groups_search];
621  2 break;
622    }
623   
624  3 String sw = searchWord.trim();
625  3 while (sw.contains(" ")) {
626  0 sw = sw.replaceAll(" ", " ");
627    }
628  3 sw = " " + sw + " ";
629    // for each food description with spaces added check for an exact
630    // match
631  3 for (int fdID : foodIDsToSearch) {
632  7855 String item = " " + foods[fdID];
633  7855 if (item.toLowerCase().replaceAll("[,\\(\\)]", " ").contains(sw)) {
634  107 results.add(item.trim());
635  107 resultsID.add(new Long(fdID));
636    }
637    }
638  3 if (false) {
639  0 sw = sw.trim() + " ";
640  0 if (results.size() < 50)
641  0 for (int fdID : foodIDsToSearch) {
642  0 String item = " " + foods[fdID];
643  0 if (item.toLowerCase().replaceAll("[,\\(\\)]", " ")
644    .contains(sw)
645    && !results.contains(item.trim())) {
646  0 results.add(item.trim());
647  0 resultsID.add(new Long(fdID));
648    }
649    }
650    }
651    // sw = " " + sw.trim();
652  3 sw = sw.trim();
653  3 if (results.size() < 40 && sw.length() > 2)
654  2 for (int fdID : foodIDsToSearch) {
655  1570 String item = foods[fdID];
656  1570 if (!results.contains(item.trim())
657    && item.toLowerCase().contains(sw)) {
658    //System.out .println("found with regex --- --- ---- --- ---- ----");
659  0 results.add(item.trim());
660  0 resultsID.add(new Long(fdID));
661    }
662    }
663   
664  3 if (results.size() < 5)
665  1 if (searchWord.length() > 3) {
666  1 searchWord = searchWord.trim().substring(0,
667    searchWord.length() - 1);
668  1 for (int fdID : foodIDsToSearch) {
669  785 String item = " " + foods[fdID];
670  785 if (!results.contains(item.trim())
671    && item.toLowerCase().replaceAll("[,\\(\\)]", " ")
672    .contains(searchWord))
673  0 results.add(item.trim());
674  785 resultsID.add(new Long(fdID));
675    //System.out.println("found ON letter less ONE");
676   
677    }
678    }
679   
680  3 if (results.size() < 50) {
681  2 String[] sWords = searchWord.trim().split(" ");
682  2 if (sWords.length > 1)
683  0 outerloop: for (int fdID : foodIDsToSearch) {
684  0 String item = foods[fdID];
685  0 for (String pt : sWords) {
686  0 if (results.contains(item.trim())
687    || !item.toLowerCase().contains(pt)
688    && pt.length() > 3)
689  0 continue outerloop;
690    }
691  0 results.add(item.trim());
692  0 resultsID.add(new Long(fdID));
693  0 System.out.println("found MULTIPLE WORD CASE---");
694  0 if (results.size() > 50) {
695  0 break outerloop;
696    }
697    }
698    }
699    // load results of search int static array
700    // string description with cooresponding food code
701  3 searchResults = new String[results.size()];
702  3 foodCodeResults = new int[results.size()];
703   
704  110 for (int i = 0; i < results.size(); i++) {
705  107 searchResults[i] = results.get(i);
706  107 foodCodeResults[i] = (resultsID.get(i).intValue());
707   
708    }
709  3 searching = false;
710    }
711   
 
712  0 toggle static int[] concat(int[] A, int[] B) {
713  0 int aLen = A.length;
714  0 int bLen = B.length;
715  0 int[] C = new int[aLen + bLen];
716  0 System.arraycopy(A, 0, C, 0, aLen);
717  0 System.arraycopy(B, 0, C, aLen, bLen);
718  0 return C;
719    }
720   
 
721    private static class SimpleStatsBuilder implements Runnable {
722   
 
723  6 toggle @Override
724    public void run() {
725  6 try {
726  6 loadingThread.join();
727    } catch (InterruptedException e) {
728    // TODO Auto-generated catch block
729  0 e.printStackTrace();
730    }
731  6 calculatingStats = true;
732  6 statsLoaded = false;
733  6 long time = System.currentTimeMillis();
734   
735  6 int[] foodIds = WhatYouEat.getFoodSearchIds();
736  786 for (int i = 0; i < 130; i++) {
737  780 boolean b = MY_NUTRIENTS[i];
738  780 if (!b)
739  314 continue;
740  466 float[] basically = StatTool.simpleStats(foodIds, i);
741   
742  466 highlightFactors.put(i, basically);
743   
744  466 Thread.yield();
745   
746    }
747   
748  6 statsLoaded = true;
749  6 calculatingStats = false;
750    }
751   
752    }
753   
 
754  0 toggle public static byte getRelativeAbundance(int nutrient, float data) {
755   
756  0 float[] nstat = WhatYouEat.highlightFactors.get(nutrient);
757  0 float min = nstat[0];
758  0 float mean = nstat[1];
759  0 float max = nstat[2];
760   
761  0 float n = 0;
762   
763  0 if (data > mean) {
764  0 n = data - mean;
765  0 n /= (max - mean);
766   
767    } else {
768   
769  0 n = -(mean - data) / (mean - min + 1);
770    }
771  0 int sim = (int) (n * 100);
772  0 if (sim > 100)
773  0 sim = (int) (101 + 100 * Math.log(n - 100));
774   
775  0 return (byte) sim;
776   
777    }
778   
 
779  0 toggle public static float getPer100KcalDataPoint(int foodID, float data) {
780  0 float calories = db[5][foodID];
781    // RETURN NEGATIVE IF CALORIES ARE ZERO AND USE SERVING
782  0 float rData = (float) (100.0 * data);
783  0 if (calories > 10)
784  0 rData /= (db[5][foodID]);
785    else
786  0 rData /= (20);
787  0 return (float) (((int) (1000 * (rData))) / 1000.0);
788   
789    }
790   
791    // 7416~1~tsp~2.2 - weights conversion
792    //
 
793  657606 toggle public static float getPerServingDataPoint(int foodID,
794    float nutritionPer100Grams) {
795  657606 if (quantityFactor[foodID] == null||optimalServingId[foodID]<0)
796  18553 return -1;
797   
798  639053 float quantityOfOddUnit = quantityFactor[foodID][optimalServingId[foodID]];
799  639053 float gramsPerOddUnit = metricConversion[foodID][optimalServingId[foodID]];
800   
801  639053 float rData = nutritionPer100Grams * gramsPerOddUnit / 100.0f;
802  639053 return (float) (((int) (1000 * (rData))) / 1000.0);
803   
804    }
805   
 
806  9 toggle public static int findGroupFromFoodID(int foodId) {
807  30 for (int i = 0; i < 25; i++) {
808  30 if (Arrays.binarySearch(foodsByGroup[i], foodId) >= 0)
809  9 return i;
810    }
811   
812  0 return 10;
813    }
814   
815    }// END APP
816