1 /* 2 * Copyright (C) 2024 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 package com.android.adservices.service.measurement.aggregation; 17 18 import android.annotation.Nullable; 19 20 import com.android.adservices.service.measurement.util.UnsignedLong; 21 22 import java.util.Objects; 23 24 /** POJO for AggregatableKeyValue */ 25 public class AggregatableKeyValue { 26 private final int mValue; 27 private final UnsignedLong mFilteringId; 28 AggregatableKeyValue(AggregatableKeyValue.Builder builder)29 private AggregatableKeyValue(AggregatableKeyValue.Builder builder) { 30 mValue = builder.mValue; 31 mFilteringId = builder.mFilteringId; 32 } 33 34 /** Returns the int value of aggregatable_value's value. */ getValue()35 public int getValue() { 36 return mValue; 37 } 38 39 /** Returns the filtering id. */ 40 @Nullable getFilteringId()41 public UnsignedLong getFilteringId() { 42 return mFilteringId; 43 } 44 45 @Override equals(Object o)46 public boolean equals(Object o) { 47 if (this == o) return true; 48 if (!(o instanceof AggregatableKeyValue)) return false; 49 AggregatableKeyValue that = (AggregatableKeyValue) o; 50 return mValue == that.mValue && Objects.equals(mFilteringId, that.mFilteringId); 51 } 52 53 @Override hashCode()54 public int hashCode() { 55 return Objects.hash(mValue, mFilteringId); 56 } 57 58 public static final class Builder { 59 private int mValue; 60 private UnsignedLong mFilteringId; 61 62 // This will throw JSONException if a JSONObject was previously persisted, and flag 63 // MEASUREMENT_ENABLE_FLEXIBLE_CONTRIBUTION_FILTERING gets set to false. Builder(int value)64 public Builder(int value) { 65 mValue = value; 66 } 67 68 /** {@link AggregatableKeyValue#getFilteringId()} */ setFilteringId(UnsignedLong filteringId)69 public AggregatableKeyValue.Builder setFilteringId(UnsignedLong filteringId) { 70 mFilteringId = filteringId; 71 return this; 72 } 73 74 /** Build the {@link AggregatableKeyValue}. */ build()75 public AggregatableKeyValue build() { 76 return new AggregatableKeyValue(this); 77 } 78 } 79 80 public interface AggregatableKeyValueContract { 81 String VALUE = "value"; 82 String FILTERING_ID = "filtering_id"; 83 } 84 } 85