1 /*
2  * Copyright (C) 2022 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 package com.android.quicksearchbox
17 
18 import android.database.DataSetObserver
19 import com.android.quicksearchbox.util.QuietlyCloseable
20 import kotlin.collections.Collection
21 
22 /** A sequence of suggestions, with a current position. */
23 interface SuggestionCursor : Suggestion, QuietlyCloseable {
24   /** Gets the query that the user typed to get this suggestion. */
25   val userQuery: String?
26 
27   /**
28    * Gets the number of suggestions in this result.
29    *
30    * @return The number of suggestions, or `0` if this result represents a failed query.
31    */
32   val count: Int
33 
34   /**
35    * Moves to a given suggestion.
36    *
37    * @param pos The position to move to.
38    * @throws IndexOutOfBoundsException if `pos < 0` or `pos >= getCount()`.
39    */
moveTonull40   fun moveTo(pos: Int)
41 
42   /**
43    * Moves to the next suggestion, if there is one.
44    *
45    * @return `false` if there is no next suggestion.
46    */
47   fun moveToNext(): Boolean
48 
49   /** Gets the current position within the cursor. */
50   val position: Int
51 
52   /** Frees any resources used by this cursor. */
53   @Override override fun close()
54 
55   /**
56    * Register an observer that is called when changes happen to this data set.
57    *
58    * @param observer gets notified when the data set changes.
59    */
60   fun registerDataSetObserver(observer: DataSetObserver?)
61 
62   /**
63    * Unregister an observer that has previously been registered with [.registerDataSetObserver]
64    *
65    * @param observer the observer to unregister.
66    */
67   fun unregisterDataSetObserver(observer: DataSetObserver?)
68 
69   /** Return the extra columns present in this cursor, or null if none exist. */
70   val extraColumns: Collection<String>?
71 }
72