• Home
Name Date Size #Lines LOC

..--

validations/04-Jul-2025-1,4831,010

PhrPageTokenWrapper.javaD04-Jul-202510.1 KiB259145

ReadMedicalResourcesInternalResponse.javaD04-Jul-20253.2 KiB9350

ReadMedicalResourcesInternalResponse.java

1 /*
2  * Copyright (C) 2024 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 com.android.server.healthconnect.phr;
18 
19 import android.annotation.Nullable;
20 import android.health.connect.ReadMedicalResourcesResponse;
21 import android.health.connect.datatypes.MedicalResource;
22 
23 import java.util.List;
24 import java.util.Objects;
25 
26 /**
27  * Internal representation of {@link ReadMedicalResourcesResponse}.
28  *
29  * @hide
30  */
31 public final class ReadMedicalResourcesInternalResponse {
32     @Nullable String mPageToken;
33     List<MedicalResource> mMedicalResources;
34     int mRemainingCount;
35 
ReadMedicalResourcesInternalResponse( List<MedicalResource> medicalResources, @Nullable String pageToken, int remainingCount)36     public ReadMedicalResourcesInternalResponse(
37             List<MedicalResource> medicalResources,
38             @Nullable String pageToken,
39             int remainingCount) {
40         if (pageToken == null && remainingCount > 0) {
41             throw new IllegalArgumentException(
42                     String.format(
43                             "Remaining count must be 0 to have a null next page token, but was %d",
44                             remainingCount));
45         }
46         if (pageToken != null && remainingCount == 0) {
47             throw new IllegalArgumentException("Next page token provided with no remaining data");
48         }
49         mMedicalResources = medicalResources;
50         mPageToken = pageToken;
51         mRemainingCount = remainingCount;
52     }
53 
54     /** Returns the {@code mPageToken}. */
55     @Nullable
getPageToken()56     public String getPageToken() {
57         return mPageToken;
58     }
59 
60     /** Returns the list of {@link MedicalResource}s. */
getMedicalResources()61     public List<MedicalResource> getMedicalResources() {
62         return mMedicalResources;
63     }
64 
65     /**
66      * Returns the count of medical resources still remaining which were not returned due to
67      * pagination.
68      *
69      * <p>For a response with a null next page token, this will be 0. This result is accurate at the
70      * time the request was made, and with the permissions when the request was made. However, the
71      * actual results may change if permissions change or resources are inserted or deleted.
72      */
getRemainingCount()73     public int getRemainingCount() {
74         return mRemainingCount;
75     }
76 
77     /** Indicates whether some other object is "equal to" this one. */
78     @Override
equals(Object o)79     public boolean equals(Object o) {
80         if (this == o) return true;
81         if (!(o instanceof ReadMedicalResourcesInternalResponse that)) return false;
82         return Objects.equals(mPageToken, that.mPageToken)
83                 && Objects.equals(mMedicalResources, that.mMedicalResources)
84                 && mRemainingCount == that.mRemainingCount;
85     }
86 
87     /** Returns a hash code value for the object. */
88     @Override
hashCode()89     public int hashCode() {
90         return Objects.hash(mPageToken, mMedicalResources, mRemainingCount);
91     }
92 }
93