1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.contacts.database; 18 19 import android.database.AbstractCursor; 20 import android.database.CursorIndexOutOfBoundsException; 21 22 /** 23 * A cursor that is empty. 24 * <p> 25 * If you want an empty cursor, this class is better than a MatrixCursor because it has less 26 * overhead. 27 */ 28 final public class EmptyCursor extends AbstractCursor { 29 30 private String[] mColumns; 31 EmptyCursor(String[] columns)32 public EmptyCursor(String[] columns) { 33 this.mColumns = columns; 34 } 35 36 @Override getCount()37 public int getCount() { 38 return 0; 39 } 40 41 @Override getColumnNames()42 public String[] getColumnNames() { 43 return mColumns; 44 } 45 46 @Override getString(int column)47 public String getString(int column) { 48 throw cursorException(); 49 } 50 51 @Override getShort(int column)52 public short getShort(int column) { 53 throw cursorException(); 54 } 55 56 @Override getInt(int column)57 public int getInt(int column) { 58 throw cursorException(); 59 } 60 61 @Override getLong(int column)62 public long getLong(int column) { 63 throw cursorException(); 64 } 65 66 @Override getFloat(int column)67 public float getFloat(int column) { 68 throw cursorException(); 69 } 70 71 @Override getDouble(int column)72 public double getDouble(int column) { 73 throw cursorException(); 74 } 75 76 @Override isNull(int column)77 public boolean isNull(int column) { 78 throw cursorException(); 79 } 80 cursorException()81 private CursorIndexOutOfBoundsException cursorException() { 82 return new CursorIndexOutOfBoundsException("Operation not permitted on an empty cursor."); 83 } 84 } 85