
repacked.com.google.common.base.Predicates Maven / Gradle / Ivy
/**
* Copyright © 2013 Sven Ruppert ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package repacked.com.google.common.base;
import javax.annotation.Nullable;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import static com.google.gson.internal.$Gson$Preconditions.checkNotNull;
/**
* Copyright (C) 2010 RapidPM
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Created by RapidPM - Team on 18.09.16.
*/
public class Predicates {
private Predicates() {
}
public static Predicate alwaysTrue() {
return ObjectPredicate.ALWAYS_TRUE.withNarrowedType();
}
public static Predicate not(Predicate predicate) {
return new NotPredicate<>(predicate);
}
public static Predicate in(Collection extends T> target) {
return new InPredicate<>(target);
}
public static boolean isEmpty(final Predicate super T>[] predicates) {
return predicates == null || predicates.length == 0;
}
public static Predicate and(final Predicate[] predicates) {
return new AndPredicate<>(defensiveCopy(predicates));
}
@SafeVarargs
private static List defensiveCopy(T... array) {
return defensiveCopy(Arrays.asList(array));
}
private static List defensiveCopy(Iterable iterable) {
ArrayList list = new ArrayList<>();
for (T element : iterable) {
list.add(checkNotNull(element));
}
return list;
}
public static Predicate isNull() {
return ObjectPredicate.IS_NULL.withNarrowedType();
}
public static Predicate equalTo(@Nullable T target) {
return (target == null) ? Predicates.isNull() : new IsEqualToPredicate(target);
}
enum ObjectPredicate implements Predicate