Initial commit
This commit is contained in:
218
sources/com/google/common/base/Predicates.java
Normal file
218
sources/com/google/common/base/Predicates.java
Normal file
@@ -0,0 +1,218 @@
|
||||
package com.google.common.base;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class Predicates {
|
||||
|
||||
private static class CompositionPredicate<A, B> implements Predicate<A>, Serializable {
|
||||
final Predicate<B> a;
|
||||
final Function<A, ? extends B> b;
|
||||
|
||||
@Override // com.google.common.base.Predicate
|
||||
public boolean apply(A a) {
|
||||
return this.a.apply(this.b.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.b.equals(compositionPredicate.b) && this.a.equals(compositionPredicate.a);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.b.hashCode() ^ this.a.hashCode();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.a + "(" + this.b + ")";
|
||||
}
|
||||
|
||||
private CompositionPredicate(Predicate<B> predicate, Function<A, ? extends B> function) {
|
||||
Preconditions.a(predicate);
|
||||
this.a = predicate;
|
||||
Preconditions.a(function);
|
||||
this.b = function;
|
||||
}
|
||||
}
|
||||
|
||||
private static class InPredicate<T> implements Predicate<T>, Serializable {
|
||||
private final Collection<?> a;
|
||||
|
||||
@Override // com.google.common.base.Predicate
|
||||
public boolean apply(T t) {
|
||||
try {
|
||||
return this.a.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.a.equals(((InPredicate) obj).a);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.a.hashCode();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Predicates.in(" + this.a + ")";
|
||||
}
|
||||
|
||||
private InPredicate(Collection<?> collection) {
|
||||
Preconditions.a(collection);
|
||||
this.a = collection;
|
||||
}
|
||||
}
|
||||
|
||||
private static class IsEqualToPredicate<T> implements Predicate<T>, Serializable {
|
||||
private final T a;
|
||||
|
||||
@Override // com.google.common.base.Predicate
|
||||
public boolean apply(T t) {
|
||||
return this.a.equals(t);
|
||||
}
|
||||
|
||||
@Override // com.google.common.base.Predicate
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof IsEqualToPredicate) {
|
||||
return this.a.equals(((IsEqualToPredicate) obj).a);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return this.a.hashCode();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Predicates.equalTo(" + this.a + ")";
|
||||
}
|
||||
|
||||
private IsEqualToPredicate(T t) {
|
||||
this.a = t;
|
||||
}
|
||||
}
|
||||
|
||||
private static class NotPredicate<T> implements Predicate<T>, Serializable {
|
||||
final Predicate<T> a;
|
||||
|
||||
NotPredicate(Predicate<T> predicate) {
|
||||
Preconditions.a(predicate);
|
||||
this.a = predicate;
|
||||
}
|
||||
|
||||
@Override // com.google.common.base.Predicate
|
||||
public boolean apply(T t) {
|
||||
return !this.a.apply(t);
|
||||
}
|
||||
|
||||
@Override // com.google.common.base.Predicate
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof NotPredicate) {
|
||||
return this.a.equals(((NotPredicate) obj).a);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return ~this.a.hashCode();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Predicates.not(" + this.a + ")";
|
||||
}
|
||||
}
|
||||
|
||||
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(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(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(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(Object obj) {
|
||||
return obj != null;
|
||||
}
|
||||
|
||||
@Override // java.lang.Enum
|
||||
public String toString() {
|
||||
return "Predicates.notNull()";
|
||||
}
|
||||
};
|
||||
|
||||
<T> Predicate<T> c() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
Joiner.a(',');
|
||||
}
|
||||
|
||||
public static <T> Predicate<T> a() {
|
||||
ObjectPredicate objectPredicate = ObjectPredicate.ALWAYS_TRUE;
|
||||
objectPredicate.c();
|
||||
return objectPredicate;
|
||||
}
|
||||
|
||||
public static <T> Predicate<T> b() {
|
||||
ObjectPredicate objectPredicate = ObjectPredicate.IS_NULL;
|
||||
objectPredicate.c();
|
||||
return objectPredicate;
|
||||
}
|
||||
|
||||
public static <T> Predicate<T> a(Predicate<T> predicate) {
|
||||
return new NotPredicate(predicate);
|
||||
}
|
||||
|
||||
public static <T> Predicate<T> a(T t) {
|
||||
return t == null ? b() : new IsEqualToPredicate(t);
|
||||
}
|
||||
|
||||
public static <T> Predicate<T> a(Collection<? extends T> collection) {
|
||||
return new InPredicate(collection);
|
||||
}
|
||||
|
||||
public static <A, B> Predicate<A> a(Predicate<B> predicate, Function<A, ? extends B> function) {
|
||||
return new CompositionPredicate(predicate, function);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user