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.annotation.NonNull; 20 import android.annotation.Nullable; 21 22 import java.util.Objects; 23 24 /** 25 * The request object to join a custom audience. 26 */ 27 public class JoinCustomAudienceRequest { 28 @NonNull 29 private final CustomAudience mCustomAudience; 30 JoinCustomAudienceRequest(@onNull JoinCustomAudienceRequest.Builder builder)31 private JoinCustomAudienceRequest(@NonNull JoinCustomAudienceRequest.Builder builder) { 32 mCustomAudience = builder.mCustomAudience; 33 } 34 35 /** 36 * Returns the custom audience to join. 37 */ 38 @NonNull getCustomAudience()39 public CustomAudience getCustomAudience() { 40 return mCustomAudience; 41 } 42 43 /** 44 * Checks whether two {@link JoinCustomAudienceRequest} objects contain the same information. 45 */ 46 @Override equals(Object o)47 public boolean equals(Object o) { 48 if (this == o) return true; 49 if (!(o instanceof JoinCustomAudienceRequest)) return false; 50 JoinCustomAudienceRequest that = (JoinCustomAudienceRequest) o; 51 return mCustomAudience.equals(that.mCustomAudience); 52 } 53 54 /** 55 * Returns the hash of the {@link JoinCustomAudienceRequest} object's data. 56 */ 57 @Override hashCode()58 public int hashCode() { 59 return Objects.hash(mCustomAudience); 60 } 61 62 /** Builder for {@link JoinCustomAudienceRequest} objects. */ 63 public static final class Builder { 64 @Nullable private CustomAudience mCustomAudience; 65 Builder()66 public Builder() { 67 } 68 69 /** 70 * Sets the custom audience to join. 71 * 72 * <p>See {@link #getCustomAudience()} for more information. 73 */ 74 @NonNull setCustomAudience( @onNull CustomAudience customAudience)75 public JoinCustomAudienceRequest.Builder setCustomAudience( 76 @NonNull CustomAudience customAudience) { 77 Objects.requireNonNull(customAudience); 78 mCustomAudience = customAudience; 79 return this; 80 } 81 82 /** 83 * Builds an instance of a {@link JoinCustomAudienceRequest}. 84 * 85 * @throws NullPointerException if any non-null parameter is null 86 */ 87 @NonNull build()88 public JoinCustomAudienceRequest build() { 89 Objects.requireNonNull(mCustomAudience, "The custom audience has not been provided"); 90 91 return new JoinCustomAudienceRequest(this); 92 } 93 } 94 } 95