1 /* 2 * Copyright (C) 2023 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.health.connect; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.health.connect.datatypes.Record; 22 23 import java.util.Objects; 24 25 /** A class to represent filtering based on record id */ 26 public class RecordIdFilter { 27 private final Class<? extends Record> mRecordType; 28 private final String mId; 29 private final String mClientRecordId; 30 31 /** 32 * Creates an instance of Record id filter based on client record id. 33 * 34 * @param recordType Record class for which the client record id must be set. 35 * @param clientRecordId Client identifier that was set while inserting the record. 36 * @return Object of {@link RecordIdFilter} 37 */ 38 @NonNull fromClientRecordId( @onNull Class<? extends Record> recordType, @NonNull String clientRecordId)39 public static RecordIdFilter fromClientRecordId( 40 @NonNull Class<? extends Record> recordType, @NonNull String clientRecordId) { 41 Objects.requireNonNull(recordType); 42 Objects.requireNonNull(clientRecordId); 43 return new RecordIdFilter(recordType, null, clientRecordId); 44 } 45 46 /** 47 * Creates an instance of Record id filter based on record id. 48 * 49 * @param recordType Record class for which the id must be set. 50 * @param id Identifier generated by the platform and returned by {@link 51 * HealthConnectManager#insertRecords} 52 * @return Object of {@link RecordIdFilter} 53 */ 54 @NonNull fromId( @onNull Class<? extends Record> recordType, @NonNull String id)55 public static RecordIdFilter fromId( 56 @NonNull Class<? extends Record> recordType, @NonNull String id) { 57 Objects.requireNonNull(recordType); 58 Objects.requireNonNull(id); 59 return new RecordIdFilter(recordType, id, null); 60 } 61 RecordIdFilter(Class<? extends Record> recordType, String id, String clientRecordId)62 private RecordIdFilter(Class<? extends Record> recordType, String id, String clientRecordId) { 63 mRecordType = recordType; 64 mId = id; 65 mClientRecordId = clientRecordId; 66 } 67 68 /** 69 * @return Record class for this identifier 70 */ 71 @NonNull getRecordType()72 public Class<? extends Record> getRecordType() { 73 return mRecordType; 74 } 75 76 /** 77 * @return Identifier given by the platform 78 */ 79 @Nullable getId()80 public String getId() { 81 return mId; 82 } 83 84 /** 85 * @return Client record identifier 86 */ 87 @Nullable getClientRecordId()88 public String getClientRecordId() { 89 return mClientRecordId; 90 } 91 } 92