Class MatrixCursor
- java.lang.Object
-
- android.database.AbstractCursor
-
- android.database.MatrixCursor
-
- All Implemented Interfaces:
CrossProcessCursor,Cursor,Closeable,AutoCloseable
public class MatrixCursor extends AbstractCursor
A mutable cursor implementation backed by an array ofObjects. UsenewRow()to add rows. Automatically expands internal capacity as needed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classMatrixCursor.RowBuilderBuilds a row of values using either of these approaches: Values can be added with explicit column ordering usingMatrixCursor.RowBuilder.add(Object), which starts from the left-most column and adds one column value at a time.
-
Field Summary
-
Fields inherited from class android.database.AbstractCursor
mClosed, mCurrentRowID, mPos, mRowIdColumnIndex, mUpdatedRows
-
Fields inherited from interface android.database.Cursor
FIELD_TYPE_BLOB, FIELD_TYPE_FLOAT, FIELD_TYPE_INTEGER, FIELD_TYPE_NULL, FIELD_TYPE_STRING
-
-
Constructor Summary
Constructors Constructor Description MatrixCursor(String[] columnNames)Constructs a new cursor.MatrixCursor(String[] columnNames, int initialCapacity)Constructs a new cursor with the given initial capacity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRow(Iterable<?> columnValues)Adds a new row to the end with the given column values.voidaddRow(Object[] columnValues)Adds a new row to the end with the given column values.byte[]getBlob(int column)Returns the value of the requested column as a byte array.String[]getColumnNames()Returns a string array holding the names of all of the columns in the result set in the order in which they were listed in the result.intgetCount()Returns the numbers of rows in the cursor.doublegetDouble(int column)Returns the value of the requested column as a double.floatgetFloat(int column)Returns the value of the requested column as a float.intgetInt(int column)Returns the value of the requested column as an int.longgetLong(int column)Returns the value of the requested column as a long.shortgetShort(int column)Returns the value of the requested column as a short.StringgetString(int column)Returns the value of the requested column as a String.intgetType(int column)Returns data type of the given column's value.booleanisNull(int column)Returnstrueif the value in the indicated column is null.MatrixCursor.RowBuildernewRow()Adds a new row to the end and returns a builder for that row.-
Methods inherited from class android.database.AbstractCursor
checkPosition, close, copyStringToBuffer, deactivate, fillWindow, finalize, getColumnCount, getColumnIndex, getColumnIndexOrThrow, getColumnName, getExtras, getPosition, getUpdatedField, getWantsAllOnMoveCalls, getWindow, isAfterLast, isBeforeFirst, isClosed, isFieldUpdated, isFirst, isLast, move, moveToFirst, moveToLast, moveToNext, moveToPosition, moveToPrevious, onChange, onDeactivateOrClose, onMove, registerDataSetObserver, requery, respond, setExtras, unregisterDataSetObserver
-
-
-
-
Constructor Detail
-
MatrixCursor
public MatrixCursor(String[] columnNames, int initialCapacity)
Constructs a new cursor with the given initial capacity.- Parameters:
columnNames- names of the columns, the ordering of which determines column ordering elsewhere in this cursorinitialCapacity- in rows
-
MatrixCursor
public MatrixCursor(String[] columnNames)
Constructs a new cursor.- Parameters:
columnNames- names of the columns, the ordering of which determines column ordering elsewhere in this cursor
-
-
Method Detail
-
newRow
public MatrixCursor.RowBuilder newRow()
Adds a new row to the end and returns a builder for that row. Not safe for concurrent use.- Returns:
- builder which can be used to set the column values for the new row
-
addRow
public void addRow(Object[] columnValues)
Adds a new row to the end with the given column values. Not safe for concurrent use.- Parameters:
columnValues- in the same order as the the column names specified at cursor construction time- Throws:
IllegalArgumentException- ifcolumnValues.length != columnNames.length
-
addRow
public void addRow(Iterable<?> columnValues)
Adds a new row to the end with the given column values. Not safe for concurrent use.- Parameters:
columnValues- in the same order as the the column names specified at cursor construction time- Throws:
IllegalArgumentException- ifcolumnValues.size() != columnNames.length
-
getCount
public int getCount()
Description copied from interface:CursorReturns the numbers of rows in the cursor.- Specified by:
getCountin interfaceCursor- Specified by:
getCountin classAbstractCursor- Returns:
- the number of rows in the cursor.
-
getColumnNames
public String[] getColumnNames()
Description copied from interface:CursorReturns a string array holding the names of all of the columns in the result set in the order in which they were listed in the result.- Specified by:
getColumnNamesin interfaceCursor- Specified by:
getColumnNamesin classAbstractCursor- Returns:
- the names of the columns returned in this query.
-
getString
public String getString(int column)
Description copied from interface:CursorReturns the value of the requested column as a String.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.
- Specified by:
getStringin interfaceCursor- Specified by:
getStringin classAbstractCursor- Parameters:
column- the zero-based index of the target column.- Returns:
- the value of that column as a String.
-
getShort
public short getShort(int column)
Description copied from interface:CursorReturns the value of the requested column as a short.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 [
Short.MIN_VALUE,Short.MAX_VALUE] is implementation-defined.- Specified by:
getShortin interfaceCursor- Specified by:
getShortin classAbstractCursor- Parameters:
column- the zero-based index of the target column.- Returns:
- the value of that column as a short.
-
getInt
public int getInt(int column)
Description copied from interface:CursorReturns the value of the requested column as an int.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 [
Integer.MIN_VALUE,Integer.MAX_VALUE] is implementation-defined.- Specified by:
getIntin interfaceCursor- Specified by:
getIntin classAbstractCursor- Parameters:
column- the zero-based index of the target column.- Returns:
- the value of that column as an int.
-
getLong
public long getLong(int column)
Description copied from interface:CursorReturns the value of the requested column as a long.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 [
Long.MIN_VALUE,Long.MAX_VALUE] is implementation-defined.- Specified by:
getLongin interfaceCursor- Specified by:
getLongin classAbstractCursor- Parameters:
column- the zero-based index of the target column.- Returns:
- the value of that column as a long.
-
getFloat
public float getFloat(int column)
Description copied from interface:CursorReturns the value of the requested column as a float.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
floatvalue is implementation-defined.- Specified by:
getFloatin interfaceCursor- Specified by:
getFloatin classAbstractCursor- Parameters:
column- the zero-based index of the target column.- Returns:
- the value of that column as a float.
-
getDouble
public double getDouble(int column)
Description copied from interface:CursorReturns the value of the requested column as a double.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
doublevalue is implementation-defined.- Specified by:
getDoublein interfaceCursor- Specified by:
getDoublein classAbstractCursor- Parameters:
column- the zero-based index of the target column.- Returns:
- the value of that column as a double.
-
getBlob
public byte[] getBlob(int column)
Description copied from interface:CursorReturns the value of the requested column as a byte array.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.
- Specified by:
getBlobin interfaceCursor- Overrides:
getBlobin classAbstractCursor- Parameters:
column- the zero-based index of the target column.- Returns:
- the value of that column as a byte array.
-
getType
public int getType(int column)
Description copied from interface:CursorReturns data type of the given column's value. The preferred type of the column is returned but the data may be converted to other types as documented in the get-type methods such asCursor.getInt(int),Cursor.getFloat(int)etc.Returned column types are
- Specified by:
getTypein interfaceCursor- Overrides:
getTypein classAbstractCursor- Parameters:
column- the zero-based index of the target column.- Returns:
- column value type
-
isNull
public boolean isNull(int column)
Description copied from interface:CursorReturnstrueif the value in the indicated column is null.- Specified by:
isNullin interfaceCursor- Specified by:
isNullin classAbstractCursor- Parameters:
column- the zero-based index of the target column.- Returns:
- whether the column value is null.
-
-