-
Notifications
You must be signed in to change notification settings - Fork 0
/
CursorASCIITable.java
170 lines (149 loc) · 3.98 KB
/
CursorASCIITable.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package za.co.immedia.ASCIITable;
import android.database.Cursor;
import android.util.Log;
import com.bethecoder.ascii_table.ASCIITable;
/**
* <p>
* Dependent: https://code.google.com/p/java-ascii-table/
* </p>
* Logger for Cursor's to help debug tables, it will output rows and columns, You may need to limit the columns due to Log wrapping
*
* @author Duncan Dean Scholtz ([email protected])
*
*/
public class CursorASCIITable {
private static final String TAG = "CursorASCIITable";
/**
* Generates the ASCIITable based on the cursor provided
*
* @param c
* @return The ASCIITable as a String
*/
public static String getTable(Cursor c) {
return getTable(c, null);
}
/**
* @param c
* @param limitToCols
* Limit column output
* @return
*/
public static String getTable(Cursor c, String[] limitToCols) {
String table = "";
if (c != null) {
int limitCount = limitToCols == null ? c.getColumnCount() : limitToCols.length;
String[] header = new String[limitCount];
String[][] data = new String[c.getCount()][limitCount];
if (limitToCols == null) {
for (int i = 0; i < c.getColumnCount(); i++) {
header[i] = c.getColumnName(i);
}
} else {
for (int i = 0; i < limitToCols.length; i++) {
header[i] = limitToCols[i];
}
}
int count = 0;
if (c.moveToFirst()) {
do {
if (limitToCols == null) {
for (int i = 0; i < c.getColumnCount(); i++) {
data[count][i] = c.getString(i);
}
} else {
for (int i = 0; i < limitToCols.length; i++) {
data[count][i] = c.getString(c.getColumnIndex(limitToCols[i]));
}
}
count++;
} while (c.moveToNext());
}
table = ASCIITable.getInstance().getTable(header, data);
}
return table;
}
/**
* @param c
*/
public static void d(Cursor c) {
Log.d(TAG, getTable(c));
}
/**
* @param c
* @param limitToCols
* Limit column output
*/
public static void d(Cursor c, String[] limitToCols) {
Log.d(TAG, getTable(c));
}
/**
* @param c
*/
public static void i(Cursor c) {
Log.i(TAG, getTable(c));
}
/**
* @param c
* @param limitToCols
* Limit column output
*/
public static void i(Cursor c, String[] limitToCols) {
Log.i(TAG, getTable(c));
}
/**
* @param c
*/
public static void e(Cursor c) {
Log.e(TAG, getTable(c));
}
/**
* @param c
* @param limitToCols
* Limit column output
*/
public static void e(Cursor c, String[] limitToCols) {
Log.e(TAG, getTable(c));
}
/**
* @param c
*/
public static void w(Cursor c) {
Log.w(TAG, getTable(c));
}
/**
* @param c
* @param limitToCols
* Limit column output
*/
public static void w(Cursor c, String[] limitToCols) {
Log.w(TAG, getTable(c));
}
/**
* @param c
*/
public static void v(Cursor c) {
Log.v(TAG, getTable(c));
}
/**
* @param c
* @param limitToCols
* Limit column output
*/
public static void v(Cursor c, String[] limitToCols) {
Log.v(TAG, getTable(c));
}
/**
* @param c
*/
public static void wtf(Cursor c) {
Log.wtf(TAG, getTable(c));
}
/**
* @param c
* @param limitToCols
* Limit column output
*/
public static void wtf(Cursor c, String[] limitToCols) {
Log.wtf(TAG, getTable(c));
}
}