what-the-bank/sources/com/google/common/base/Predicates.java

528 lines
18 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.base;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;
/* loaded from: classes2.dex */
public final class Predicates {
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public enum ObjectPredicate implements Predicate<Object> {
ALWAYS_TRUE { // from class: com.google.common.base.Predicates.ObjectPredicate.1
@Override // com.google.common.base.Predicate
public final boolean apply(Object obj) {
return true;
}
@Override // java.lang.Enum
public final String toString() {
return "Predicates.alwaysTrue()";
}
},
ALWAYS_FALSE { // from class: com.google.common.base.Predicates.ObjectPredicate.2
@Override // com.google.common.base.Predicate
public final boolean apply(Object obj) {
return false;
}
@Override // java.lang.Enum
public final String toString() {
return "Predicates.alwaysFalse()";
}
},
IS_NULL { // from class: com.google.common.base.Predicates.ObjectPredicate.3
@Override // com.google.common.base.Predicate
public final boolean apply(Object obj) {
return obj == null;
}
@Override // java.lang.Enum
public final String toString() {
return "Predicates.isNull()";
}
},
NOT_NULL { // from class: com.google.common.base.Predicates.ObjectPredicate.4
@Override // com.google.common.base.Predicate
public final boolean apply(Object obj) {
return obj != null;
}
@Override // java.lang.Enum
public final String toString() {
return "Predicates.notNull()";
}
};
<T> Predicate<T> withNarrowedType() {
return this;
}
}
private Predicates() {
}
public static <T> Predicate<T> alwaysTrue() {
return ObjectPredicate.ALWAYS_TRUE.withNarrowedType();
}
public static <T> Predicate<T> alwaysFalse() {
return ObjectPredicate.ALWAYS_FALSE.withNarrowedType();
}
public static <T> Predicate<T> isNull() {
return ObjectPredicate.IS_NULL.withNarrowedType();
}
public static <T> Predicate<T> notNull() {
return ObjectPredicate.NOT_NULL.withNarrowedType();
}
public static <T> Predicate<T> not(Predicate<T> predicate) {
return new NotPredicate(predicate);
}
public static <T> Predicate<T> and(Iterable<? extends Predicate<? super T>> iterable) {
return new AndPredicate(defensiveCopy(iterable));
}
@SafeVarargs
public static <T> Predicate<T> and(Predicate<? super T>... predicateArr) {
return new AndPredicate(defensiveCopy(predicateArr));
}
public static <T> Predicate<T> and(Predicate<? super T> predicate, Predicate<? super T> predicate2) {
return new AndPredicate(asList((Predicate) Preconditions.checkNotNull(predicate), (Predicate) Preconditions.checkNotNull(predicate2)));
}
public static <T> Predicate<T> or(Iterable<? extends Predicate<? super T>> iterable) {
return new OrPredicate(defensiveCopy(iterable));
}
@SafeVarargs
public static <T> Predicate<T> or(Predicate<? super T>... predicateArr) {
return new OrPredicate(defensiveCopy(predicateArr));
}
public static <T> Predicate<T> or(Predicate<? super T> predicate, Predicate<? super T> predicate2) {
return new OrPredicate(asList((Predicate) Preconditions.checkNotNull(predicate), (Predicate) Preconditions.checkNotNull(predicate2)));
}
public static <T> Predicate<T> equalTo(T t) {
return t == null ? isNull() : new IsEqualToPredicate(t);
}
public static Predicate<Object> instanceOf(Class<?> cls) {
return new InstanceOfPredicate(cls);
}
public static Predicate<Class<?>> subtypeOf(Class<?> cls) {
return new SubtypeOfPredicate(cls);
}
public static <T> Predicate<T> in(Collection<? extends T> collection) {
return new InPredicate(collection);
}
public static <A, B> Predicate<A> compose(Predicate<B> predicate, Function<A, ? extends B> function) {
return new CompositionPredicate(predicate, function);
}
public static Predicate<CharSequence> containsPattern(String str) {
return new ContainsPatternFromStringPredicate(str);
}
public static Predicate<CharSequence> contains(Pattern pattern) {
return new ContainsPatternPredicate(new JdkPattern(pattern));
}
/* loaded from: classes2.dex */
static class NotPredicate<T> implements Predicate<T>, Serializable {
private static final long serialVersionUID = 0;
final Predicate<T> predicate;
NotPredicate(Predicate<T> predicate) {
this.predicate = (Predicate) Preconditions.checkNotNull(predicate);
}
@Override // com.google.common.base.Predicate
public boolean apply(T t) {
return !this.predicate.apply(t);
}
public int hashCode() {
return ~this.predicate.hashCode();
}
@Override // com.google.common.base.Predicate
public boolean equals(Object obj) {
if (obj instanceof NotPredicate) {
return this.predicate.equals(((NotPredicate) obj).predicate);
}
return false;
}
public String toString() {
String valueOf = String.valueOf(this.predicate);
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 16);
sb.append("Predicates.not(");
sb.append(valueOf);
sb.append(")");
return sb.toString();
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static class AndPredicate<T> implements Predicate<T>, Serializable {
private static final long serialVersionUID = 0;
private final List<? extends Predicate<? super T>> components;
private AndPredicate(List<? extends Predicate<? super T>> list) {
this.components = list;
}
@Override // com.google.common.base.Predicate
public boolean apply(T t) {
for (int i = 0; i < this.components.size(); i++) {
if (!this.components.get(i).apply(t)) {
return false;
}
}
return true;
}
public int hashCode() {
return this.components.hashCode() + 306654252;
}
@Override // com.google.common.base.Predicate
public boolean equals(Object obj) {
if (obj instanceof AndPredicate) {
return this.components.equals(((AndPredicate) obj).components);
}
return false;
}
public String toString() {
return Predicates.toStringHelper("and", this.components);
}
}
/* loaded from: classes2.dex */
static class OrPredicate<T> implements Predicate<T>, Serializable {
private static final long serialVersionUID = 0;
private final List<? extends Predicate<? super T>> components;
private OrPredicate(List<? extends Predicate<? super T>> list) {
this.components = list;
}
@Override // com.google.common.base.Predicate
public boolean apply(T t) {
for (int i = 0; i < this.components.size(); i++) {
if (this.components.get(i).apply(t)) {
return true;
}
}
return false;
}
public int hashCode() {
return this.components.hashCode() + 87855567;
}
@Override // com.google.common.base.Predicate
public boolean equals(Object obj) {
if (obj instanceof OrPredicate) {
return this.components.equals(((OrPredicate) obj).components);
}
return false;
}
public String toString() {
return Predicates.toStringHelper("or", this.components);
}
}
/* JADX INFO: Access modifiers changed from: private */
public static String toStringHelper(String str, Iterable<?> iterable) {
StringBuilder sb = new StringBuilder("Predicates.");
sb.append(str);
sb.append('(');
boolean z = true;
for (Object obj : iterable) {
if (!z) {
sb.append(',');
}
sb.append(obj);
z = false;
}
sb.append(')');
return sb.toString();
}
/* loaded from: classes2.dex */
static class IsEqualToPredicate<T> implements Predicate<T>, Serializable {
private static final long serialVersionUID = 0;
private final T target;
private IsEqualToPredicate(T t) {
this.target = t;
}
@Override // com.google.common.base.Predicate
public boolean apply(T t) {
return this.target.equals(t);
}
public int hashCode() {
return this.target.hashCode();
}
@Override // com.google.common.base.Predicate
public boolean equals(Object obj) {
if (obj instanceof IsEqualToPredicate) {
return this.target.equals(((IsEqualToPredicate) obj).target);
}
return false;
}
public String toString() {
String valueOf = String.valueOf(this.target);
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 20);
sb.append("Predicates.equalTo(");
sb.append(valueOf);
sb.append(")");
return sb.toString();
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static class InstanceOfPredicate implements Predicate<Object>, Serializable {
private static final long serialVersionUID = 0;
private final Class<?> clazz;
private InstanceOfPredicate(Class<?> cls) {
this.clazz = (Class) Preconditions.checkNotNull(cls);
}
@Override // com.google.common.base.Predicate
public boolean apply(Object obj) {
return this.clazz.isInstance(obj);
}
public int hashCode() {
return this.clazz.hashCode();
}
@Override // com.google.common.base.Predicate
public boolean equals(Object obj) {
return (obj instanceof InstanceOfPredicate) && this.clazz == ((InstanceOfPredicate) obj).clazz;
}
public String toString() {
String name = this.clazz.getName();
StringBuilder sb = new StringBuilder(String.valueOf(name).length() + 23);
sb.append("Predicates.instanceOf(");
sb.append(name);
sb.append(")");
return sb.toString();
}
}
/* loaded from: classes2.dex */
static class SubtypeOfPredicate implements Predicate<Class<?>>, Serializable {
private static final long serialVersionUID = 0;
private final Class<?> clazz;
private SubtypeOfPredicate(Class<?> cls) {
this.clazz = (Class) Preconditions.checkNotNull(cls);
}
@Override // com.google.common.base.Predicate
public boolean apply(Class<?> cls) {
return this.clazz.isAssignableFrom(cls);
}
public int hashCode() {
return this.clazz.hashCode();
}
@Override // com.google.common.base.Predicate
public boolean equals(Object obj) {
return (obj instanceof SubtypeOfPredicate) && this.clazz == ((SubtypeOfPredicate) obj).clazz;
}
public String toString() {
String name = this.clazz.getName();
StringBuilder sb = new StringBuilder(String.valueOf(name).length() + 22);
sb.append("Predicates.subtypeOf(");
sb.append(name);
sb.append(")");
return sb.toString();
}
}
/* loaded from: classes2.dex */
static class InPredicate<T> implements Predicate<T>, Serializable {
private static final long serialVersionUID = 0;
private final Collection<?> target;
private InPredicate(Collection<?> collection) {
this.target = (Collection) Preconditions.checkNotNull(collection);
}
@Override // com.google.common.base.Predicate
public boolean apply(T t) {
try {
return this.target.contains(t);
} catch (ClassCastException | NullPointerException unused) {
return false;
}
}
@Override // com.google.common.base.Predicate
public boolean equals(Object obj) {
if (obj instanceof InPredicate) {
return this.target.equals(((InPredicate) obj).target);
}
return false;
}
public int hashCode() {
return this.target.hashCode();
}
public String toString() {
String valueOf = String.valueOf(this.target);
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 15);
sb.append("Predicates.in(");
sb.append(valueOf);
sb.append(")");
return sb.toString();
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static class CompositionPredicate<A, B> implements Predicate<A>, Serializable {
private static final long serialVersionUID = 0;
final Function<A, ? extends B> f;
final Predicate<B> p;
private CompositionPredicate(Predicate<B> predicate, Function<A, ? extends B> function) {
this.p = (Predicate) Preconditions.checkNotNull(predicate);
this.f = (Function) Preconditions.checkNotNull(function);
}
@Override // com.google.common.base.Predicate
public boolean apply(A a) {
return this.p.apply(this.f.apply(a));
}
@Override // com.google.common.base.Predicate
public boolean equals(Object obj) {
if (!(obj instanceof CompositionPredicate)) {
return false;
}
CompositionPredicate compositionPredicate = (CompositionPredicate) obj;
return this.f.equals(compositionPredicate.f) && this.p.equals(compositionPredicate.p);
}
public int hashCode() {
return this.f.hashCode() ^ this.p.hashCode();
}
public String toString() {
String valueOf = String.valueOf(this.p);
String valueOf2 = String.valueOf(this.f);
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 2 + String.valueOf(valueOf2).length());
sb.append(valueOf);
sb.append("(");
sb.append(valueOf2);
sb.append(")");
return sb.toString();
}
}
/* loaded from: classes2.dex */
static class ContainsPatternPredicate implements Predicate<CharSequence>, Serializable {
private static final long serialVersionUID = 0;
final CommonPattern pattern;
ContainsPatternPredicate(CommonPattern commonPattern) {
this.pattern = (CommonPattern) Preconditions.checkNotNull(commonPattern);
}
@Override // com.google.common.base.Predicate
public boolean apply(CharSequence charSequence) {
return this.pattern.matcher(charSequence).find();
}
public int hashCode() {
return Objects.hashCode(this.pattern.pattern(), Integer.valueOf(this.pattern.flags()));
}
@Override // com.google.common.base.Predicate
public boolean equals(Object obj) {
if (!(obj instanceof ContainsPatternPredicate)) {
return false;
}
ContainsPatternPredicate containsPatternPredicate = (ContainsPatternPredicate) obj;
return Objects.equal(this.pattern.pattern(), containsPatternPredicate.pattern.pattern()) && this.pattern.flags() == containsPatternPredicate.pattern.flags();
}
public String toString() {
String obj = MoreObjects.toStringHelper(this.pattern).add("pattern", this.pattern.pattern()).add("pattern.flags", this.pattern.flags()).toString();
StringBuilder sb = new StringBuilder(String.valueOf(obj).length() + 21);
sb.append("Predicates.contains(");
sb.append(obj);
sb.append(")");
return sb.toString();
}
}
/* loaded from: classes2.dex */
static class ContainsPatternFromStringPredicate extends ContainsPatternPredicate {
private static final long serialVersionUID = 0;
ContainsPatternFromStringPredicate(String str) {
super(Platform.compilePattern(str));
}
@Override // com.google.common.base.Predicates.ContainsPatternPredicate
public String toString() {
String pattern = this.pattern.pattern();
StringBuilder sb = new StringBuilder(String.valueOf(pattern).length() + 28);
sb.append("Predicates.containsPattern(");
sb.append(pattern);
sb.append(")");
return sb.toString();
}
}
private static <T> List<Predicate<? super T>> asList(Predicate<? super T> predicate, Predicate<? super T> predicate2) {
return Arrays.asList(predicate, predicate2);
}
private static <T> List<T> defensiveCopy(T... tArr) {
return defensiveCopy(Arrays.asList(tArr));
}
static <T> List<T> defensiveCopy(Iterable<T> iterable) {
ArrayList arrayList = new ArrayList();
Iterator<T> it = iterable.iterator();
while (it.hasNext()) {
arrayList.add(Preconditions.checkNotNull(it.next()));
}
return arrayList;
}
}