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 import android.annotation.Nullable;
21 import android.content.ComponentName;
22 
23 import com.android.ondevicepersonalization.internal.util.AnnotationValidations;
24 import com.android.ondevicepersonalization.internal.util.DataClass;
25 import com.android.ondevicepersonalization.services.data.DbUtils;
26 
27 /**
28  * JoinedRow object representing a single row in the joined Events and queries table
29  */
30 @DataClass(
31         genBuilder = true,
32         genEqualsHashCode = true
33 )
34 public class JoinedEvent {
35     /** The id of the event. */
36     private final long mEventId;
37 
38     /** The id of the query. */
39     private final long mQueryId;
40 
41     /** Index of the associated entry in the request log for this event. */
42     private final int mRowIndex;
43 
44     /** Name of the service that owns this event */
45     @NonNull
46     private final ComponentName mService;
47 
48     /** The service assigned type of the event. */
49     private final int mType;
50 
51     /** Time of the event in milliseconds. */
52     private final long mEventTimeMillis;
53 
54     /** Blob representing the event. */
55     @Nullable
56     private final byte[] mEventData;
57 
58     /** Time of the query in milliseconds. */
59     private final long mQueryTimeMillis;
60 
61     /** Blob representing the query. */
62     @Nullable
63     private final byte[] mQueryData;
64 
65     @NonNull
getServiceName()66     public String getServiceName() {
67         return DbUtils.toTableValue(mService);
68     }
69 
70 
71 
72     // Code below generated by codegen v1.0.23.
73     //
74     // DO NOT MODIFY!
75     // CHECKSTYLE:OFF Generated code
76     //
77     // To regenerate run:
78     // $ codegen $ANDROID_BUILD_TOP/packages/modules/OnDevicePersonalization/src/com/android/ondevicepersonalization/services/data/events/JoinedEvent.java
79     //
80     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
81     //   Settings > Editor > Code Style > Formatter Control
82     //@formatter:off
83 
84 
85     @DataClass.Generated.Member
JoinedEvent( long eventId, long queryId, int rowIndex, @NonNull ComponentName service, int type, long eventTimeMillis, @Nullable byte[] eventData, long queryTimeMillis, @Nullable byte[] queryData)86     /* package-private */ JoinedEvent(
87             long eventId,
88             long queryId,
89             int rowIndex,
90             @NonNull ComponentName service,
91             int type,
92             long eventTimeMillis,
93             @Nullable byte[] eventData,
94             long queryTimeMillis,
95             @Nullable byte[] queryData) {
96         this.mEventId = eventId;
97         this.mQueryId = queryId;
98         this.mRowIndex = rowIndex;
99         this.mService = service;
100         AnnotationValidations.validate(
101                 NonNull.class, null, mService);
102         this.mType = type;
103         this.mEventTimeMillis = eventTimeMillis;
104         this.mEventData = eventData;
105         this.mQueryTimeMillis = queryTimeMillis;
106         this.mQueryData = queryData;
107 
108         // onConstructed(); // You can define this method to get a callback
109     }
110 
111     /**
112      * The id of the event.
113      */
114     @DataClass.Generated.Member
getEventId()115     public long getEventId() {
116         return mEventId;
117     }
118 
119     /**
120      * The id of the query.
121      */
122     @DataClass.Generated.Member
getQueryId()123     public long getQueryId() {
124         return mQueryId;
125     }
126 
127     /**
128      * Index of the associated entry in the request log for this event.
129      */
130     @DataClass.Generated.Member
getRowIndex()131     public int getRowIndex() {
132         return mRowIndex;
133     }
134 
135     /**
136      * Name of the service that owns this event
137      */
138     @DataClass.Generated.Member
getService()139     public @NonNull ComponentName getService() {
140         return mService;
141     }
142 
143     /**
144      * The service assigned type of the event.
145      */
146     @DataClass.Generated.Member
getType()147     public int getType() {
148         return mType;
149     }
150 
151     /**
152      * Time of the event in milliseconds.
153      */
154     @DataClass.Generated.Member
getEventTimeMillis()155     public long getEventTimeMillis() {
156         return mEventTimeMillis;
157     }
158 
159     /**
160      * Blob representing the event.
161      */
162     @DataClass.Generated.Member
getEventData()163     public @Nullable byte[] getEventData() {
164         return mEventData;
165     }
166 
167     /**
168      * Time of the query in milliseconds.
169      */
170     @DataClass.Generated.Member
getQueryTimeMillis()171     public long getQueryTimeMillis() {
172         return mQueryTimeMillis;
173     }
174 
175     /**
176      * Blob representing the query.
177      */
178     @DataClass.Generated.Member
getQueryData()179     public @Nullable byte[] getQueryData() {
180         return mQueryData;
181     }
182 
183     @Override
184     @DataClass.Generated.Member
equals(@ullable Object o)185     public boolean equals(@Nullable Object o) {
186         // You can override field equality logic by defining either of the methods like:
187         // boolean fieldNameEquals(JoinedEvent other) { ... }
188         // boolean fieldNameEquals(FieldType otherValue) { ... }
189 
190         if (this == o) return true;
191         if (o == null || getClass() != o.getClass()) return false;
192         @SuppressWarnings("unchecked")
193         JoinedEvent that = (JoinedEvent) o;
194         //noinspection PointlessBooleanExpression
195         return true
196                 && mEventId == that.mEventId
197                 && mQueryId == that.mQueryId
198                 && mRowIndex == that.mRowIndex
199                 && java.util.Objects.equals(mService, that.mService)
200                 && mType == that.mType
201                 && mEventTimeMillis == that.mEventTimeMillis
202                 && java.util.Arrays.equals(mEventData, that.mEventData)
203                 && mQueryTimeMillis == that.mQueryTimeMillis
204                 && java.util.Arrays.equals(mQueryData, that.mQueryData);
205     }
206 
207     @Override
208     @DataClass.Generated.Member
hashCode()209     public int hashCode() {
210         // You can override field hashCode logic by defining methods like:
211         // int fieldNameHashCode() { ... }
212 
213         int _hash = 1;
214         _hash = 31 * _hash + Long.hashCode(mEventId);
215         _hash = 31 * _hash + Long.hashCode(mQueryId);
216         _hash = 31 * _hash + mRowIndex;
217         _hash = 31 * _hash + java.util.Objects.hashCode(mService);
218         _hash = 31 * _hash + mType;
219         _hash = 31 * _hash + Long.hashCode(mEventTimeMillis);
220         _hash = 31 * _hash + java.util.Arrays.hashCode(mEventData);
221         _hash = 31 * _hash + Long.hashCode(mQueryTimeMillis);
222         _hash = 31 * _hash + java.util.Arrays.hashCode(mQueryData);
223         return _hash;
224     }
225 
226     /**
227      * A builder for {@link JoinedEvent}
228      */
229     @SuppressWarnings("WeakerAccess")
230     @DataClass.Generated.Member
231     public static class Builder {
232 
233         private long mEventId;
234         private long mQueryId;
235         private int mRowIndex;
236         private @NonNull ComponentName mService;
237         private int mType;
238         private long mEventTimeMillis;
239         private @Nullable byte[] mEventData;
240         private long mQueryTimeMillis;
241         private @Nullable byte[] mQueryData;
242 
243         private long mBuilderFieldsSet = 0L;
244 
Builder()245         public Builder() {
246         }
247 
248         /**
249          * Creates a new Builder.
250          *
251          * @param eventId
252          *   The id of the event.
253          * @param queryId
254          *   The id of the query.
255          * @param rowIndex
256          *   Index of the associated entry in the request log for this event.
257          * @param service
258          *   Name of the service that owns this event
259          * @param type
260          *   The service assigned type of the event.
261          * @param eventTimeMillis
262          *   Time of the event in milliseconds.
263          * @param eventData
264          *   Blob representing the event.
265          * @param queryTimeMillis
266          *   Time of the query in milliseconds.
267          * @param queryData
268          *   Blob representing the query.
269          */
Builder( long eventId, long queryId, int rowIndex, @NonNull ComponentName service, int type, long eventTimeMillis, @Nullable byte[] eventData, long queryTimeMillis, @Nullable byte[] queryData)270         public Builder(
271                 long eventId,
272                 long queryId,
273                 int rowIndex,
274                 @NonNull ComponentName service,
275                 int type,
276                 long eventTimeMillis,
277                 @Nullable byte[] eventData,
278                 long queryTimeMillis,
279                 @Nullable byte[] queryData) {
280             mEventId = eventId;
281             mQueryId = queryId;
282             mRowIndex = rowIndex;
283             mService = service;
284             AnnotationValidations.validate(
285                     NonNull.class, null, mService);
286             mType = type;
287             mEventTimeMillis = eventTimeMillis;
288             mEventData = eventData;
289             mQueryTimeMillis = queryTimeMillis;
290             mQueryData = queryData;
291         }
292 
293         /**
294          * The id of the event.
295          */
296         @DataClass.Generated.Member
setEventId(long value)297         public @NonNull Builder setEventId(long value) {
298             checkNotUsed();
299             mBuilderFieldsSet |= 0x1;
300             mEventId = value;
301             return this;
302         }
303 
304         /**
305          * The id of the query.
306          */
307         @DataClass.Generated.Member
setQueryId(long value)308         public @NonNull Builder setQueryId(long value) {
309             checkNotUsed();
310             mBuilderFieldsSet |= 0x2;
311             mQueryId = value;
312             return this;
313         }
314 
315         /**
316          * Index of the associated entry in the request log for this event.
317          */
318         @DataClass.Generated.Member
setRowIndex(int value)319         public @NonNull Builder setRowIndex(int value) {
320             checkNotUsed();
321             mBuilderFieldsSet |= 0x4;
322             mRowIndex = value;
323             return this;
324         }
325 
326         /**
327          * Name of the service that owns this event
328          */
329         @DataClass.Generated.Member
setService(@onNull ComponentName value)330         public @NonNull Builder setService(@NonNull ComponentName value) {
331             checkNotUsed();
332             mBuilderFieldsSet |= 0x8;
333             mService = value;
334             return this;
335         }
336 
337         /**
338          * The service assigned type of the event.
339          */
340         @DataClass.Generated.Member
setType(int value)341         public @NonNull Builder setType(int value) {
342             checkNotUsed();
343             mBuilderFieldsSet |= 0x10;
344             mType = value;
345             return this;
346         }
347 
348         /**
349          * Time of the event in milliseconds.
350          */
351         @DataClass.Generated.Member
setEventTimeMillis(long value)352         public @NonNull Builder setEventTimeMillis(long value) {
353             checkNotUsed();
354             mBuilderFieldsSet |= 0x20;
355             mEventTimeMillis = value;
356             return this;
357         }
358 
359         /**
360          * Blob representing the event.
361          */
362         @DataClass.Generated.Member
setEventData(@onNull byte... value)363         public @NonNull Builder setEventData(@NonNull byte... value) {
364             checkNotUsed();
365             mBuilderFieldsSet |= 0x40;
366             mEventData = value;
367             return this;
368         }
369 
370         /**
371          * Time of the query in milliseconds.
372          */
373         @DataClass.Generated.Member
setQueryTimeMillis(long value)374         public @NonNull Builder setQueryTimeMillis(long value) {
375             checkNotUsed();
376             mBuilderFieldsSet |= 0x80;
377             mQueryTimeMillis = value;
378             return this;
379         }
380 
381         /**
382          * Blob representing the query.
383          */
384         @DataClass.Generated.Member
setQueryData(@onNull byte... value)385         public @NonNull Builder setQueryData(@NonNull byte... value) {
386             checkNotUsed();
387             mBuilderFieldsSet |= 0x100;
388             mQueryData = value;
389             return this;
390         }
391 
392         /** Builds the instance. This builder should not be touched after calling this! */
build()393         public @NonNull JoinedEvent build() {
394             checkNotUsed();
395             mBuilderFieldsSet |= 0x200; // Mark builder used
396 
397             JoinedEvent o = new JoinedEvent(
398                     mEventId,
399                     mQueryId,
400                     mRowIndex,
401                     mService,
402                     mType,
403                     mEventTimeMillis,
404                     mEventData,
405                     mQueryTimeMillis,
406                     mQueryData);
407             return o;
408         }
409 
checkNotUsed()410         private void checkNotUsed() {
411             if ((mBuilderFieldsSet & 0x200) != 0) {
412                 throw new IllegalStateException(
413                         "This Builder should not be reused. Use a new Builder instance instead");
414             }
415         }
416     }
417 
418     @DataClass.Generated(
419             time = 1708722682206L,
420             codegenVersion = "1.0.23",
421             sourceFile = "packages/modules/OnDevicePersonalization/src/com/android/ondevicepersonalization/services/data/events/JoinedEvent.java",
422             inputSignatures = "private final  long mEventId\nprivate final  long mQueryId\nprivate final  int mRowIndex\nprivate final @android.annotation.NonNull android.content.ComponentName mService\nprivate final  int mType\nprivate final  long mEventTimeMillis\nprivate final @android.annotation.Nullable byte[] mEventData\nprivate final  long mQueryTimeMillis\nprivate final @android.annotation.Nullable byte[] mQueryData\npublic @android.annotation.NonNull java.lang.String getServiceName()\nclass JoinedEvent extends java.lang.Object implements []\n@com.android.ondevicepersonalization.internal.util.DataClass(genBuilder=true, genEqualsHashCode=true)")
423     @Deprecated
__metadata()424     private void __metadata() {}
425 
426 
427     //@formatter:on
428     // End of generated code
429 
430 }
431