• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.service.measurement.aggregation;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 
22 import com.android.adservices.service.measurement.FilterMap;
23 import com.android.adservices.service.measurement.util.UnsignedLong;
24 
25 import java.util.List;
26 import java.util.Objects;
27 import java.util.Optional;
28 
29 /** Aggregate Deduplication Key containing de-deup key and filters info. */
30 public class AggregateDeduplicationKey {
31     private Optional<UnsignedLong> mDedupKey;
32     private Optional<List<FilterMap>> mFilterSet;
33 
34     private Optional<List<FilterMap>> mNotFilterSet;
35 
36     /** Create a new aggregate encryption key object. */
AggregateDeduplicationKey()37     private AggregateDeduplicationKey() {
38         mDedupKey = Optional.empty();
39         mFilterSet = Optional.empty();
40         mNotFilterSet = Optional.empty();
41     }
42 
43     @Override
equals(Object obj)44     public boolean equals(Object obj) {
45         if (!(obj instanceof AggregateDeduplicationKey)) {
46             return false;
47         }
48         AggregateDeduplicationKey key = (AggregateDeduplicationKey) obj;
49         return Objects.equals(mDedupKey, key.mDedupKey)
50                 && Objects.equals(mFilterSet, key.mFilterSet)
51                 && Objects.equals(mNotFilterSet, key.mNotFilterSet);
52     }
53 
54     @Override
hashCode()55     public int hashCode() {
56         return Objects.hash(mDedupKey, mFilterSet, mNotFilterSet);
57     }
58 
59     /** Deduplication key to match dedup key with source. */
getDeduplicationKey()60     public Optional<UnsignedLong> getDeduplicationKey() {
61         return mDedupKey;
62     }
63 
64     /** Filters that should match with source's. */
getFilterSet()65     public Optional<List<FilterMap>> getFilterSet() {
66         return mFilterSet;
67     }
68 
69     /** Returns the not_filter, reverse of filter. */
getNotFilterSet()70     public Optional<List<FilterMap>> getNotFilterSet() {
71         return mNotFilterSet;
72     }
73 
74     /** A builder for {@link AggregateDeduplicationKey}. */
75     public static final class Builder {
76         private final AggregateDeduplicationKey mBuilding;
77 
Builder()78         public Builder() {
79             mBuilding = new AggregateDeduplicationKey();
80         }
81         /** See {@link AggregateDeduplicationKey#getFilterSet()}. */
setDeduplicationKey(@onNull UnsignedLong dedupKey)82         public Builder setDeduplicationKey(@NonNull UnsignedLong dedupKey) {
83             mBuilding.mDedupKey = Optional.of(dedupKey);
84             return this;
85         }
86 
87         /** See {@link AggregateDeduplicationKey#getFilterSet()}. */
setFilterSet(@ullable List<FilterMap> filterSet)88         public Builder setFilterSet(@Nullable List<FilterMap> filterSet) {
89             mBuilding.mFilterSet = Optional.of(filterSet);
90             return this;
91         }
92 
93         /** See {@link AggregateDeduplicationKey#getNotFilterSet()} */
setNotFilterSet(List<FilterMap> notFilterSet)94         public Builder setNotFilterSet(List<FilterMap> notFilterSet) {
95             mBuilding.mNotFilterSet = Optional.of(notFilterSet);
96             return this;
97         }
98 
99         /** Build the AggregateDeduplicationKey. */
build()100         public @NonNull AggregateDeduplicationKey build() {
101             return mBuilding;
102         }
103     }
104 }
105