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.topics.classifier; 18 19 import android.annotation.NonNull; 20 21 import com.google.common.collect.ImmutableList; 22 23 import java.util.List; 24 import java.util.Objects; 25 26 /** POJO Represents a ClassifierInputConfig. */ 27 public class ClassifierInputConfig { 28 private final String mInputFormat; 29 30 private final List<ClassifierInputField> mInputFields; 31 ClassifierInputConfig( @onNull String inputFormat, @NonNull List<ClassifierInputField> inputFields)32 ClassifierInputConfig( 33 @NonNull String inputFormat, @NonNull List<ClassifierInputField> inputFields) { 34 Objects.requireNonNull(inputFormat); 35 Objects.requireNonNull(inputFields); 36 mInputFormat = inputFormat; 37 mInputFields = inputFields; 38 } 39 40 /** Enum representing the possible input fields for the classifier. */ 41 public enum ClassifierInputField { 42 PACKAGE_NAME, 43 SPLIT_PACKAGE_NAME, 44 APP_NAME, 45 APP_DESCRIPTION; 46 } 47 48 @Override equals(Object object)49 public boolean equals(Object object) { 50 if (this == object) { 51 return true; 52 } 53 if (!(object instanceof ClassifierInputConfig)) { 54 return false; 55 } 56 ClassifierInputConfig classifierInputConfig = (ClassifierInputConfig) object; 57 return mInputFormat.equals(classifierInputConfig.mInputFormat) 58 && mInputFields.equals(classifierInputConfig.mInputFields); 59 } 60 61 @Override hashCode()62 public int hashCode() { 63 return Objects.hash(super.hashCode(), mInputFormat, mInputFields); 64 } 65 66 /** @return The input format. */ 67 @NonNull getInputFormat()68 public String getInputFormat() { 69 return mInputFormat; 70 } 71 72 /** @return The input fields. */ 73 @NonNull getInputFields()74 public List<ClassifierInputField> getInputFields() { 75 return mInputFields; 76 } 77 78 /** 79 * Util method to get an empty config. 80 * 81 * @return A config with empty input format and input fields. 82 */ getEmptyConfig()83 public static ClassifierInputConfig getEmptyConfig() { 84 return new ClassifierInputConfig("", ImmutableList.of()); 85 } 86 } 87