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 com.android.adservices.service.measurement.aggregation; 18 19 import com.android.adservices.service.measurement.FilterMap; 20 21 import java.math.BigInteger; 22 import java.util.Objects; 23 import java.util.TreeMap; 24 25 /** 26 * POJO for AggregatableAttributionSource. 27 */ 28 public class AggregatableAttributionSource { 29 30 private TreeMap<String, BigInteger> mAggregatableSource; 31 private FilterMap mFilterMap; 32 AggregatableAttributionSource()33 private AggregatableAttributionSource() { 34 mAggregatableSource = new TreeMap<>(); 35 mFilterMap = null; 36 } 37 38 @Override equals(Object obj)39 public boolean equals(Object obj) { 40 if (!(obj instanceof AggregatableAttributionSource)) { 41 return false; 42 } 43 AggregatableAttributionSource attributionSource = (AggregatableAttributionSource) obj; 44 return Objects.equals(mAggregatableSource, attributionSource.mAggregatableSource) 45 && Objects.equals(mFilterMap, attributionSource.mFilterMap); 46 } 47 48 @Override hashCode()49 public int hashCode() { 50 return Objects.hash(mAggregatableSource); 51 } 52 53 /** 54 * Returns aggregatable_source map with key represents the name field in JSON, value represents 55 * the id field in JSON. 56 */ getAggregatableSource()57 public TreeMap<String, BigInteger> getAggregatableSource() { 58 return mAggregatableSource; 59 } 60 61 /** 62 * Returns aggregate filter data which represents a map in JSONObject. 63 */ getFilterMap()64 public FilterMap getFilterMap() { 65 return mFilterMap; 66 } 67 68 /** 69 * Builder for {@link AggregatableAttributionSource}. 70 */ 71 public static final class Builder { 72 private final AggregatableAttributionSource mBuilding; 73 Builder()74 public Builder() { 75 mBuilding = new AggregatableAttributionSource(); 76 } 77 78 /** 79 * See {@link AggregatableAttributionSource#getAggregatableSource()}. 80 */ setAggregatableSource( TreeMap<String, BigInteger> aggregatableSource)81 public Builder setAggregatableSource( 82 TreeMap<String, BigInteger> aggregatableSource) { 83 mBuilding.mAggregatableSource = aggregatableSource; 84 return this; 85 } 86 87 /** 88 * See {@link AggregatableAttributionSource#getFilterMap()}. 89 */ setFilterMap(FilterMap filterMap)90 public Builder setFilterMap(FilterMap filterMap) { 91 mBuilding.mFilterMap = filterMap; 92 return this; 93 } 94 95 /** 96 * Build the {@link AggregatableAttributionSource}. 97 */ build()98 public AggregatableAttributionSource build() { 99 return mBuilding; 100 } 101 } 102 } 103