Debian Codegraph @

core/java/android/service/autofill/RequiredValidators.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 only returns {@code true} on {@link #isValid(ValueFinder)} if all
32 * of its subvalidators return {@code true} as well.
33 *
34 * <p>Used to implement an {@code AND} logical operation.
35 *
36 * @hide
37 */
38 final class RequiredValidators extends InternalValidator {
39
40 private static final String TAG = "RequiredValidators";
41
42 @NonNull private final InternalValidator[] mValidators;
43
44 RequiredValidators(@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 false;
54 }
55 return true;
56 }
57
58 /////////////////////////////////////
59 // Object "contract" methods. //
60 /////////////////////////////////////
61 @Override
62 public String toString() {
63 if (!sDebug) return super.toString();
64
65 return new StringBuilder("RequiredValidators: [validators=")
66 .append(Arrays.toString(mValidators))
67 .append("]")
68 .toString();
69 }
70
71 /////////////////////////////////////
72 // Parcelable "contract" methods. //
73 /////////////////////////////////////
74 @Override
75 public int describeContents() {
76 return 0;
77 }
78
79 @Override
80 public void writeToParcel(Parcel dest, int flags) {
81 dest.writeParcelableArray(mValidators, flags);
82 }
83
84 public static final @android.annotation.NonNull Parcelable.Creator<RequiredValidators> CREATOR =
85 new Parcelable.Creator<RequiredValidators>() {
86 @Override
87 public RequiredValidators createFromParcel(Parcel parcel) {
88 return new RequiredValidators(parcel
89 .readParcelableArray(null, InternalValidator.class));
90 }
91
92 @Override
93 public RequiredValidators[] newArray(int size) {
94 return new RequiredValidators[size];
95 }
96 };
97 }