1 /*
2  * Copyright 2018 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 androidx.paging;
18 
19 import androidx.annotation.NonNull;
20 import androidx.annotation.Nullable;
21 
22 import java.util.concurrent.Executor;
23 
24 abstract class ContiguousDataSource<Key, Value> extends DataSource<Key, Value> {
25     @Override
isContiguous()26     boolean isContiguous() {
27         return true;
28     }
29 
dispatchLoadInitial( @ullable Key key, int initialLoadSize, int pageSize, boolean enablePlaceholders, @NonNull Executor mainThreadExecutor, @NonNull PageResult.Receiver<Value> receiver)30     abstract void dispatchLoadInitial(
31             @Nullable Key key,
32             int initialLoadSize,
33             int pageSize,
34             boolean enablePlaceholders,
35             @NonNull Executor mainThreadExecutor,
36             @NonNull PageResult.Receiver<Value> receiver);
37 
dispatchLoadAfter( int currentEndIndex, @NonNull Value currentEndItem, int pageSize, @NonNull Executor mainThreadExecutor, @NonNull PageResult.Receiver<Value> receiver)38     abstract void dispatchLoadAfter(
39             int currentEndIndex,
40             @NonNull Value currentEndItem,
41             int pageSize,
42             @NonNull Executor mainThreadExecutor,
43             @NonNull PageResult.Receiver<Value> receiver);
44 
dispatchLoadBefore( int currentBeginIndex, @NonNull Value currentBeginItem, int pageSize, @NonNull Executor mainThreadExecutor, @NonNull PageResult.Receiver<Value> receiver)45     abstract void dispatchLoadBefore(
46             int currentBeginIndex,
47             @NonNull Value currentBeginItem,
48             int pageSize,
49             @NonNull Executor mainThreadExecutor,
50             @NonNull PageResult.Receiver<Value> receiver);
51 
52     /**
53      * Get the key from either the position, or item, or null if position/item invalid.
54      * <p>
55      * Position may not match passed item's position - if trying to query the key from a position
56      * that isn't yet loaded, a fallback item (last loaded item accessed) will be passed.
57      */
getKey(int position, Value item)58     abstract Key getKey(int position, Value item);
59 }
60