Clover Coverage Report - SaveApp Coverage Report
Coverage timestamp: mar dic 23 2014 15:53:11 EST
../../../../img/srcFileCovDistChart3.png 70% of files have more coverage
148   247   54   9,25
22   217   0,36   16
16     3,38  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  Utilities       Line # 15 148 54 30,6% 0.30645162
 
No Tests
 
1    package com.loopback.androidapps.saveapp;
2   
3    import java.text.ParseException;
4    import java.text.SimpleDateFormat;
5    import java.util.ArrayList;
6    import java.util.Calendar;
7    import java.util.Date;
8   
9    import android.app.AlertDialog;
10    import android.content.DialogInterface;
11    import android.database.Cursor;
12    import android.util.Log;
13    import android.view.Display;
14   
 
15    public class Utilities {
16    public static SaveApp saveApp;
17   
18    // String to Integer
 
19  253 toggle public static int stringToInt(String string) {
20  253 Log.i("UT", "String = " + string + ".");
21  253 if (string == null)
22  0 return 0;
23  253 else if (string.compareTo("") == 0)
24  0 return 0;
25    else
26  253 return Integer.valueOf(string);
27    }
28   
29    // String to Double
 
30  74 toggle public static double stringToDouble(String string) {
31  74 if (string == null)
32  0 return 0;
33  74 else if (string.compareTo("") == 0)
34  0 return 0;
35    else
36  74 return Double.valueOf(string);
37    }
38   
 
39  0 toggle public ArrayList<Outlay> readOutlay(Cursor cursor) {
40  0 ArrayList<Outlay> outlayList = new ArrayList<Outlay>();
41  0 int i = 0;
42  0 Log.i("UT", "Read Cursor");
43  0 if (cursor.moveToFirst())
44  0 do {
45  0 Outlay outlay = new Outlay();
46  0 outlay.setId(cursor.getInt(cursor
47    .getColumnIndexOrThrow(DBManager.KEY_ID)));
48  0 outlay.setCharge(cursor.getInt(cursor
49    .getColumnIndexOrThrow(DBManager.OUTLAY_COLUMN_CHARGE)));
50  0 outlay.setDate(cursor.getString(cursor
51    .getColumnIndexOrThrow(DBManager.OUTLAY_COLUMN_DATE)));
52  0 outlayList.add(outlay);
53  0 i++;
54  0 } while (cursor.moveToNext());
55  0 return outlayList;
56    }
57   
58    /*------------------------------------------------------------------------------------------------
59    *--------------------------------------DATE--------------------------------------------------
60    *------------------------------------------------------------------------------------------------ */
 
61  17 toggle public static String dateGetter() {
62  17 String pattern = "MM/dd/yyyy HH:mm";
63  17 SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
64  17 Date date = new Date();
65  17 return dateFormat.format(date);
66    }
67   
 
68  0 toggle public static Date datePutter(String _date) {
69  0 String pattern = "MM/dd/yyyy HH:mm";
70  0 SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
71  0 Date date = new Date();
72  0 try {
73  0 date = dateFormat.parse(_date);
74    } catch (ParseException e) {
75  0 Log.i("UT", "Date Format Error");
76  0 e.printStackTrace();
77    }
78   
79  0 return date;
80   
81    }
82   
83    // Select Layout Depending on the rotation
 
84  0 toggle public static int getLayout(Display display, int orientationPortrait,
85    int orientationLandScape) {
86  0 int orientation = display.getOrientation();
87  0 if (orientation == 1 || orientation == 3)
88  0 return orientationLandScape;
89    else
90  0 return orientationPortrait;
91    }
92   
 
93  0 toggle public static int getDateUnit(Date date, char unit) {
94  0 String pattern = null;
95  0 switch (unit) {
96  0 case 'y':
97  0 pattern = "yyyy";
98  0 break;
99  0 case 'M':
100  0 pattern = "MM";
101  0 break;
102  0 case 'd':
103  0 pattern = "dd";
104  0 break;
105  0 case 'H':
106  0 pattern = "HH";
107  0 break;
108  0 case 'm':
109  0 pattern = "mm";
110  0 break;
111    }
112  0 SimpleDateFormat simpleDateformat = new SimpleDateFormat(pattern);
113  0 return Integer.valueOf(simpleDateformat.format(date));
114    }
115   
 
116  54 toggle public static String getDateUnit(String date, char unit) {
117  54 String result = null;
118  54 switch (unit) {
119  18 case 'y':
120  18 result = date.substring(6, 10);
121  18 break;
122  18 case 'M':
123  18 result = date.substring(0, 2);
124  18 break;
125  18 case 'd':
126  18 result = date.substring(3, 5);
127  18 break;
128  0 case 'H':
129  0 result = date.substring(11, 13);
130  0 break;
131  0 case 'm':
132  0 result = date.substring(13, 15);
133  0 break;
134    } // 06/06/1999 34:34
135  54 return result;
136    }
137   
 
138  66 toggle public static String printDate(String date) {
139  66 if (date.substring(0, 1).equals("N") || date.substring(0, 1).equals(""))
140  0 return date;
141  66 else if (date.length() == 0)
142  0 return date;
143  66 else if (saveApp.isEuropean()) {
144  0 return date.substring(3, 5) + "/" + date.substring(0, 2)
145    + date.substring(6, 10) + "/ " + date.substring(11, 13)
146    + ":" + date.substring(13, 15);
147    } else
148  66 return date;
149    }
150   
 
151  8 toggle public static String formatDate(int _year, int _month, int _day, int _hour,
152    int _minute) {
153  8 String year = String.valueOf(_year);
154  8 String month = String.format("%02d", _month + 1);
155  8 String day = String.format("%02d", _day);
156  8 String hour = String.format("%02d", _hour);
157  8 String minute = String.format("%02d", _minute);
158   
159  8 return month + "/" + day + "/" + year + " " + hour + ":" + minute;
160    }
161   
 
162  13 toggle public static int calculateCurrentBudget() {
163  13 Outlay outlay = new Outlay();
164  13 return saveApp.getBudget() + outlay.sum(saveApp.getAccountId());
165    }
166   
 
167  13 toggle public static int daysUntilToday(String date) {
168  13 Calendar todayCal = Calendar.getInstance();
169  13 Calendar dateCal = Calendar.getInstance();
170  13 dateCal.set(Integer.valueOf(getDateUnit(date, 'y')),
171    Integer.valueOf(Utilities.getDateUnit(date, 'M')) - 1,
172    Integer.valueOf(Utilities.getDateUnit(date, 'd')));
173  13 long milis1 = todayCal.getTimeInMillis();
174  13 long milis2 = dateCal.getTimeInMillis();
175  13 long diff = milis1 - milis2;
176  13 return (int) (diff / (24 * 60 * 60 * 1000));
177    }
178   
 
179  0 toggle public static double dateToMiliseconds(String date) {
180  0 Calendar dateCal = Calendar.getInstance();
181  0 dateCal.set(Integer.valueOf(getDateUnit(date, 'y')),
182    Integer.valueOf(Utilities.getDateUnit(date, 'M')) - 1,
183    Integer.valueOf(Utilities.getDateUnit(date, 'd')));
184  0 return dateCal.getTimeInMillis();
185    }
186   
 
187  0 toggle public static void showAccounts(AlertDialog.Builder builder) {
188  0 final CharSequence[] accounts;
189  0 Account account = new Account();
190  0 accounts = account.selectAccounts();
191  0 builder.setTitle("Chooese Account");
192  0 builder.setItems(accounts, new DialogInterface.OnClickListener() {
 
193  0 toggle public void onClick(DialogInterface dialog, int _item) {
194  0 saveApp.setAccountId(_item + 1);
195   
196    }
197    });
198    }
199   
 
200  0 toggle public static int numberOfDaysPerMonth(int month, int year) {
201  0 int returnValue = 30;
202  0 switch (month) {
203  0 case 1:
204  0 returnValue = 31;
205  0 break;
206  0 case 2:
207  0 if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
208  0 returnValue = 29;
209    else
210  0 returnValue = 28;
211  0 break;
212  0 case 3:
213  0 returnValue = 30;
214  0 break;
215  0 case 4:
216  0 returnValue = 31;
217  0 break;
218  0 case 5:
219  0 returnValue = 30;
220  0 break;
221  0 case 6:
222  0 returnValue = 31;
223  0 break;
224  0 case 7:
225  0 returnValue = 30;
226  0 break;
227  0 case 8:
228  0 returnValue = 31;
229  0 break;
230  0 case 9:
231  0 returnValue = 30;
232  0 break;
233  0 case 10:
234  0 returnValue = 31;
235  0 break;
236  0 case 11:
237  0 returnValue = 30;
238  0 break;
239  0 case 12:
240  0 returnValue = 31;
241  0 break;
242   
243    }
244  0 return returnValue;
245   
246    }
247    }