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 { 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()"; } }; Predicate withNarrowedType() { return this; } } private Predicates() { } public static Predicate alwaysTrue() { return ObjectPredicate.ALWAYS_TRUE.withNarrowedType(); } public static Predicate alwaysFalse() { return ObjectPredicate.ALWAYS_FALSE.withNarrowedType(); } public static Predicate isNull() { return ObjectPredicate.IS_NULL.withNarrowedType(); } public static Predicate notNull() { return ObjectPredicate.NOT_NULL.withNarrowedType(); } public static Predicate not(Predicate predicate) { return new NotPredicate(predicate); } public static Predicate and(Iterable> iterable) { return new AndPredicate(defensiveCopy(iterable)); } @SafeVarargs public static Predicate and(Predicate... predicateArr) { return new AndPredicate(defensiveCopy(predicateArr)); } public static Predicate and(Predicate predicate, Predicate predicate2) { return new AndPredicate(asList((Predicate) Preconditions.checkNotNull(predicate), (Predicate) Preconditions.checkNotNull(predicate2))); } public static Predicate or(Iterable> iterable) { return new OrPredicate(defensiveCopy(iterable)); } @SafeVarargs public static Predicate or(Predicate... predicateArr) { return new OrPredicate(defensiveCopy(predicateArr)); } public static Predicate or(Predicate predicate, Predicate predicate2) { return new OrPredicate(asList((Predicate) Preconditions.checkNotNull(predicate), (Predicate) Preconditions.checkNotNull(predicate2))); } public static Predicate equalTo(T t) { return t == null ? isNull() : new IsEqualToPredicate(t); } public static Predicate instanceOf(Class cls) { return new InstanceOfPredicate(cls); } public static Predicate> subtypeOf(Class cls) { return new SubtypeOfPredicate(cls); } public static Predicate in(Collection collection) { return new InPredicate(collection); } public static Predicate compose(Predicate predicate, Function function) { return new CompositionPredicate(predicate, function); } public static Predicate containsPattern(String str) { return new ContainsPatternFromStringPredicate(str); } public static Predicate contains(Pattern pattern) { return new ContainsPatternPredicate(new JdkPattern(pattern)); } /* loaded from: classes2.dex */ static class NotPredicate implements Predicate, Serializable { private static final long serialVersionUID = 0; final Predicate predicate; NotPredicate(Predicate 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 implements Predicate, Serializable { private static final long serialVersionUID = 0; private final List> components; private AndPredicate(List> 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 implements Predicate, Serializable { private static final long serialVersionUID = 0; private final List> components; private OrPredicate(List> 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 implements Predicate, 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, 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>, 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 implements Predicate, 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 implements Predicate, Serializable { private static final long serialVersionUID = 0; final Function f; final Predicate p; private CompositionPredicate(Predicate predicate, Function 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, 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 List> asList(Predicate predicate, Predicate predicate2) { return Arrays.asList(predicate, predicate2); } private static List defensiveCopy(T... tArr) { return defensiveCopy(Arrays.asList(tArr)); } static List defensiveCopy(Iterable iterable) { ArrayList arrayList = new ArrayList(); Iterator it = iterable.iterator(); while (it.hasNext()) { arrayList.add(Preconditions.checkNotNull(it.next())); } return arrayList; } }