SuggestionCursorWrapper.java revision 87e947cbd9f279a83337900ff8bbd5ab0a8dc455
1/*
2 * Copyright (C) 2010 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
17package com.android.quicksearchbox;
18
19import android.database.DataSetObserver;
20
21/**
22 * A suggestion cursor that delegates all methods to another SuggestionCursor.
23 */
24public class SuggestionCursorWrapper extends AbstractSuggestionCursorWrapper {
25
26    private final SuggestionCursor mCursor;
27
28    public SuggestionCursorWrapper(String userQuery, SuggestionCursor cursor) {
29        super(userQuery);
30        mCursor = cursor;
31    }
32
33    public void close() {
34        if (mCursor != null) {
35            mCursor.close();
36        }
37    }
38
39    public int getCount() {
40        return mCursor == null ? 0 : mCursor.getCount();
41    }
42
43    public int getPosition() {
44        return mCursor == null ? 0 : mCursor.getPosition();
45    }
46
47    public void moveTo(int pos) {
48        if (mCursor != null) {
49            mCursor.moveTo(pos);
50        }
51    }
52
53    public boolean moveToNext() {
54        if (mCursor != null) {
55            return mCursor.moveToNext();
56        } else {
57            return false;
58        }
59    }
60
61    public void registerDataSetObserver(DataSetObserver observer) {
62        if (mCursor != null) {
63            mCursor.registerDataSetObserver(observer);
64        }
65    }
66
67    public void unregisterDataSetObserver(DataSetObserver observer) {
68        if (mCursor != null) {
69            mCursor.unregisterDataSetObserver(observer);
70        }
71    }
72
73    @Override
74    protected SuggestionCursor current() {
75        return mCursor;
76    }
77
78}
79