Debian Codegraph @

core/java/android/service/autofill/OptionalValidators.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2017 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.service.autofill;
18
19 import static android.view.autofill.Helper.sDebug;
20
21 import android.annotation.NonNull;
22 import android.os.Parcel;
23 import android.os.Parcelable;
24 import android.util.Log;
25
26 import com.android.internal.util.Preconditions;
27
28 import java.util.Arrays;
29
30 /**
31 * Compound validator that returns {@code true} on {@link #isValid(ValueFinder)} if any
32 * of its subvalidators returns {@code true} as well.
33 *
34 * <p>Used to implement an {@code OR} logical operation.
35 *
36 * @hide
37 */
38 final class OptionalValidators extends InternalValidator {
39
40 private static final String TAG = "OptionalValidators";
41
42 @NonNull private final InternalValidator[] mValidators;
43
44 OptionalValidators(@NonNull InternalValidator[] validators) {
45 mValidators = Preconditions.checkArrayElementsNotNull(validators, "validators");
46 }
47
48 @Override
49 public boolean isValid(@NonNull ValueFinder finder) {
50 for (InternalValidator validator : mValidators) {
51 final boolean valid = validator.isValid(finder);
52 if (sDebug) Log.d(TAG, "isValid(" + validator + "): " + valid);
53 if (valid) return true;
54 }
55
56 return false;
57 }
58
59 /////////////////////////////////////
60 // Object "contract" methods. //
61 /////////////////////////////////////
62 @Override
63 public String toString() {
64 if (!sDebug) return super.toString();
65
66 return new StringBuilder("OptionalValidators: [validators=")
67 .append(Arrays.toString(mValidators))
68 .append("]")
69 .toString();
70 }
71
72 /////////////////////////////////////
73 // Parcelable "contract" methods. //
74 /////////////////////////////////////
75 @Override
76 public int describeContents() {
77 return 0;
78 }
79
80 @Override
81 public void writeToParcel(Parcel dest, int flags) {
82 dest.writeParcelableArray(mValidators, flags);
83 }
84
85 public static final @android.annotation.NonNull Parcelable.Creator<OptionalValidators> CREATOR =
86 new Parcelable.Creator<OptionalValidators>() {
87 @Override
88 public OptionalValidators createFromParcel(Parcel parcel) {
89 return new OptionalValidators(parcel
90 .readParcelableArray(null, InternalValidator.class));
91 }
92
93 @Override
94 public OptionalValidators[] newArray(int size) {
95 return new OptionalValidators[size];
96 }
97 };
98 }