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