Home | History | Annotate | Download | only in base
      1 /*
      2  * Copyright (C) 2007 The Guava Authors
      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.
     25  *
     26  * <p>The {@link Predicates} class provides common predicates and related utilities.
     27  *
     28  * <p>See the Guava User Guide article on <a href=
     29  * "http://code.google.com/p/guava-libraries/wiki/FunctionalExplained">the use of {@code
     30  * Predicate}</a>.
     31  *
     32  * @author Kevin Bourrillion
     33  * @since 2.0 (imported from Google Collections Library)
     34  */
     35 @GwtCompatible
     36 public interface Predicate<T> {
     37   /**
     38    * Returns the result of applying this predicate to {@code input}. This method is <i>generally
     39    * expected</i>, but not absolutely required, to have the following properties:
     40    *
     41    * <ul>
     42    * <li>Its execution does not cause any observable side effects.
     43    * <li>The computation is <i>consistent with equals</i>; that is, {@link Objects#equal
     44    *     Objects.equal}{@code (a, b)} implies that {@code predicate.apply(a) ==
     45    *     predicate.apply(b))}.
     46    * </ul>
     47    *
     48    * @throws NullPointerException if {@code input} is null and this predicate does not accept null
     49    *     arguments
     50    */
     51   boolean apply(@Nullable T input);
     52 
     53   /**
     54    * Indicates whether another object is equal to this predicate.
     55    *
     56    * <p>Most implementations will have no reason to override the behavior of {@link Object#equals}.
     57    * However, an implementation may also choose to return {@code true} whenever {@code object} is a
     58    * {@link Predicate} that it considers <i>interchangeable</i> with this one. "Interchangeable"
     59    * <i>typically</i> means that {@code this.apply(t) == that.apply(t)} for all {@code t} of type
     60    * {@code T}). Note that a {@code false} result from this method does not imply that the
     61    * predicates are known <i>not</i> to be interchangeable.
     62    */
     63   @Override
     64   boolean equals(@Nullable Object object);
     65 }
     66