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 an output value based on an input value.
025 * 
026 * <p>See the Guava User Guide article on <a href=
027 * "http://code.google.com/p/guava-libraries/wiki/FunctionalExplained">the use of {@code
028 * Function}</a>.
029 * 
030 * @author Kevin Bourrillion
031 * @since 2.0 (imported from Google Collections Library)
032 */
033@GwtCompatible
034public interface Function<F, T> {
035  /**
036   * Returns the result of applying this function to {@code input}. This method is <i>generally
037   * expected</i>, but not absolutely required, to have the following properties:
038   *
039   * <ul>
040   * <li>Its execution does not cause any observable side effects.
041   * <li>The computation is <i>consistent with equals</i>; that is, {@link Objects#equal
042   *     Objects.equal}{@code (a, b)} implies that {@code Objects.equal(function.apply(a),
043   *     function.apply(b))}.
044   * </ul>
045   *
046   * @throws NullPointerException if {@code input} is null and this function does not accept null
047   *     arguments
048   */
049  @Nullable T apply(@Nullable F input);
050
051  /**
052   * Indicates whether another object is equal to this function.
053   *
054   * <p>Most implementations will have no reason to override the behavior of {@link Object#equals}.
055   * However, an implementation may also choose to return {@code true} whenever {@code object} is a
056   * {@link Function} that it considers <i>interchangeable</i> with this one. "Interchangeable"
057   * <i>typically</i> means that {@code Objects.equal(this.apply(f), that.apply(f))} is true for all
058   * {@code f} of type {@code F}. Note that a {@code false} result from this method does not imply
059   * that the functions are known <i>not</i> to be interchangeable.
060   */
061  @Override
062  boolean equals(@Nullable Object object);
063}