001    /*
002     * Copyright (C) 2007 Google Inc.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package com.google.common.base;
018    
019    import com.google.common.annotations.GwtCompatible;
020    
021    import javax.annotation.Nullable;
022    
023    /**
024     * Determines a true or false value for a given input. For example, a
025     * {@code RegexPredicate} might implement {@code Predicate<String>}, and return
026     * {@code true} for any string that matches its given regular expression.
027     *
028     * <p>Implementations which may cause side effects upon evaluation are strongly
029     * encouraged to state this fact clearly in their API documentation.
030     *
031     * @author Kevin Bourrillion
032     * @since 2 (imported from Google Collections Library)
033     */
034    @GwtCompatible
035    public interface Predicate<T> {
036    
037      /*
038       * This interface does not extend Function<T, Boolean> because doing so would
039       * let predicates return null.
040       */
041    
042      /**
043       * Applies this predicate to the given object.
044       *
045       * @param input the input that the predicate should act on
046       * @return the value of this predicate when applied to the input {@code t}
047       */
048      boolean apply(@Nullable T input);
049    
050      /**
051       * Indicates whether some other object is equal to this {@code Predicate}.
052       * This method can return {@code true} <i>only</i> if the specified object is
053       * also a {@code Predicate} and, for every input object {@code input}, it
054       * returns exactly the same value. Thus, {@code predicate1.equals(predicate2)}
055       * implies that either {@code predicate1.apply(input)} and
056       * {@code predicate2.apply(input)} are both {@code true} or both
057       * {@code false}.
058       *
059       * <p>Note that it is always safe <i>not</i> to override
060       * {@link Object#equals}.
061       */
062      boolean equals(@Nullable Object obj);
063    }