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 
17 package android.adservices.ondevicepersonalization;
18 
19 import android.annotation.FlaggedApi;
20 import android.annotation.NonNull;
21 
22 import com.android.adservices.ondevicepersonalization.flags.Flags;
23 import com.android.ondevicepersonalization.internal.util.AnnotationValidations;
24 import com.android.ondevicepersonalization.internal.util.DataClass;
25 
26 import java.util.Collections;
27 import java.util.Map;
28 
29 /** The result returned by {@link ModelManager#run}. */
30 @FlaggedApi(Flags.FLAG_ON_DEVICE_PERSONALIZATION_APIS_ENABLED)
31 @DataClass(genBuilder = true, genEqualsHashCode = true)
32 public final class InferenceOutput {
33     /**
34      * A map mapping output indices to multidimensional arrays of output.
35      *
36      * <p>For TFLite, this field is mapped to outputs of runForMultipleInputsOutputs:
37      * https://www.tensorflow.org/lite/api_docs/java/org/tensorflow/lite/InterpreterApi#parameters_9
38      */
39     @NonNull private Map<Integer, Object> mDataOutputs = Collections.emptyMap();
40 
41     // Code below generated by codegen v1.0.23.
42     //
43     // DO NOT MODIFY!
44     // CHECKSTYLE:OFF Generated code
45     //
46     // To regenerate run:
47     // $ codegen
48     // $ANDROID_BUILD_TOP/packages/modules/OnDevicePersonalization/framework/java/android/adservices/ondevicepersonalization/InferenceOutput.java
49     //
50     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
51     //   Settings > Editor > Code Style > Formatter Control
52     // @formatter:off
53 
54     @DataClass.Generated.Member
InferenceOutput(@onNull Map<Integer, Object> dataOutputs)55     /* package-private */ InferenceOutput(@NonNull Map<Integer, Object> dataOutputs) {
56         this.mDataOutputs = dataOutputs;
57         AnnotationValidations.validate(NonNull.class, null, mDataOutputs);
58 
59         // onConstructed(); // You can define this method to get a callback
60     }
61 
62     /**
63      * A map mapping output indices to multidimensional arrays of output.
64      *
65      * <p>For TFLite, this field is mapped to outputs of runForMultipleInputsOutputs:
66      * https://www.tensorflow.org/lite/api_docs/java/org/tensorflow/lite/InterpreterApi#parameters_9
67      */
68     @DataClass.Generated.Member
getDataOutputs()69     public @NonNull Map<Integer, Object> getDataOutputs() {
70         return mDataOutputs;
71     }
72 
73     @Override
74     @DataClass.Generated.Member
equals(@ndroid.annotation.Nullable Object o)75     public boolean equals(@android.annotation.Nullable Object o) {
76         // You can override field equality logic by defining either of the methods like:
77         // boolean fieldNameEquals(InferenceOutput other) { ... }
78         // boolean fieldNameEquals(FieldType otherValue) { ... }
79 
80         if (this == o) return true;
81         if (o == null || getClass() != o.getClass()) return false;
82         @SuppressWarnings("unchecked")
83         InferenceOutput that = (InferenceOutput) o;
84         //noinspection PointlessBooleanExpression
85         return true && java.util.Objects.equals(mDataOutputs, that.mDataOutputs);
86     }
87 
88     @Override
89     @DataClass.Generated.Member
hashCode()90     public int hashCode() {
91         // You can override field hashCode logic by defining methods like:
92         // int fieldNameHashCode() { ... }
93 
94         int _hash = 1;
95         _hash = 31 * _hash + java.util.Objects.hashCode(mDataOutputs);
96         return _hash;
97     }
98 
99     /** A builder for {@link InferenceOutput} */
100     @SuppressWarnings("WeakerAccess")
101     @DataClass.Generated.Member
102     public static final class Builder {
103 
104         private @NonNull Map<Integer, Object> mDataOutputs;
105 
106         private long mBuilderFieldsSet = 0L;
107 
Builder()108         public Builder() {}
109 
110         /**
111          * A map mapping output indices to multidimensional arrays of output.
112          *
113          * <p>For TFLite, this field is mapped to outputs of runForMultipleInputsOutputs:
114          * https://www.tensorflow.org/lite/api_docs/java/org/tensorflow/lite/InterpreterApi#parameters_9
115          */
116         @DataClass.Generated.Member
setDataOutputs(@onNull Map<Integer, Object> value)117         public @NonNull Builder setDataOutputs(@NonNull Map<Integer, Object> value) {
118             checkNotUsed();
119             mBuilderFieldsSet |= 0x1;
120             mDataOutputs = value;
121             return this;
122         }
123 
124         /**
125          * @see #setDataOutputs
126          */
127         @DataClass.Generated.Member
addDataOutput(int key, @NonNull Object value)128         public @NonNull Builder addDataOutput(int key, @NonNull Object value) {
129             // You can refine this method's name by providing item's singular name, e.g.:
130             // @DataClass.PluralOf("item")) mItems = ...
131 
132             if (mDataOutputs == null) setDataOutputs(new java.util.LinkedHashMap());
133             mDataOutputs.put(key, value);
134             return this;
135         }
136 
137         /** Builds the instance. This builder should not be touched after calling this! */
build()138         public @NonNull InferenceOutput build() {
139             checkNotUsed();
140             mBuilderFieldsSet |= 0x2; // Mark builder used
141 
142             if ((mBuilderFieldsSet & 0x1) == 0) {
143                 mDataOutputs = Collections.emptyMap();
144             }
145             InferenceOutput o = new InferenceOutput(mDataOutputs);
146             return o;
147         }
148 
checkNotUsed()149         private void checkNotUsed() {
150             if ((mBuilderFieldsSet & 0x2) != 0) {
151                 throw new IllegalStateException(
152                         "This Builder should not be reused. Use a new Builder instance instead");
153             }
154         }
155     }
156 
157     @DataClass.Generated(
158             time = 1707187954917L,
159             codegenVersion = "1.0.23",
160             sourceFile =
161                     "packages/modules/OnDevicePersonalization/framework/java/android/adservices/ondevicepersonalization/InferenceOutput.java",
162             inputSignatures =
163                     "private @android.annotation.NonNull java.util.Map<java.lang.Integer,java.lang.Object> mDataOutputs\nclass InferenceOutput extends java.lang.Object implements []\n@com.android.ondevicepersonalization.internal.util.DataClass(genBuilder=true, genEqualsHashCode=true)")
164     @Deprecated
__metadata()165     private void __metadata() {}
166 
167     // @formatter:on
168     // End of generated code
169 
170 }
171