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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
package de.thedevstack.conversationsplus.persistance;
import android.database.Cursor;
/**
* Created by steckbrief on 15.04.2016.
*/
public abstract class CursorHelper {
static double getDouble(Cursor cursor, String columnName) {
if (null == cursor) {
return Double.MIN_VALUE;
}
int columnIndex = getColumnIndex(cursor, columnName);
if (columnIndex < 0) {
return Double.MIN_VALUE;
}
return getDouble(cursor, columnIndex);
}
static String getString(Cursor cursor, String columnName) {
if (null == cursor) {
return null;
}
int columnIndex = getColumnIndex(cursor, columnName);
if (columnIndex < 0) {
return null;
}
return getString(cursor, columnIndex);
}
static float getFloat(Cursor cursor, String columnName) {
if (null == cursor) {
return Float.MIN_VALUE;
}
int columnIndex = getColumnIndex(cursor, columnName);
if (columnIndex < 0) {
return Float.MIN_VALUE;
}
return getFloat(cursor, columnIndex);
}
static int getInt(Cursor cursor, String columnName) {
if (null == cursor) {
return Integer.MIN_VALUE;
}
int columnIndex = getColumnIndex(cursor, columnName);
if (columnIndex < 0) {
return Integer.MIN_VALUE;
}
return getInt(cursor, columnIndex);
}
static long getLong(Cursor cursor, String columnName) {
if (null == cursor) {
return Long.MIN_VALUE;
}
int columnIndex = getColumnIndex(cursor, columnName);
if (columnIndex < 0) {
return Long.MIN_VALUE;
}
return getLong(cursor, columnIndex);
}
static int getShort(Cursor cursor, String columnName) {
if (null == cursor) {
return Short.MIN_VALUE;
}
int columnIndex = getColumnIndex(cursor, columnName);
if (columnIndex < 0) {
return Short.MIN_VALUE;
}
return getShort(cursor, columnIndex);
}
static byte[] getBlob(Cursor cursor, String columnName) {
if (null == cursor) {
return null;
}
int columnIndex = getColumnIndex(cursor, columnName);
if (columnIndex < 0) {
return null;
}
return getBlob(cursor, columnIndex);
}
/**
* Returns the zero-based index for the given column name, or -1 if the column doesn't exist.
* If you expect the column to exist use {@link Cursor#getColumnIndexOrThrow(String)} instead, which
* will make the error more clear.
*
* @param columnName the name of the target column.
* @return the zero-based column index for the given column name, or -1 if
* the column name does not exist.
* @see Cursor#getColumnIndexOrThrow(String)
*/
static int getColumnIndex(Cursor cursor, String columnName) {
return cursor.getColumnIndex(columnName);
}
/**
* Returns the value of the requested column as a byte array.
*
* <p>The result and whether this method throws an exception when the
* column value is null or the column type is not a blob type is
* implementation-defined.
*
* @param columnIndex the zero-based index of the target column.
* @return the value of that column as a byte array.
*/
static byte[] getBlob(Cursor cursor, int columnIndex) {
return cursor.getBlob(columnIndex);
}
/**
* Returns the value of the requested column as a String.
*
* <p>The result and whether this method throws an exception when the
* column value is null or the column type is not a string type is
* implementation-defined.
*
* @param columnIndex the zero-based index of the target column.
* @return the value of that column as a String.
*/
static String getString(Cursor cursor, int columnIndex) {
return cursor.getString(columnIndex);
}
/**
* Returns the value of the requested column as a short.
*
* <p>The result and whether this method throws an exception when the
* column value is null, the column type is not an integral type, or the
* integer value is outside the range [<code>Short.MIN_VALUE</code>,
* <code>Short.MAX_VALUE</code>] is implementation-defined.
*
* @param columnIndex the zero-based index of the target column.
* @return the value of that column as a short.
*/
static short getShort(Cursor cursor, int columnIndex) {
return cursor.getShort(columnIndex);
}
/**
* Returns the value of the requested column as an int.
*
* <p>The result and whether this method throws an exception when the
* column value is null, the column type is not an integral type, or the
* integer value is outside the range [<code>Integer.MIN_VALUE</code>,
* <code>Integer.MAX_VALUE</code>] is implementation-defined.
*
* @param columnIndex the zero-based index of the target column.
* @return the value of that column as an int.
*/
static int getInt(Cursor cursor, int columnIndex) {
return cursor.getInt(columnIndex);
}
/**
* Returns the value of the requested column as a long.
*
* <p>The result and whether this method throws an exception when the
* column value is null, the column type is not an integral type, or the
* integer value is outside the range [<code>Long.MIN_VALUE</code>,
* <code>Long.MAX_VALUE</code>] is implementation-defined.
*
* @param columnIndex the zero-based index of the target column.
* @return the value of that column as a long.
*/
static long getLong(Cursor cursor, int columnIndex) {
return cursor.getLong(columnIndex);
}
/**
* Returns the value of the requested column as a float.
*
* <p>The result and whether this method throws an exception when the
* column value is null, the column type is not a floating-point type, or the
* floating-point value is not representable as a <code>float</code> value is
* implementation-defined.
*
* @param columnIndex the zero-based index of the target column.
* @return the value of that column as a float.
*/
static float getFloat(Cursor cursor, int columnIndex) {
return cursor.getFloat(columnIndex);
}
/**
* Returns the value of the requested column as a double.
*
* <p>The result and whether this method throws an exception when the
* column value is null, the column type is not a floating-point type, or the
* floating-point value is not representable as a <code>double</code> value is
* implementation-defined.
*
* @param columnIndex the zero-based index of the target column.
* @return the value of that column as a double.
*/
static double getDouble(Cursor cursor, int columnIndex) {
return cursor.getDouble(columnIndex);
}
}
|