• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.android.mail.common.base;
18 
19 
20 /**
21  * Determines a true or false value for a given input. For example, a
22  * {@code RegexPredicate} might implement {@code Predicate<String>}, and return
23  * {@code true} for any string that matches its given regular expression.
24  *
25  * <p>Implementations which may cause side effects upon evaluation are strongly
26  * encouraged to state this fact clearly in their API documentation.
27  *
28  * @author Kevin Bourrillion
29  * @since 2010.01.04 <b>stable</b> (imported from Google Collections Library)
30  */
31 public interface Predicate<T> {
32 
33   /*
34    * This interface does not extend Function<T, Boolean> because doing so would
35    * let predicates return null.
36    */
37 
38   /**
39    * Applies this predicate to the given object.
40    *
41    * @param input the input that the predicate should act on
42    * @return the value of this predicate when applied to the input {@code t}
43    */
apply(T input)44   boolean apply(T input);
45 
46   /**
47    * Indicates whether some other object is equal to this {@code Predicate}.
48    * This method can return {@code true} <i>only</i> if the specified object is
49    * also a {@code Predicate} and, for every input object {@code input}, it
50    * returns exactly the same value. Thus, {@code predicate1.equals(predicate2)}
51    * implies that either {@code predicate1.apply(input)} and
52    * {@code predicate2.apply(input)} are both {@code true} or both
53    * {@code false}.
54    *
55    * <p>Note that it is always safe <i>not</i> to override
56    * {@link Object#equals}.
57    */
equals(Object obj)58   boolean equals(Object obj);
59 }
60