1 /* 2 * Copyright (C) 2022 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.adservices.customaudience; 18 19 import android.adservices.common.AdTechIdentifier; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 23 import java.util.Objects; 24 25 /** The request object is used to leave a custom audience. */ 26 public final class LeaveCustomAudienceRequest { 27 @NonNull private final AdTechIdentifier mBuyer; 28 @NonNull private final String mName; 29 LeaveCustomAudienceRequest(@onNull LeaveCustomAudienceRequest.Builder builder)30 private LeaveCustomAudienceRequest(@NonNull LeaveCustomAudienceRequest.Builder builder) { 31 mBuyer = builder.mBuyer; 32 mName = builder.mName; 33 } 34 35 /** 36 * Gets the buyer's {@link AdTechIdentifier}, as identified by a domain in the form 37 * "buyerexample.com". 38 * 39 * @return an {@link AdTechIdentifier} containing the custom audience's buyer's domain 40 */ 41 @NonNull getBuyer()42 public AdTechIdentifier getBuyer() { 43 return mBuyer; 44 } 45 46 /** 47 * Gets the arbitrary string provided by the owner and buyer on creation of the {@link 48 * CustomAudience} object that represents a single custom audience. 49 * 50 * @return the String name of the custom audience 51 */ 52 @NonNull getName()53 public String getName() { 54 return mName; 55 } 56 57 /** 58 * Checks whether two {@link LeaveCustomAudienceRequest} objects contain the same information. 59 */ 60 @Override equals(Object o)61 public boolean equals(Object o) { 62 if (this == o) return true; 63 if (!(o instanceof LeaveCustomAudienceRequest)) return false; 64 LeaveCustomAudienceRequest that = (LeaveCustomAudienceRequest) o; 65 return mBuyer.equals(that.mBuyer) && mName.equals(that.mName); 66 } 67 68 /** 69 * Returns the hash of the {@link LeaveCustomAudienceRequest} object's data. 70 */ 71 @Override hashCode()72 public int hashCode() { 73 return Objects.hash(mBuyer, mName); 74 } 75 76 /** Builder for {@link LeaveCustomAudienceRequest} objects. */ 77 public static final class Builder { 78 @Nullable private AdTechIdentifier mBuyer; 79 @Nullable private String mName; 80 Builder()81 public Builder() {} 82 83 /** 84 * Sets the buyer {@link AdTechIdentifier}. 85 * 86 * <p>See {@link #getBuyer()} for more information. 87 */ 88 @NonNull setBuyer(@onNull AdTechIdentifier buyer)89 public LeaveCustomAudienceRequest.Builder setBuyer(@NonNull AdTechIdentifier buyer) { 90 Objects.requireNonNull(buyer); 91 mBuyer = buyer; 92 return this; 93 } 94 95 /** 96 * Sets the {@link CustomAudience} object's name. 97 * <p> 98 * See {@link #getName()} for more information. 99 */ 100 @NonNull setName(@onNull String name)101 public LeaveCustomAudienceRequest.Builder setName(@NonNull String name) { 102 Objects.requireNonNull(name); 103 mName = name; 104 return this; 105 } 106 107 /** 108 * Builds an instance of a {@link LeaveCustomAudienceRequest}. 109 * 110 * @throws NullPointerException if any non-null parameter is null 111 */ 112 @NonNull build()113 public LeaveCustomAudienceRequest build() { 114 Objects.requireNonNull(mBuyer); 115 Objects.requireNonNull(mName); 116 117 return new LeaveCustomAudienceRequest(this); 118 } 119 } 120 } 121