Rabbit-R1/android (non root)/java/sources/com/google/common/base/Predicates.java
2024-05-21 17:08:36 -04:00

500 lines
18 KiB
Java

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;
import javax.annotation.CheckForNull;
@ElementTypesAreNonnullByDefault
/* 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 boolean apply(@CheckForNull Object obj) {
return true;
}
@Override // java.lang.Enum
public String toString() {
return "Predicates.alwaysTrue()";
}
},
ALWAYS_FALSE { // from class: com.google.common.base.Predicates.ObjectPredicate.2
@Override // com.google.common.base.Predicate
public boolean apply(@CheckForNull Object obj) {
return false;
}
@Override // java.lang.Enum
public String toString() {
return "Predicates.alwaysFalse()";
}
},
IS_NULL { // from class: com.google.common.base.Predicates.ObjectPredicate.3
@Override // com.google.common.base.Predicate
public boolean apply(@CheckForNull Object obj) {
return obj == null;
}
@Override // java.lang.Enum
public String toString() {
return "Predicates.isNull()";
}
},
NOT_NULL { // from class: com.google.common.base.Predicates.ObjectPredicate.4
@Override // com.google.common.base.Predicate
public boolean apply(@CheckForNull Object obj) {
return obj != null;
}
@Override // java.lang.Enum
public 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(@ParametricNullness T t) {
if (t == null) {
return isNull();
}
return new IsEqualToPredicate(t).withNarrowedType();
}
public static <T> Predicate<T> 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 */
private 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(@ParametricNullness T t) {
return !this.predicate.apply(t);
}
public int hashCode() {
return ~this.predicate.hashCode();
}
@Override // com.google.common.base.Predicate
public boolean equals(@CheckForNull Object obj) {
if (obj instanceof NotPredicate) {
return this.predicate.equals(((NotPredicate) obj).predicate);
}
return false;
}
public String toString() {
String valueOf = String.valueOf(this.predicate);
return new StringBuilder(String.valueOf(valueOf).length() + 16).append("Predicates.not(").append(valueOf).append(")").toString();
}
}
/* JADX INFO: Access modifiers changed from: 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(@ParametricNullness 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(@CheckForNull 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 */
private 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(@ParametricNullness 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(@CheckForNull 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 append = new StringBuilder("Predicates.").append(str).append('(');
boolean z = true;
for (Object obj : iterable) {
if (!z) {
append.append(',');
}
append.append(obj);
z = false;
}
return append.append(')').toString();
}
/* loaded from: classes2.dex */
private static class IsEqualToPredicate implements Predicate<Object>, Serializable {
private static final long serialVersionUID = 0;
private final Object target;
<T> Predicate<T> withNarrowedType() {
return this;
}
private IsEqualToPredicate(Object obj) {
this.target = obj;
}
@Override // com.google.common.base.Predicate
public boolean apply(@CheckForNull Object obj) {
return this.target.equals(obj);
}
public int hashCode() {
return this.target.hashCode();
}
@Override // com.google.common.base.Predicate
public boolean equals(@CheckForNull Object obj) {
if (obj instanceof IsEqualToPredicate) {
return this.target.equals(((IsEqualToPredicate) obj).target);
}
return false;
}
public String toString() {
String valueOf = String.valueOf(this.target);
return new StringBuilder(String.valueOf(valueOf).length() + 20).append("Predicates.equalTo(").append(valueOf).append(")").toString();
}
}
/* JADX INFO: Access modifiers changed from: private */
/* loaded from: classes2.dex */
public static class InstanceOfPredicate<T> implements Predicate<T>, 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(@ParametricNullness T t) {
return this.clazz.isInstance(t);
}
public int hashCode() {
return this.clazz.hashCode();
}
@Override // com.google.common.base.Predicate
public boolean equals(@CheckForNull Object obj) {
return (obj instanceof InstanceOfPredicate) && this.clazz == ((InstanceOfPredicate) obj).clazz;
}
public String toString() {
String name = this.clazz.getName();
return new StringBuilder(String.valueOf(name).length() + 23).append("Predicates.instanceOf(").append(name).append(")").toString();
}
}
/* loaded from: classes2.dex */
private 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(@CheckForNull Object obj) {
return (obj instanceof SubtypeOfPredicate) && this.clazz == ((SubtypeOfPredicate) obj).clazz;
}
public String toString() {
String name = this.clazz.getName();
return new StringBuilder(String.valueOf(name).length() + 22).append("Predicates.subtypeOf(").append(name).append(")").toString();
}
}
/* loaded from: classes2.dex */
private 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(@ParametricNullness T t) {
try {
return this.target.contains(t);
} catch (ClassCastException | NullPointerException unused) {
return false;
}
}
@Override // com.google.common.base.Predicate
public boolean equals(@CheckForNull 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);
return new StringBuilder(String.valueOf(valueOf).length() + 15).append("Predicates.in(").append(valueOf).append(")").toString();
}
}
/* JADX INFO: Access modifiers changed from: 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(@ParametricNullness A a) {
return this.p.apply(this.f.apply(a));
}
@Override // com.google.common.base.Predicate
public boolean equals(@CheckForNull 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.p.hashCode() ^ this.f.hashCode();
}
public String toString() {
String valueOf = String.valueOf(this.p);
String valueOf2 = String.valueOf(this.f);
return new StringBuilder(String.valueOf(valueOf).length() + 2 + String.valueOf(valueOf2).length()).append(valueOf).append("(").append(valueOf2).append(")").toString();
}
}
/* loaded from: classes2.dex */
private 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(@CheckForNull 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 toStringHelper = MoreObjects.toStringHelper(this.pattern).add("pattern", this.pattern.pattern()).add("pattern.flags", this.pattern.flags()).toString();
return new StringBuilder(String.valueOf(toStringHelper).length() + 21).append("Predicates.contains(").append(toStringHelper).append(")").toString();
}
}
/* loaded from: classes2.dex */
private 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();
return new StringBuilder(String.valueOf(pattern).length() + 28).append("Predicates.containsPattern(").append(pattern).append(")").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;
}
}