1 /* 2 * Copyright 2020 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 android.app.appsearch; 18 19 import android.app.appsearch.safeparcel.AbstractSafeParcelable; 20 import android.app.appsearch.safeparcel.SafeParcelable; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import org.jspecify.annotations.NonNull; 25 import org.jspecify.annotations.Nullable; 26 27 import java.util.Collections; 28 import java.util.List; 29 30 /** 31 * This class represents a page of {@link SearchResult}s 32 * 33 * @hide 34 */ 35 @SafeParcelable.Class(creator = "SearchResultPageCreator") 36 public class SearchResultPage extends AbstractSafeParcelable { 37 public static final Parcelable.@NonNull Creator<SearchResultPage> CREATOR = 38 new SearchResultPageCreator(); 39 40 @Field(id = 1, getter = "getNextPageToken") 41 private final long mNextPageToken; 42 43 @Field(id = 2, getter = "getResults") 44 private final @Nullable List<SearchResult> mResults; 45 46 @Constructor SearchResultPage( @aramid = 1) long nextPageToken, @Param(id = 2) @Nullable List<SearchResult> results)47 public SearchResultPage( 48 @Param(id = 1) long nextPageToken, 49 @Param(id = 2) @Nullable List<SearchResult> results) { 50 mNextPageToken = nextPageToken; 51 mResults = results; 52 } 53 54 /** Default constructor for {@link SearchResultPage}. */ SearchResultPage()55 public SearchResultPage() { 56 mNextPageToken = 0; 57 mResults = Collections.emptyList(); 58 } 59 60 /** Returns the Token to get next {@link SearchResultPage}. */ getNextPageToken()61 public long getNextPageToken() { 62 return mNextPageToken; 63 } 64 65 /** Returns all {@link android.app.appsearch.SearchResult}s of this page */ getResults()66 public @NonNull List<SearchResult> getResults() { 67 if (mResults == null) { 68 return Collections.emptyList(); 69 } 70 return mResults; 71 } 72 73 @Override writeToParcel(@onNull Parcel dest, int flags)74 public void writeToParcel(@NonNull Parcel dest, int flags) { 75 SearchResultPageCreator.writeToParcel(this, dest, flags); 76 } 77 } 78