001/*
002 * Copyright (C) 2007 The Guava Authors
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
017package com.google.common.base;
018
019import com.google.common.annotations.GwtCompatible;
020
021import javax.annotation.Nullable;
022
023/**
024 * Determines a true or false value for a given input.
025 *
026 * @author Kevin Bourrillion
027 * @since 2 (imported from Google Collections Library)
028 */
029@GwtCompatible
030public interface Predicate<T> {
031  /**
032   * Returns the result of applying this predicate to {@code input}. This method is <i>generally
033   * expected</i>, but not absolutely required, to have the following properties:
034   *
035   * <ul>
036   * <li>Its execution does not cause any observable side effects.
037   * <li>The computation is <i>consistent with equals</i>; that is, {@link Objects#equal
038   *     Objects.equal}{@code (a, b)} implies that {@code predicate.apply(a) ==
039   *     predicate.apply(b))}.
040   * </ul>
041   *
042   * @throws NullPointerException if {@code input} is null and this predicate does not accept null
043   *     arguments
044   */
045  boolean apply(@Nullable T input);
046
047  /**
048   * Indicates whether another object is equal to this predicate.
049   *
050   * <p>Most implementations will have no reason to override the behavior of {@link Object#equals}.
051   * However, an implementation may also choose to return {@code true} whenever {@code object} is a
052   * {@link Predicate} that it considers <i>interchangeable</i> with this one. "Interchangeable"
053   * <i>typically</i> means that {@code this.apply(t) == that.apply(t)} for all {@code t} of type
054   * {@code T}). Note that a {@code false} result from this method does not imply that the
055   * predicates are known <i>not</i> to be interchangeable.
056   */
057  @Override
058  boolean equals(@Nullable Object object);
059}