1 /* 2 * Copyright (C) 2007 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.common.base; 18 19 import com.google.common.annotations.GwtCompatible; 20 21 import javax.annotation.Nullable; 22 23 /** 24 * Determines a true or false value for a given input. For example, a 25 * {@code RegexPredicate} might implement {@code Predicate<String>}, and return 26 * {@code true} for any string that matches its given regular expression. 27 * 28 * <p>Implementations which may cause side effects upon evaluation are strongly 29 * encouraged to state this fact clearly in their API documentation. 30 * 31 * @author Kevin Bourrillion 32 * @since 2010.01.04 <b>stable</b> (imported from Google Collections Library) 33 */ 34 @GwtCompatible 35 public interface Predicate<T> { 36 37 /* 38 * This interface does not extend Function<T, Boolean> because doing so would 39 * let predicates return null. 40 */ 41 42 /** 43 * Applies this predicate to the given object. 44 * 45 * @param input the input that the predicate should act on 46 * @return the value of this predicate when applied to the input {@code t} 47 */ 48 boolean apply(@Nullable T input); 49 50 /** 51 * Indicates whether some other object is equal to this {@code Predicate}. 52 * This method can return {@code true} <i>only</i> if the specified object is 53 * also a {@code Predicate} and, for every input object {@code input}, it 54 * returns exactly the same value. Thus, {@code predicate1.equals(predicate2)} 55 * implies that either {@code predicate1.apply(input)} and 56 * {@code predicate2.apply(input)} are both {@code true} or both 57 * {@code false}. 58 * 59 * <p>Note that it is always safe <i>not</i> to override 60 * {@link Object#equals}. 61 */ 62 boolean equals(@Nullable Object obj); 63 } 64