FileDocCategorySizeDatePackage
MergeCursor.javaAPI DocAndroid 5.1 API6095Thu Mar 12 22:22:10 GMT 2015android.database

MergeCursor

public class MergeCursor extends AbstractCursor
A convience class that lets you present an array of Cursors as a single linear Cursor. The schema of the cursors presented is entirely up to the creator of the MergeCursor, and may be different if that is desired. Calls to getColumns, getColumnIndex, etc will return the value for the row that the MergeCursor is currently pointing at.

Fields Summary
private DataSetObserver
mObserver
private Cursor
mCursor
private Cursor[]
mCursors
Constructors Summary
public MergeCursor(Cursor[] cursors)

    
      
    
        mCursors = cursors;
        mCursor = cursors[0];
        
        for (int i = 0; i < mCursors.length; i++) {
            if (mCursors[i] == null) continue;
            
            mCursors[i].registerDataSetObserver(mObserver);
        }
    
Methods Summary
public voidclose()

        int length = mCursors.length;
        for (int i = 0 ; i < length ; i++) {
            if (mCursors[i] == null) continue;
            mCursors[i].close();
        }
        super.close();
    
public voiddeactivate()

        int length = mCursors.length;
        for (int i = 0 ; i < length ; i++) {
            if (mCursors[i] != null) {
                mCursors[i].deactivate();
            }
        }
        super.deactivate();
    
public byte[]getBlob(int column)

        return mCursor.getBlob(column);   
    
public java.lang.String[]getColumnNames()

        if (mCursor != null) {
            return mCursor.getColumnNames();
        } else {
            return new String[0];
        }
    
public intgetCount()

        int count = 0;
        int length = mCursors.length;
        for (int i = 0 ; i < length ; i++) {
            if (mCursors[i] != null) {
                count += mCursors[i].getCount();
            }
        }
        return count;
    
public doublegetDouble(int column)

        return mCursor.getDouble(column);
    
public floatgetFloat(int column)

        return mCursor.getFloat(column);
    
public intgetInt(int column)

        return mCursor.getInt(column);
    
public longgetLong(int column)

        return mCursor.getLong(column);
    
public shortgetShort(int column)

        return mCursor.getShort(column);
    
public java.lang.StringgetString(int column)

        return mCursor.getString(column);
    
public intgetType(int column)

        return mCursor.getType(column);
    
public booleanisNull(int column)

        return mCursor.isNull(column);
    
public booleanonMove(int oldPosition, int newPosition)

        /* Find the right cursor */
        mCursor = null;
        int cursorStartPos = 0;
        int length = mCursors.length;
        for (int i = 0 ; i < length; i++) {
            if (mCursors[i] == null) {
                continue;
            }
            
            if (newPosition < (cursorStartPos + mCursors[i].getCount())) {
                mCursor = mCursors[i];
                break;
            }

            cursorStartPos += mCursors[i].getCount();
        }

        /* Move it to the right position */
        if (mCursor != null) {
            boolean ret = mCursor.moveToPosition(newPosition - cursorStartPos);
            return ret;
        }
        return false;
    
public voidregisterContentObserver(ContentObserver observer)

        int length = mCursors.length;
        for (int i = 0 ; i < length ; i++) {
            if (mCursors[i] != null) {
                mCursors[i].registerContentObserver(observer);
            }
        }
    
public voidregisterDataSetObserver(DataSetObserver observer)

        int length = mCursors.length;
        for (int i = 0 ; i < length ; i++) {
            if (mCursors[i] != null) {
                mCursors[i].registerDataSetObserver(observer);
            }
        }
    
public booleanrequery()

        int length = mCursors.length;
        for (int i = 0 ; i < length ; i++) {
            if (mCursors[i] == null) {
                continue;
            }

            if (mCursors[i].requery() == false) {
                return false;
            }
        }

        return true;
    
public voidunregisterContentObserver(ContentObserver observer)

        int length = mCursors.length;
        for (int i = 0 ; i < length ; i++) {
            if (mCursors[i] != null) {
                mCursors[i].unregisterContentObserver(observer);
            }
        }
    
public voidunregisterDataSetObserver(DataSetObserver observer)

        int length = mCursors.length;
        for (int i = 0 ; i < length ; i++) {
            if (mCursors[i] != null) {
                mCursors[i].unregisterDataSetObserver(observer);
            }
        }