FileDocCategorySizeDatePackage
ArrayListCursor.javaAPI DocAndroid 1.5 API5096Wed May 06 22:41:56 BST 2009com.android.internal.database

ArrayListCursor

public class ArrayListCursor extends android.database.AbstractCursor
A convenience class that presents a two-dimensional ArrayList as a Cursor.

Fields Summary
private String[]
mColumnNames
private ArrayList[]
mRows
Constructors Summary
public ArrayListCursor(String[] columnNames, ArrayList rows)

        int colCount = columnNames.length;
        boolean foundID = false;
        // Add an _id column if not in columnNames
        for (int i = 0; i < colCount; ++i) {
            if (columnNames[i].compareToIgnoreCase("_id") == 0) {
                mColumnNames = columnNames;
                foundID = true;
                break;
            }
        }

        if (!foundID) {
            mColumnNames = new String[colCount + 1];
            System.arraycopy(columnNames, 0, mColumnNames, 0, columnNames.length);
            mColumnNames[colCount] = "_id";
        }

        int rowCount = rows.size();
        mRows = new ArrayList[rowCount];

        for (int i = 0; i < rowCount; ++i) {
            mRows[i] = rows.get(i);
            if (!foundID) {
                mRows[i].add(i);
            }
        }
    
Methods Summary
public booleandeleteRow()

        return false;
    
public voidfillWindow(int position, android.database.CursorWindow window)

        if (position < 0 || position > getCount()) {
            return;
        }

        window.acquireReference();
        try {
            int oldpos = mPos;
            mPos = position - 1;
            window.clear();
            window.setStartPosition(position);
            int columnNum = getColumnCount();
            window.setNumColumns(columnNum);
            while (moveToNext() && window.allocRow()) {
                for (int i = 0; i < columnNum; i++) {
                    final Object data = mRows[mPos].get(i);
                    if (data != null) {
                        if (data instanceof byte[]) {
                            byte[] field = (byte[]) data;
                            if (!window.putBlob(field, mPos, i)) {
                                window.freeLastRow();
                                break;
                            }
                        } else {
                            String field = data.toString();
                            if (!window.putString(field, mPos, i)) {
                                window.freeLastRow();
                                break;
                            }
                        }
                    } else {
                        if (!window.putNull(mPos, i)) {
                            window.freeLastRow();
                            break;
                        }
                    }
                }
            }

            mPos = oldpos;
        } catch (IllegalStateException e){
            // simply ignore it
        } finally {
            window.releaseReference();
        }
    
public byte[]getBlob(int columnIndex)

        return (byte[]) mRows[mPos].get(columnIndex);
    
public java.lang.String[]getColumnNames()

        return mColumnNames;
    
public intgetCount()

        return mRows.length;
    
public doublegetDouble(int columnIndex)

        Number num = (Number) mRows[mPos].get(columnIndex);
        return num.doubleValue();
    
public floatgetFloat(int columnIndex)

        Number num = (Number) mRows[mPos].get(columnIndex);
        return num.floatValue();
    
public intgetInt(int columnIndex)

        Number num = (Number) mRows[mPos].get(columnIndex);
        return num.intValue();
    
public longgetLong(int columnIndex)

        Number num = (Number) mRows[mPos].get(columnIndex);
        return num.longValue();
    
public shortgetShort(int columnIndex)

        Number num = (Number) mRows[mPos].get(columnIndex);
        return num.shortValue();
    
public java.lang.StringgetString(int columnIndex)

        Object cell = mRows[mPos].get(columnIndex);
        return (cell == null) ? null : cell.toString();
    
public booleanisNull(int columnIndex)

        return mRows[mPos].get(columnIndex) == null;