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 com.android.adservices.data.topics; 18 19 import android.annotation.NonNull; 20 21 import com.android.internal.annotations.Immutable; 22 23 import com.google.auto.value.AutoValue; 24 25 import java.util.Objects; 26 27 /** POJO to store unencrypted {@link Topic} and encrypted {@link EncryptedTopic}. */ 28 @AutoValue 29 @Immutable 30 public abstract class CombinedTopic { 31 /** 32 * @return Unencrypted Topic object. 33 */ getTopic()34 public abstract Topic getTopic(); 35 36 /** 37 * @return Encrypted Topic object. 38 */ getEncryptedTopic()39 public abstract EncryptedTopic getEncryptedTopic(); 40 41 /** 42 * Creates an instance of {@link CombinedTopic}. 43 * 44 * @param topic Unencrypted topic object. 45 * @param encryptedTopic Encrypted topic object 46 * @return Combined topic object containing both encrypted and unencrypted topic object. 47 */ 48 @NonNull create(Topic topic, EncryptedTopic encryptedTopic)49 public static CombinedTopic create(Topic topic, EncryptedTopic encryptedTopic) { 50 Objects.requireNonNull(topic); 51 Objects.requireNonNull(encryptedTopic); 52 53 return builder().setTopic(topic).setEncryptedTopic(encryptedTopic).build(); 54 } 55 56 /** 57 * @return generic builder 58 */ 59 @NonNull builder()60 public static CombinedTopic.Builder builder() { 61 return new AutoValue_CombinedTopic.Builder(); 62 } 63 64 /** Builder for {@link CombinedTopic}. */ 65 @AutoValue.Builder 66 public abstract static class Builder { 67 /** Set unencrypted Topic */ setTopic(Topic topic)68 public abstract CombinedTopic.Builder setTopic(Topic topic); 69 70 /** Set encrypted Topic */ setEncryptedTopic(EncryptedTopic encryptedTopic)71 public abstract CombinedTopic.Builder setEncryptedTopic(EncryptedTopic encryptedTopic); 72 73 /** Build a CombinedTopic instance */ 74 @NonNull build()75 public abstract CombinedTopic build(); 76 } 77 78 @Override equals(Object object)79 public final boolean equals(Object object) { 80 if (this == object) return true; 81 if (!(object instanceof CombinedTopic)) return false; 82 CombinedTopic combinedTopic = (CombinedTopic) object; 83 return getTopic().equals(combinedTopic.getTopic()) 84 && getEncryptedTopic().equals(combinedTopic.getEncryptedTopic()); 85 } 86 87 @Override hashCode()88 public final int hashCode() { 89 return Objects.hash(getTopic().hashCode(), getEncryptedTopic().hashCode()); 90 } 91 92 @Override toString()93 public final String toString() { 94 return "CombinedTopic{" 95 + "topic=" 96 + getTopic() 97 + ", encryptedTopic=" 98 + getEncryptedTopic() 99 + '}'; 100 } 101 } 102