1 /*
2  * Copyright 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 androidx.appsearch.safeparcel;
18 
19 import android.os.Parcel;
20 import android.os.Parcelable;
21 
22 import androidx.annotation.RestrictTo;
23 import androidx.appsearch.app.AppSearchBlobHandle;
24 import androidx.appsearch.app.AppSearchSchema;
25 import androidx.appsearch.app.AppSearchSchema.PropertyConfig.Cardinality;
26 import androidx.appsearch.app.AppSearchSchema.PropertyConfig.DataType;
27 import androidx.appsearch.app.AppSearchSchema.StringPropertyConfig.DeletePropagationType;
28 import androidx.appsearch.app.AppSearchSchema.StringPropertyConfig.JoinableValueType;
29 import androidx.appsearch.app.AppSearchSchema.StringPropertyConfig.TokenizerType;
30 import androidx.appsearch.app.ExperimentalAppSearchApi;
31 import androidx.appsearch.safeparcel.stub.StubCreators.DocumentIndexingConfigParcelCreator;
32 import androidx.appsearch.safeparcel.stub.StubCreators.EmbeddingIndexingConfigParcelCreator;
33 import androidx.appsearch.safeparcel.stub.StubCreators.IntegerIndexingConfigParcelCreator;
34 import androidx.appsearch.safeparcel.stub.StubCreators.JoinableConfigParcelCreator;
35 import androidx.appsearch.safeparcel.stub.StubCreators.PropertyConfigParcelCreator;
36 import androidx.appsearch.safeparcel.stub.StubCreators.StringIndexingConfigParcelCreator;
37 import androidx.core.util.ObjectsCompat;
38 
39 import org.jspecify.annotations.NonNull;
40 import org.jspecify.annotations.Nullable;
41 
42 import java.util.List;
43 import java.util.Objects;
44 
45 /**
46  * Class to hold property configuration for one property defined in {@link AppSearchSchema}.
47  *
48  * <p>It is defined as same as PropertyConfigProto for the native code to handle different property
49  * types in one class.
50  *
51  * <p>Currently it can handle String, long, double, boolean, bytes and document type.
52  *
53  * @exportToFramework:hide
54  */
55 @RestrictTo(RestrictTo.Scope.LIBRARY)
56 @SafeParcelable.Class(creator = "PropertyConfigParcelCreator")
57 public final class PropertyConfigParcel extends AbstractSafeParcelable {
58     public static final Parcelable.@NonNull Creator<PropertyConfigParcel> CREATOR =
59             new PropertyConfigParcelCreator();
60 
61     @Field(id = 1, getter = "getName")
62     private final String mName;
63 
64     @AppSearchSchema.PropertyConfig.DataType
65     @Field(id = 2, getter = "getDataType")
66     private final int mDataType;
67 
68     @AppSearchSchema.PropertyConfig.Cardinality
69     @Field(id = 3, getter = "getCardinality")
70     private final int mCardinality;
71 
72     @Field(id = 4, getter = "getSchemaType")
73     private final @Nullable String mSchemaType;
74 
75     @Field(id = 5, getter = "getStringIndexingConfigParcel")
76     private final @Nullable StringIndexingConfigParcel mStringIndexingConfigParcel;
77 
78     @Field(id = 6, getter = "getDocumentIndexingConfigParcel")
79     private final @Nullable DocumentIndexingConfigParcel mDocumentIndexingConfigParcel;
80 
81     @Field(id = 7, getter = "getIntegerIndexingConfigParcel")
82     private final @Nullable IntegerIndexingConfigParcel mIntegerIndexingConfigParcel;
83 
84     @Field(id = 8, getter = "getJoinableConfigParcel")
85     private final @Nullable JoinableConfigParcel mJoinableConfigParcel;
86 
87     @Field(id = 9, getter = "getDescription")
88     private final String mDescription;
89 
90     @Field(id = 10, getter = "getEmbeddingIndexingConfigParcel")
91     private final EmbeddingIndexingConfigParcel mEmbeddingIndexingConfigParcel;
92 
93     @Field(id = 11, getter = "isScoringEnabled")
94     private final boolean mScoringEnabled;
95 
96     private @Nullable Integer mHashCode;
97 
98     /** Constructor for {@link PropertyConfigParcel}. */
99     @Constructor
PropertyConfigParcel( @aramid = 1) @onNull String name, @Param(id = 2) @DataType int dataType, @Param(id = 3) @Cardinality int cardinality, @Param(id = 4) @Nullable String schemaType, @Param(id = 5) @Nullable StringIndexingConfigParcel stringIndexingConfigParcel, @Param(id = 6) @Nullable DocumentIndexingConfigParcel documentIndexingConfigParcel, @Param(id = 7) @Nullable IntegerIndexingConfigParcel integerIndexingConfigParcel, @Param(id = 8) @Nullable JoinableConfigParcel joinableConfigParcel, @Param(id = 9) @NonNull String description, @Param(id = 10) @Nullable EmbeddingIndexingConfigParcel embeddingIndexingConfigParcel, @Param(id = 11) boolean scoringEnabled)100     PropertyConfigParcel(
101             @Param(id = 1) @NonNull String name,
102             @Param(id = 2) @DataType int dataType,
103             @Param(id = 3) @Cardinality int cardinality,
104             @Param(id = 4) @Nullable String schemaType,
105             @Param(id = 5) @Nullable StringIndexingConfigParcel stringIndexingConfigParcel,
106             @Param(id = 6) @Nullable DocumentIndexingConfigParcel documentIndexingConfigParcel,
107             @Param(id = 7) @Nullable IntegerIndexingConfigParcel integerIndexingConfigParcel,
108             @Param(id = 8) @Nullable JoinableConfigParcel joinableConfigParcel,
109             @Param(id = 9) @NonNull String description,
110             @Param(id = 10) @Nullable EmbeddingIndexingConfigParcel embeddingIndexingConfigParcel,
111             @Param(id = 11) boolean scoringEnabled) {
112         mName = Objects.requireNonNull(name);
113         mDataType = dataType;
114         mCardinality = cardinality;
115         mSchemaType = schemaType;
116         mStringIndexingConfigParcel = stringIndexingConfigParcel;
117         mDocumentIndexingConfigParcel = documentIndexingConfigParcel;
118         mIntegerIndexingConfigParcel = integerIndexingConfigParcel;
119         mJoinableConfigParcel = joinableConfigParcel;
120         mDescription = Objects.requireNonNull(description);
121         mEmbeddingIndexingConfigParcel = embeddingIndexingConfigParcel;
122         mScoringEnabled = scoringEnabled;
123     }
124 
125     /** Creates a {@link PropertyConfigParcel} for String. */
createForString( @onNull String propertyName, @NonNull String description, @Cardinality int cardinality, @NonNull StringIndexingConfigParcel stringIndexingConfigParcel, @NonNull JoinableConfigParcel joinableConfigParcel)126     public static @NonNull PropertyConfigParcel createForString(
127             @NonNull String propertyName,
128             @NonNull String description,
129             @Cardinality int cardinality,
130             @NonNull StringIndexingConfigParcel stringIndexingConfigParcel,
131             @NonNull JoinableConfigParcel joinableConfigParcel) {
132         return new PropertyConfigParcel(
133                 Objects.requireNonNull(propertyName),
134                 AppSearchSchema.PropertyConfig.DATA_TYPE_STRING,
135                 cardinality,
136                 /*schemaType=*/ null,
137                 Objects.requireNonNull(stringIndexingConfigParcel),
138                 /*documentIndexingConfigParcel=*/ null,
139                 /*integerIndexingConfigParcel=*/ null,
140                 Objects.requireNonNull(joinableConfigParcel),
141                 Objects.requireNonNull(description),
142                 /*embeddingIndexingConfigParcel=*/ null,
143                 /*scoringEnabled=*/false);
144     }
145 
146     /** Creates a {@link PropertyConfigParcel} for Long. */
createForLong( @onNull String propertyName, @NonNull String description, @Cardinality int cardinality, @AppSearchSchema.LongPropertyConfig.IndexingType int indexingType, boolean scoringEnabled)147     public static @NonNull PropertyConfigParcel createForLong(
148             @NonNull String propertyName,
149             @NonNull String description,
150             @Cardinality int cardinality,
151             @AppSearchSchema.LongPropertyConfig.IndexingType int indexingType,
152             boolean scoringEnabled) {
153         return new PropertyConfigParcel(
154                 Objects.requireNonNull(propertyName),
155                 AppSearchSchema.PropertyConfig.DATA_TYPE_LONG,
156                 cardinality,
157                 /*schemaType=*/ null,
158                 /*stringIndexingConfigParcel=*/ null,
159                 /*documentIndexingConfigParcel=*/ null,
160                 new IntegerIndexingConfigParcel(indexingType),
161                 /*joinableConfigParcel=*/ null,
162                 Objects.requireNonNull(description),
163                 /*embeddingIndexingConfigParcel=*/ null,
164                 scoringEnabled);
165     }
166 
167     /** Creates a {@link PropertyConfigParcel} for Double. */
createForDouble( @onNull String propertyName, @NonNull String description, @Cardinality int cardinality, boolean scoringEnabled)168     public static @NonNull PropertyConfigParcel createForDouble(
169             @NonNull String propertyName,
170             @NonNull String description,
171             @Cardinality int cardinality,
172             boolean scoringEnabled) {
173         return new PropertyConfigParcel(
174                 Objects.requireNonNull(propertyName),
175                 AppSearchSchema.PropertyConfig.DATA_TYPE_DOUBLE,
176                 cardinality,
177                 /*schemaType=*/ null,
178                 /*stringIndexingConfigParcel=*/ null,
179                 /*documentIndexingConfigParcel=*/ null,
180                 /*integerIndexingConfigParcel=*/ null,
181                 /*joinableConfigParcel=*/ null,
182                 Objects.requireNonNull(description),
183                 /*embeddingIndexingConfigParcel=*/ null,
184                 scoringEnabled);
185     }
186 
187     /** Creates a {@link PropertyConfigParcel} for Boolean. */
createForBoolean( @onNull String propertyName, @NonNull String description, @Cardinality int cardinality, boolean scoringEnabled)188     public static @NonNull PropertyConfigParcel createForBoolean(
189             @NonNull String propertyName,
190             @NonNull String description,
191             @Cardinality int cardinality,
192             boolean scoringEnabled) {
193         return new PropertyConfigParcel(
194                 Objects.requireNonNull(propertyName),
195                 AppSearchSchema.PropertyConfig.DATA_TYPE_BOOLEAN,
196                 cardinality,
197                 /*schemaType=*/ null,
198                 /*stringIndexingConfigParcel=*/ null,
199                 /*documentIndexingConfigParcel=*/ null,
200                 /*integerIndexingConfigParcel=*/ null,
201                 /*joinableConfigParcel=*/ null,
202                 Objects.requireNonNull(description),
203                 /*embeddingIndexingConfigParcel=*/ null,
204                 scoringEnabled);
205     }
206 
207     /** Creates a {@link PropertyConfigParcel} for Bytes. */
createForBytes( @onNull String propertyName, @NonNull String description, @Cardinality int cardinality)208     public static @NonNull PropertyConfigParcel createForBytes(
209             @NonNull String propertyName,
210             @NonNull String description,
211             @Cardinality int cardinality) {
212         return new PropertyConfigParcel(
213                 Objects.requireNonNull(propertyName),
214                 AppSearchSchema.PropertyConfig.DATA_TYPE_BYTES,
215                 cardinality,
216                 /*schemaType=*/ null,
217                 /*stringIndexingConfigParcel=*/ null,
218                 /*documentIndexingConfigParcel=*/ null,
219                 /*integerIndexingConfigParcel=*/ null,
220                 /*joinableConfigParcel=*/ null,
221                 Objects.requireNonNull(description),
222                 /*embeddingIndexingConfigParcel=*/ null,
223                 /*scoringEnabled=*/false);
224     }
225 
226     /** Creates a {@link PropertyConfigParcel} for Document. */
createForDocument( @onNull String propertyName, @NonNull String description, @Cardinality int cardinality, @NonNull String schemaType, @NonNull DocumentIndexingConfigParcel documentIndexingConfigParcel)227     public static @NonNull PropertyConfigParcel createForDocument(
228             @NonNull String propertyName,
229             @NonNull String description,
230             @Cardinality int cardinality,
231             @NonNull String schemaType,
232             @NonNull DocumentIndexingConfigParcel documentIndexingConfigParcel) {
233         return new PropertyConfigParcel(
234                 Objects.requireNonNull(propertyName),
235                 AppSearchSchema.PropertyConfig.DATA_TYPE_DOCUMENT,
236                 cardinality,
237                 Objects.requireNonNull(schemaType),
238                 /*stringIndexingConfigParcel=*/ null,
239                 Objects.requireNonNull(documentIndexingConfigParcel),
240                 /*integerIndexingConfigParcel=*/ null,
241                 /*joinableConfigParcel=*/ null,
242                 Objects.requireNonNull(description),
243                 /*embeddingIndexingConfigParcel=*/ null,
244                 /*scoringEnabled=*/false);
245     }
246 
247     /** Creates a {@link PropertyConfigParcel} for Embedding. */
createForEmbedding( @onNull String propertyName, @NonNull String description, @Cardinality int cardinality, @AppSearchSchema.EmbeddingPropertyConfig.IndexingType int indexingType, @AppSearchSchema.EmbeddingPropertyConfig.QuantizationType int quantizationType)248     public static @NonNull PropertyConfigParcel createForEmbedding(
249             @NonNull String propertyName,
250             @NonNull String description,
251             @Cardinality int cardinality,
252             @AppSearchSchema.EmbeddingPropertyConfig.IndexingType int indexingType,
253             @AppSearchSchema.EmbeddingPropertyConfig.QuantizationType int quantizationType) {
254         return new PropertyConfigParcel(
255                 Objects.requireNonNull(propertyName),
256                 AppSearchSchema.PropertyConfig.DATA_TYPE_EMBEDDING,
257                 cardinality,
258                 /*schemaType=*/ null,
259                 /*stringIndexingConfigParcel=*/ null,
260                 /*documentIndexingConfigParcel=*/ null,
261                 /*integerIndexingConfigParcel=*/ null,
262                 /*joinableConfigParcel=*/ null,
263                 Objects.requireNonNull(description),
264                 new EmbeddingIndexingConfigParcel(indexingType, quantizationType),
265                 /*scoringEnabled=*/false);
266     }
267 
268     /** Creates a {@link PropertyConfigParcel} for {@link AppSearchBlobHandle}. */
269     @ExperimentalAppSearchApi
createForBlobHandle( @onNull String propertyName, @NonNull String description, @Cardinality int cardinality)270     public static @NonNull PropertyConfigParcel createForBlobHandle(
271             @NonNull String propertyName,
272             @NonNull String description,
273             @Cardinality int cardinality) {
274         return new PropertyConfigParcel(
275                 Objects.requireNonNull(propertyName),
276                 AppSearchSchema.PropertyConfig.DATA_TYPE_BLOB_HANDLE,
277                 cardinality,
278                 /*schemaType=*/ null,
279                 /*stringIndexingConfigParcel=*/ null,
280                 /*documentIndexingConfigParcel=*/ null,
281                 /*integerIndexingConfigParcel=*/ null,
282                 /*joinableConfigParcel=*/ null,
283                 Objects.requireNonNull(description),
284                 /*embeddingIndexingConfigParcel=*/ null,
285                 /*scoringEnabled=*/false);
286     }
287 
288     /** Gets name for the property. */
getName()289     public @NonNull String getName() {
290         return mName;
291     }
292 
293     /** Gets description for the property. */
getDescription()294     public @NonNull String getDescription() {
295         return mDescription;
296     }
297 
298     /** Gets data type for the property. */
299     @DataType
getDataType()300     public int getDataType() {
301         return mDataType;
302     }
303 
304     /** Gets cardinality for the property. */
305     @Cardinality
getCardinality()306     public int getCardinality() {
307         return mCardinality;
308     }
309 
310     /** Gets schema type. */
getSchemaType()311     public @Nullable String getSchemaType() {
312         return mSchemaType;
313     }
314 
315     /** Gets the {@link StringIndexingConfigParcel}. */
getStringIndexingConfigParcel()316     public @Nullable StringIndexingConfigParcel getStringIndexingConfigParcel() {
317         return mStringIndexingConfigParcel;
318     }
319 
320     /** Gets the {@link DocumentIndexingConfigParcel}. */
getDocumentIndexingConfigParcel()321     public @Nullable DocumentIndexingConfigParcel getDocumentIndexingConfigParcel() {
322         return mDocumentIndexingConfigParcel;
323     }
324 
325     /** Gets the {@link IntegerIndexingConfigParcel}. */
getIntegerIndexingConfigParcel()326     public @Nullable IntegerIndexingConfigParcel getIntegerIndexingConfigParcel() {
327         return mIntegerIndexingConfigParcel;
328     }
329 
330     /** Gets the {@link JoinableConfigParcel}. */
getJoinableConfigParcel()331     public @Nullable JoinableConfigParcel getJoinableConfigParcel() {
332         return mJoinableConfigParcel;
333     }
334 
335     /** Gets the {@link EmbeddingIndexingConfigParcel}. */
getEmbeddingIndexingConfigParcel()336     public @Nullable EmbeddingIndexingConfigParcel getEmbeddingIndexingConfigParcel() {
337         return mEmbeddingIndexingConfigParcel;
338     }
339 
340     /** Gets ScorableType for the property. */
isScoringEnabled()341     public boolean isScoringEnabled() {
342         return mScoringEnabled;
343     }
344 
345     @Override
writeToParcel(@onNull Parcel dest, int flags)346     public void writeToParcel(@NonNull Parcel dest, int flags) {
347         PropertyConfigParcelCreator.writeToParcel(this, dest, flags);
348     }
349 
350     @Override
equals(@ullable Object other)351     public boolean equals(@Nullable Object other) {
352         if (this == other) {
353             return true;
354         }
355         if (!(other instanceof PropertyConfigParcel)) {
356             return false;
357         }
358         PropertyConfigParcel otherProperty = (PropertyConfigParcel) other;
359         return ObjectsCompat.equals(mName, otherProperty.mName)
360                 && Objects.equals(mDescription, otherProperty.mDescription)
361                 && ObjectsCompat.equals(mDataType, otherProperty.mDataType)
362                 && ObjectsCompat.equals(mCardinality, otherProperty.mCardinality)
363                 && ObjectsCompat.equals(mSchemaType, otherProperty.mSchemaType)
364                 && ObjectsCompat.equals(
365                 mStringIndexingConfigParcel, otherProperty.mStringIndexingConfigParcel)
366                 && ObjectsCompat.equals(
367                 mDocumentIndexingConfigParcel, otherProperty.mDocumentIndexingConfigParcel)
368                 && ObjectsCompat.equals(
369                 mIntegerIndexingConfigParcel, otherProperty.mIntegerIndexingConfigParcel)
370                 && ObjectsCompat.equals(
371                 mJoinableConfigParcel, otherProperty.mJoinableConfigParcel)
372                 && ObjectsCompat.equals(
373                 mEmbeddingIndexingConfigParcel, otherProperty.mEmbeddingIndexingConfigParcel)
374                 && mScoringEnabled == otherProperty.mScoringEnabled;
375     }
376 
377     @Override
hashCode()378     public int hashCode() {
379         if (mHashCode == null) {
380             mHashCode =
381                 ObjectsCompat.hash(
382                         mName,
383                         mDescription,
384                         mDataType,
385                         mCardinality,
386                         mSchemaType,
387                         mStringIndexingConfigParcel,
388                         mDocumentIndexingConfigParcel,
389                         mIntegerIndexingConfigParcel,
390                         mJoinableConfigParcel,
391                         mEmbeddingIndexingConfigParcel,
392                         mScoringEnabled);
393         }
394         return mHashCode;
395     }
396 
397     @Override
toString()398     public @NonNull String toString() {
399         return "{name: " + mName
400                 + ", description: " + mDescription
401                 + ", dataType: " + mDataType
402                 + ", cardinality: " + mCardinality
403                 + ", schemaType: " + mSchemaType
404                 + ", stringIndexingConfigParcel: " + mStringIndexingConfigParcel
405                 + ", documentIndexingConfigParcel: " + mDocumentIndexingConfigParcel
406                 + ", integerIndexingConfigParcel: " + mIntegerIndexingConfigParcel
407                 + ", joinableConfigParcel: " + mJoinableConfigParcel
408                 + ", embeddingIndexingConfigParcel: " + mEmbeddingIndexingConfigParcel
409                 + ", isScoringEnabled: " + mScoringEnabled
410                 + "}";
411     }
412 
413     /** Class to hold join configuration for a String type. */
414     @SafeParcelable.Class(creator = "JoinableConfigParcelCreator")
415     public static class JoinableConfigParcel extends AbstractSafeParcelable {
416         public static final Parcelable.@NonNull Creator<JoinableConfigParcel> CREATOR =
417                 new JoinableConfigParcelCreator();
418 
419         @JoinableValueType
420         @Field(id = 1, getter = "getJoinableValueType")
421         private final int mJoinableValueType;
422 
423         @Field(id = 3, getter = "getDeletePropagationType")
424         private final int mDeletePropagationType;
425 
426         /** Constructor for {@link JoinableConfigParcel}. */
427         @Constructor
JoinableConfigParcel( @aramid = 1) @oinableValueType int joinableValueType, @Param(id = 3) @DeletePropagationType int deletePropagationType)428         public JoinableConfigParcel(
429                 @Param(id = 1) @JoinableValueType int joinableValueType,
430                 @Param(id = 3) @DeletePropagationType int deletePropagationType) {
431             mJoinableValueType = joinableValueType;
432             mDeletePropagationType = deletePropagationType;
433         }
434 
435         /** Gets {@link JoinableValueType} of the join. */
436         @JoinableValueType
getJoinableValueType()437         public int getJoinableValueType() {
438             return mJoinableValueType;
439         }
440 
441         /** Gets {@link DeletePropagationType} of the join. */
442         @DeletePropagationType
getDeletePropagationType()443         public int getDeletePropagationType() {
444             return mDeletePropagationType;
445         }
446 
447         @Override
writeToParcel(@onNull Parcel dest, int flags)448         public void writeToParcel(@NonNull Parcel dest, int flags) {
449             JoinableConfigParcelCreator.writeToParcel(this, dest, flags);
450         }
451 
452         @Override
hashCode()453         public int hashCode() {
454             return ObjectsCompat.hash(mJoinableValueType, mDeletePropagationType);
455         }
456 
457         @Override
equals(@ullable Object other)458         public boolean equals(@Nullable Object other) {
459             if (this == other) {
460                 return true;
461             }
462             if (!(other instanceof JoinableConfigParcel)) {
463                 return false;
464             }
465             JoinableConfigParcel otherObject = (JoinableConfigParcel) other;
466             return ObjectsCompat.equals(mJoinableValueType, otherObject.mJoinableValueType)
467                     && mDeletePropagationType == otherObject.mDeletePropagationType;
468         }
469 
470         @Override
toString()471         public @NonNull String toString() {
472             return "{joinableValueType: " + mJoinableValueType
473                     + ", deletePropagationType: " + mDeletePropagationType + "}";
474         }
475     }
476 
477     /** Class to hold configuration a string type. */
478     @SafeParcelable.Class(creator = "StringIndexingConfigParcelCreator")
479     public static class StringIndexingConfigParcel extends AbstractSafeParcelable {
480         public static final Parcelable.@NonNull Creator<StringIndexingConfigParcel> CREATOR =
481                 new StringIndexingConfigParcelCreator();
482 
483         @AppSearchSchema.StringPropertyConfig.IndexingType
484         @Field(id = 1, getter = "getIndexingType")
485         private final int mIndexingType;
486 
487         @TokenizerType
488         @Field(id = 2, getter = "getTokenizerType")
489         private final int mTokenizerType;
490 
491         /** Constructor for {@link StringIndexingConfigParcel}. */
492         @Constructor
StringIndexingConfigParcel( @aramid = 1) @ppSearchSchema.StringPropertyConfig.IndexingType int indexingType, @Param(id = 2) @TokenizerType int tokenizerType)493         public StringIndexingConfigParcel(
494                 @Param(id = 1) @AppSearchSchema.StringPropertyConfig.IndexingType int indexingType,
495                 @Param(id = 2) @TokenizerType int tokenizerType) {
496             mIndexingType = indexingType;
497             mTokenizerType = tokenizerType;
498         }
499 
500         /** Gets the indexing type for this property. */
501         @AppSearchSchema.StringPropertyConfig.IndexingType
getIndexingType()502         public int getIndexingType() {
503             return mIndexingType;
504         }
505 
506         /** Gets the tokenization type for this property. */
507         @TokenizerType
getTokenizerType()508         public int getTokenizerType() {
509             return mTokenizerType;
510         }
511 
512         @Override
writeToParcel(@onNull Parcel dest, int flags)513         public void writeToParcel(@NonNull Parcel dest, int flags) {
514             StringIndexingConfigParcelCreator.writeToParcel(this, dest, flags);
515         }
516 
517         @Override
hashCode()518         public int hashCode() {
519             return ObjectsCompat.hash(mIndexingType, mTokenizerType);
520         }
521 
522         @Override
equals(@ullable Object other)523         public boolean equals(@Nullable Object other) {
524             if (this == other) {
525                 return true;
526             }
527             if (!(other instanceof StringIndexingConfigParcel)) {
528                 return false;
529             }
530             StringIndexingConfigParcel otherObject = (StringIndexingConfigParcel) other;
531             return mIndexingType == otherObject.mIndexingType
532                     && ObjectsCompat.equals(mTokenizerType, otherObject.mTokenizerType);
533         }
534 
535         @Override
toString()536         public @NonNull String toString() {
537             return "{indexingType: " + mIndexingType
538                     + ", tokenizerType: " + mTokenizerType + "}";
539         }
540     }
541 
542     /** Class to hold configuration for integer property type. */
543     @SafeParcelable.Class(creator = "IntegerIndexingConfigParcelCreator")
544     public static class IntegerIndexingConfigParcel extends AbstractSafeParcelable {
545         public static final Parcelable.@NonNull Creator<IntegerIndexingConfigParcel> CREATOR =
546                 new IntegerIndexingConfigParcelCreator();
547 
548         @AppSearchSchema.LongPropertyConfig.IndexingType
549         @Field(id = 1, getter = "getIndexingType")
550         private final int mIndexingType;
551 
552         /** Constructor for {@link IntegerIndexingConfigParcel}. */
553         @Constructor
IntegerIndexingConfigParcel( @aramid = 1) @ppSearchSchema.LongPropertyConfig.IndexingType int indexingType)554         public IntegerIndexingConfigParcel(
555                 @Param(id = 1) @AppSearchSchema.LongPropertyConfig.IndexingType int indexingType) {
556             mIndexingType = indexingType;
557         }
558 
559         /** Gets the indexing type for this integer property. */
560         @AppSearchSchema.LongPropertyConfig.IndexingType
getIndexingType()561         public int getIndexingType() {
562             return mIndexingType;
563         }
564 
565         @Override
writeToParcel(@onNull Parcel dest, int flags)566         public void writeToParcel(@NonNull Parcel dest, int flags) {
567             IntegerIndexingConfigParcelCreator.writeToParcel(this, dest, flags);
568         }
569 
570         @Override
hashCode()571         public int hashCode() {
572             return ObjectsCompat.hashCode(mIndexingType);
573         }
574 
575         @Override
equals(@ullable Object other)576         public boolean equals(@Nullable Object other) {
577             if (this == other) {
578                 return true;
579             }
580             if (!(other instanceof IntegerIndexingConfigParcel)) {
581                 return false;
582             }
583             IntegerIndexingConfigParcel otherObject = (IntegerIndexingConfigParcel) other;
584             return mIndexingType == otherObject.mIndexingType;
585         }
586 
587         @Override
toString()588         public @NonNull String toString() {
589             return "{indexingType: " + mIndexingType + "}";
590         }
591     }
592 
593     /** Class to hold configuration for document property type. */
594     @SafeParcelable.Class(creator = "DocumentIndexingConfigParcelCreator")
595     public static class DocumentIndexingConfigParcel extends AbstractSafeParcelable {
596         public static final Parcelable.@NonNull Creator<DocumentIndexingConfigParcel> CREATOR =
597                 new DocumentIndexingConfigParcelCreator();
598 
599         @Field(id = 1, getter = "shouldIndexNestedProperties")
600         private final boolean mIndexNestedProperties;
601 
602         @Field(id = 2, getter = "getIndexableNestedPropertiesList")
603         private final @NonNull List<String> mIndexableNestedPropertiesList;
604 
605         /** Constructor for {@link DocumentIndexingConfigParcel}. */
606         @Constructor
DocumentIndexingConfigParcel( @aramid = 1) boolean indexNestedProperties, @Param(id = 2) @NonNull List<String> indexableNestedPropertiesList)607         public DocumentIndexingConfigParcel(
608                 @Param(id = 1) boolean indexNestedProperties,
609                 @Param(id = 2) @NonNull List<String> indexableNestedPropertiesList) {
610             mIndexNestedProperties = indexNestedProperties;
611             mIndexableNestedPropertiesList = Objects.requireNonNull(indexableNestedPropertiesList);
612         }
613 
614         /** Nested properties should be indexed. */
shouldIndexNestedProperties()615         public boolean shouldIndexNestedProperties() {
616             return mIndexNestedProperties;
617         }
618 
619         /** Gets the list for nested property list. */
getIndexableNestedPropertiesList()620         public @NonNull List<String> getIndexableNestedPropertiesList() {
621             return mIndexableNestedPropertiesList;
622         }
623 
624         @Override
writeToParcel(@onNull Parcel dest, int flags)625         public void writeToParcel(@NonNull Parcel dest, int flags) {
626             DocumentIndexingConfigParcelCreator.writeToParcel(this, dest, flags);
627         }
628 
629         @Override
hashCode()630         public int hashCode() {
631             return ObjectsCompat.hash(mIndexNestedProperties, mIndexableNestedPropertiesList);
632         }
633 
634         @Override
equals(@ullable Object other)635         public boolean equals(@Nullable Object other) {
636             if (this == other) {
637                 return true;
638             }
639             if (!(other instanceof DocumentIndexingConfigParcel)) {
640                 return false;
641             }
642             DocumentIndexingConfigParcel otherObject = (DocumentIndexingConfigParcel) other;
643             return ObjectsCompat.equals(mIndexNestedProperties, otherObject.mIndexNestedProperties)
644                     && ObjectsCompat.equals(mIndexableNestedPropertiesList,
645                     otherObject.mIndexableNestedPropertiesList);
646         }
647 
648         @Override
toString()649         public @NonNull String toString() {
650             return "{indexNestedProperties: " + mIndexNestedProperties
651                     + ", indexableNestedPropertiesList: " + mIndexableNestedPropertiesList
652                     + "}";
653         }
654     }
655 
656     /** Class to hold configuration for embedding property. */
657     @SafeParcelable.Class(creator = "EmbeddingIndexingConfigParcelCreator")
658     public static class EmbeddingIndexingConfigParcel extends AbstractSafeParcelable {
659         public static final Parcelable.@NonNull Creator<EmbeddingIndexingConfigParcel> CREATOR =
660                 new EmbeddingIndexingConfigParcelCreator();
661 
662         @AppSearchSchema.EmbeddingPropertyConfig.IndexingType
663         @Field(id = 1, getter = "getIndexingType")
664         private final int mIndexingType;
665 
666         @AppSearchSchema.EmbeddingPropertyConfig.QuantizationType
667         @Field(id = 2, getter = "getQuantizationType")
668         private final int mQuantizationType;
669 
670         /** Constructor for {@link EmbeddingIndexingConfigParcel}. */
671         @Constructor
EmbeddingIndexingConfigParcel( @aramid = 1) @ppSearchSchema.EmbeddingPropertyConfig.IndexingType int indexingType, @Param(id = 2) @AppSearchSchema.EmbeddingPropertyConfig.QuantizationType int quantizationType)672         public EmbeddingIndexingConfigParcel(
673                 @Param(id = 1) @AppSearchSchema.EmbeddingPropertyConfig.IndexingType
674                 int indexingType,
675                 @Param(id = 2) @AppSearchSchema.EmbeddingPropertyConfig.QuantizationType
676                 int quantizationType) {
677             mIndexingType = indexingType;
678             mQuantizationType = quantizationType;
679         }
680 
681         /** Gets the indexing type for this embedding property. */
682         @AppSearchSchema.EmbeddingPropertyConfig.IndexingType
getIndexingType()683         public int getIndexingType() {
684             return mIndexingType;
685         }
686 
687         /** Gets the quantization type for this embedding property. */
688         @AppSearchSchema.EmbeddingPropertyConfig.QuantizationType
getQuantizationType()689         public int getQuantizationType() {
690             return mQuantizationType;
691         }
692 
693         @Override
writeToParcel(@onNull Parcel dest, int flags)694         public void writeToParcel(@NonNull Parcel dest, int flags) {
695             EmbeddingIndexingConfigParcelCreator.writeToParcel(this, dest, flags);
696         }
697 
698         @Override
hashCode()699         public int hashCode() {
700             return ObjectsCompat.hash(mIndexingType, mQuantizationType);
701         }
702 
703         @Override
equals(@ullable Object other)704         public boolean equals(@Nullable Object other) {
705             if (this == other) {
706                 return true;
707             }
708             if (!(other instanceof EmbeddingIndexingConfigParcel)) {
709                 return false;
710             }
711             EmbeddingIndexingConfigParcel otherObject = (EmbeddingIndexingConfigParcel) other;
712             return mIndexingType == otherObject.mIndexingType
713                     && mQuantizationType == otherObject.mQuantizationType;
714         }
715 
716         @Override
toString()717         public @NonNull String toString() {
718             return "{indexingType: " + mIndexingType
719                     + ", quantizationType: " + mQuantizationType + "}";
720         }
721     }
722 }
723