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.ondevicepersonalization.services.data.events;
18 
19 import android.annotation.NonNull;
20 
21 import com.android.ondevicepersonalization.internal.util.AnnotationValidations;
22 import com.android.ondevicepersonalization.internal.util.DataClass;
23 
24 /**
25  * ColumnSchema object representing a SQL column
26  */
27 @DataClass(
28         genBuilder = true,
29         genEqualsHashCode = true
30 )
31 public class ColumnSchema {
32     public static final int SQL_DATA_TYPE_INTEGER = 1;
33     public static final int SQL_DATA_TYPE_REAL = 2;
34     public static final int SQL_DATA_TYPE_TEXT = 3;
35     public static final int SQL_DATA_TYPE_BLOB = 4;
36 
37     /** The name of the column. */
38     @NonNull
39     private final String mName;
40 
41     /** The SQL type of the column. */
42     @SqlDataType
43     private final int mType;
44 
45     @Override
toString()46     public String toString() {
47         String result = mName + " ";
48         switch (mType) {
49             case ColumnSchema.SQL_DATA_TYPE_INTEGER:
50                 result += "INTEGER";
51                 break;
52             case ColumnSchema.SQL_DATA_TYPE_REAL:
53                 result += "REAL";
54                 break;
55             case ColumnSchema.SQL_DATA_TYPE_TEXT:
56                 result += "TEXT";
57                 break;
58             case ColumnSchema.SQL_DATA_TYPE_BLOB:
59             default:
60                 result += "BLOB";
61                 break;
62         }
63         return result;
64     }
65 
66 
67 
68     // Code below generated by codegen v1.0.23.
69     //
70     // DO NOT MODIFY!
71     // CHECKSTYLE:OFF Generated code
72     //
73     // To regenerate run:
74     // $ codegen $ANDROID_BUILD_TOP/packages/modules/OnDevicePersonalization/src/com/android/ondevicepersonalization/services/data/events/ColumnSchema.java
75     //
76     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
77     //   Settings > Editor > Code Style > Formatter Control
78     //@formatter:off
79 
80 
81     @android.annotation.IntDef(prefix = "SQL_DATA_TYPE_", value = {
82         SQL_DATA_TYPE_INTEGER,
83         SQL_DATA_TYPE_REAL,
84         SQL_DATA_TYPE_TEXT,
85         SQL_DATA_TYPE_BLOB
86     })
87     @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
88     @DataClass.Generated.Member
89     public @interface SqlDataType {}
90 
91     @DataClass.Generated.Member
sqlDataTypeToString(@qlDataType int value)92     public static String sqlDataTypeToString(@SqlDataType int value) {
93         switch (value) {
94             case SQL_DATA_TYPE_INTEGER:
95                     return "SQL_DATA_TYPE_INTEGER";
96             case SQL_DATA_TYPE_REAL:
97                     return "SQL_DATA_TYPE_REAL";
98             case SQL_DATA_TYPE_TEXT:
99                     return "SQL_DATA_TYPE_TEXT";
100             case SQL_DATA_TYPE_BLOB:
101                     return "SQL_DATA_TYPE_BLOB";
102             default: return Integer.toHexString(value);
103         }
104     }
105 
106     @DataClass.Generated.Member
ColumnSchema( @onNull String name, @SqlDataType int type)107     /* package-private */ ColumnSchema(
108             @NonNull String name,
109             @SqlDataType int type) {
110         this.mName = name;
111         AnnotationValidations.validate(
112                 NonNull.class, null, mName);
113         this.mType = type;
114 
115         if (!(mType == SQL_DATA_TYPE_INTEGER)
116                 && !(mType == SQL_DATA_TYPE_REAL)
117                 && !(mType == SQL_DATA_TYPE_TEXT)
118                 && !(mType == SQL_DATA_TYPE_BLOB)) {
119             throw new java.lang.IllegalArgumentException(
120                     "type was " + mType + " but must be one of: "
121                             + "SQL_DATA_TYPE_INTEGER(" + SQL_DATA_TYPE_INTEGER + "), "
122                             + "SQL_DATA_TYPE_REAL(" + SQL_DATA_TYPE_REAL + "), "
123                             + "SQL_DATA_TYPE_TEXT(" + SQL_DATA_TYPE_TEXT + "), "
124                             + "SQL_DATA_TYPE_BLOB(" + SQL_DATA_TYPE_BLOB + ")");
125         }
126 
127 
128         // onConstructed(); // You can define this method to get a callback
129     }
130 
131     /**
132      * The name of the column.
133      */
134     @DataClass.Generated.Member
getName()135     public @NonNull String getName() {
136         return mName;
137     }
138 
139     /**
140      * The SQL type of the column.
141      */
142     @DataClass.Generated.Member
getType()143     public @SqlDataType int getType() {
144         return mType;
145     }
146 
147     @Override
148     @DataClass.Generated.Member
equals(@ndroid.annotation.Nullable Object o)149     public boolean equals(@android.annotation.Nullable Object o) {
150         // You can override field equality logic by defining either of the methods like:
151         // boolean fieldNameEquals(ColumnSchema other) { ... }
152         // boolean fieldNameEquals(FieldType otherValue) { ... }
153 
154         if (this == o) return true;
155         if (o == null || getClass() != o.getClass()) return false;
156         @SuppressWarnings("unchecked")
157         ColumnSchema that = (ColumnSchema) o;
158         //noinspection PointlessBooleanExpression
159         return true
160                 && java.util.Objects.equals(mName, that.mName)
161                 && mType == that.mType;
162     }
163 
164     @Override
165     @DataClass.Generated.Member
hashCode()166     public int hashCode() {
167         // You can override field hashCode logic by defining methods like:
168         // int fieldNameHashCode() { ... }
169 
170         int _hash = 1;
171         _hash = 31 * _hash + java.util.Objects.hashCode(mName);
172         _hash = 31 * _hash + mType;
173         return _hash;
174     }
175 
176     /**
177      * A builder for {@link ColumnSchema}
178      */
179     @SuppressWarnings("WeakerAccess")
180     @DataClass.Generated.Member
181     public static class Builder {
182 
183         private @NonNull String mName;
184         private @SqlDataType int mType;
185 
186         private long mBuilderFieldsSet = 0L;
187 
Builder()188         public Builder() {
189         }
190 
191         /**
192          * Creates a new Builder.
193          *
194          * @param name
195          *   The name of the column.
196          * @param type
197          *   The SQL type of the column.
198          */
Builder( @onNull String name, @SqlDataType int type)199         public Builder(
200                 @NonNull String name,
201                 @SqlDataType int type) {
202             mName = name;
203             AnnotationValidations.validate(
204                     NonNull.class, null, mName);
205             mType = type;
206 
207             if (!(mType == SQL_DATA_TYPE_INTEGER)
208                     && !(mType == SQL_DATA_TYPE_REAL)
209                     && !(mType == SQL_DATA_TYPE_TEXT)
210                     && !(mType == SQL_DATA_TYPE_BLOB)) {
211                 throw new java.lang.IllegalArgumentException(
212                         "type was " + mType + " but must be one of: "
213                                 + "SQL_DATA_TYPE_INTEGER(" + SQL_DATA_TYPE_INTEGER + "), "
214                                 + "SQL_DATA_TYPE_REAL(" + SQL_DATA_TYPE_REAL + "), "
215                                 + "SQL_DATA_TYPE_TEXT(" + SQL_DATA_TYPE_TEXT + "), "
216                                 + "SQL_DATA_TYPE_BLOB(" + SQL_DATA_TYPE_BLOB + ")");
217             }
218 
219         }
220 
221         /**
222          * The name of the column.
223          */
224         @DataClass.Generated.Member
setName(@onNull String value)225         public @NonNull Builder setName(@NonNull String value) {
226             checkNotUsed();
227             mBuilderFieldsSet |= 0x1;
228             mName = value;
229             return this;
230         }
231 
232         /**
233          * The SQL type of the column.
234          */
235         @DataClass.Generated.Member
setType(@qlDataType int value)236         public @NonNull Builder setType(@SqlDataType int value) {
237             checkNotUsed();
238             mBuilderFieldsSet |= 0x2;
239             mType = value;
240             return this;
241         }
242 
243         /** Builds the instance. This builder should not be touched after calling this! */
build()244         public @NonNull ColumnSchema build() {
245             checkNotUsed();
246             mBuilderFieldsSet |= 0x4; // Mark builder used
247 
248             ColumnSchema o = new ColumnSchema(
249                     mName,
250                     mType);
251             return o;
252         }
253 
checkNotUsed()254         private void checkNotUsed() {
255             if ((mBuilderFieldsSet & 0x4) != 0) {
256                 throw new IllegalStateException(
257                         "This Builder should not be reused. Use a new Builder instance instead");
258             }
259         }
260     }
261 
262     @DataClass.Generated(
263             time = 1693945130500L,
264             codegenVersion = "1.0.23",
265             sourceFile = "packages/modules/OnDevicePersonalization/src/com/android/ondevicepersonalization/services/data/events/ColumnSchema.java",
266             inputSignatures = "public static final  int SQL_DATA_TYPE_INTEGER\npublic static final  int SQL_DATA_TYPE_REAL\npublic static final  int SQL_DATA_TYPE_TEXT\npublic static final  int SQL_DATA_TYPE_BLOB\nprivate final @android.annotation.NonNull java.lang.String mName\nprivate final @com.android.ondevicepersonalization.services.data.events.ColumnSchema.SqlDataType int mType\nclass ColumnSchema extends java.lang.Object implements []\n@com.android.ondevicepersonalization.internal.util.DataClass(genBuilder=true, genEqualsHashCode=true)")
267     @Deprecated
__metadata()268     private void __metadata() {}
269 
270 
271     //@formatter:on
272     // End of generated code
273 
274 }
275