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
17package com.google.common.base;
18
19import com.google.common.annotations.GwtCompatible;
20
21import javax.annotation.Nullable;
22
23/**
24 * Determines an output value based on an input value.
25 *
26 * @author Kevin Bourrillion
27 * @since 2.0 (imported from Google Collections Library)
28 */
29@GwtCompatible
30public interface Function<F, T> {
31  /**
32   * Returns the result of applying this function to {@code input}. This method is <i>generally
33   * expected</i>, but not absolutely required, to have the following properties:
34   *
35   * <ul>
36   * <li>Its execution does not cause any observable side effects.
37   * <li>The computation is <i>consistent with equals</i>; that is, {@link Objects#equal
38   *     Objects.equal}{@code (a, b)} implies that {@code Objects.equal(function.apply(a),
39   *     function.apply(b))}.
40   * </ul>
41   *
42   * @throws NullPointerException if {@code input} is null and this function does not accept null
43   *     arguments
44   */
45  T apply(@Nullable F input);
46
47  /**
48   * Indicates whether another object is equal to this function.
49   *
50   * <p>Most implementations will have no reason to override the behavior of {@link Object#equals}.
51   * However, an implementation may also choose to return {@code true} whenever {@code object} is a
52   * {@link Function} that it considers <i>interchangeable</i> with this one. "Interchangeable"
53   * <i>typically</i> means that {@code Objects.equal(this.apply(f), that.apply(f))} is true for all
54   * {@code f} of type {@code F}. Note that a {@code false} result from this method does not imply
55   * that the functions are known <i>not</i> to be interchangeable.
56   */
57  @Override
58  boolean equals(@Nullable Object object);
59}
60