diff options
-rw-r--r-- | core/java/android/database/MatrixCursor.java | 43 | ||||
-rw-r--r-- | tests/CoreTests/android/database/MatrixCursorTest.java | 6 |
2 files changed, 33 insertions, 16 deletions
diff --git a/core/java/android/database/MatrixCursor.java b/core/java/android/database/MatrixCursor.java index cf5a573..d5c3a32 100644 --- a/core/java/android/database/MatrixCursor.java +++ b/core/java/android/database/MatrixCursor.java @@ -214,53 +214,64 @@ public class MatrixCursor extends AbstractCursor { // AbstractCursor implementation. + @Override public int getCount() { return rowCount; } + @Override public String[] getColumnNames() { return columnNames; } + @Override public String getString(int column) { - return String.valueOf(get(column)); + Object value = get(column); + if (value == null) return null; + return value.toString(); } + @Override public short getShort(int column) { Object value = get(column); - return (value instanceof String) - ? Short.valueOf((String) value) - : ((Number) value).shortValue(); + if (value == null) return 0; + if (value instanceof Number) return ((Number) value).shortValue(); + return Short.parseShort(value.toString()); } + @Override public int getInt(int column) { Object value = get(column); - return (value instanceof String) - ? Integer.valueOf((String) value) - : ((Number) value).intValue(); + if (value == null) return 0; + if (value instanceof Number) return ((Number) value).intValue(); + return Integer.parseInt(value.toString()); } + @Override public long getLong(int column) { Object value = get(column); - return (value instanceof String) - ? Long.valueOf((String) value) - : ((Number) value).longValue(); + if (value == null) return 0; + if (value instanceof Number) return ((Number) value).longValue(); + return Long.parseLong(value.toString()); } + @Override public float getFloat(int column) { Object value = get(column); - return (value instanceof String) - ? Float.valueOf((String) value) - : ((Number) value).floatValue(); + if (value == null) return 0.0f; + if (value instanceof Number) return ((Number) value).floatValue(); + return Float.parseFloat(value.toString()); } + @Override public double getDouble(int column) { Object value = get(column); - return (value instanceof String) - ? Double.valueOf((String) value) - : ((Number) value).doubleValue(); + if (value == null) return 0.0d; + if (value instanceof Number) return ((Number) value).doubleValue(); + return Double.parseDouble(value.toString()); } + @Override public boolean isNull(int column) { return get(column) == null; } diff --git a/tests/CoreTests/android/database/MatrixCursorTest.java b/tests/CoreTests/android/database/MatrixCursorTest.java index fb8a12f..cddc6c4 100644 --- a/tests/CoreTests/android/database/MatrixCursorTest.java +++ b/tests/CoreTests/android/database/MatrixCursorTest.java @@ -32,6 +32,12 @@ public class MatrixCursorTest extends TestCase { cursor.newRow().add(null); cursor.moveToNext(); assertTrue(cursor.isNull(0)); + assertNull(cursor.getString(0)); + assertEquals(0, cursor.getShort(0)); + assertEquals(0, cursor.getInt(0)); + assertEquals(0L, cursor.getLong(0)); + assertEquals(0.0f, cursor.getFloat(0)); + assertEquals(0.0d, cursor.getDouble(0)); } public void testMatrixCursor() { |