blob: 0e2264ce4a1746fa0db2fef684c01b6ed9ab7f39 [file] [log] [blame]
crazyboblee210bf432009-02-05 06:04:18 +00001/*
2 * Copyright (C) 2007 Google Inc.
crazyboblee66b415a2006-08-25 02:01:19 +00003 *
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
sberlin9a277032010-08-01 19:23:10 +000017package com.google.inject.internal.util;
18
crazyboblee66b415a2006-08-25 02:01:19 +000019
20/**
crazyboblee210bf432009-02-05 06:04:18 +000021 * A transformation from one object to another. For example, a
22 * {@code StringToIntegerFunction} may implement
23 * <code>Function&lt;String,Integer&gt;</code> and transform integers in
24 * {@code String} format to {@code Integer} format.
crazyboblee66b415a2006-08-25 02:01:19 +000025 *
crazyboblee210bf432009-02-05 06:04:18 +000026 * <p>The transformation on the source object does not necessarily result in
crazyboblee66b415a2006-08-25 02:01:19 +000027 * an object of a different type. For example, a
crazyboblee210bf432009-02-05 06:04:18 +000028 * {@code FarenheitToCelsiusFunction} may implement
crazyboblee66b415a2006-08-25 02:01:19 +000029 * <code>Function&lt;Float,Float&gt;</code>.
30 *
crazyboblee210bf432009-02-05 06:04:18 +000031 * <p>Implementations which may cause side effects upon evaluation are strongly
32 * encouraged to state this fact clearly in their API documentation.
33 *
34 * <p>This interface may be used with the Google Web Toolkit (GWT).
35 *
36 * @param <F> the type of the function input
37 * @param <T> the type of the function output
38 * @author Kevin Bourrillion
39 * @author Scott Bonneau
crazyboblee66b415a2006-08-25 02:01:19 +000040 */
crazyboblee210bf432009-02-05 06:04:18 +000041public interface Function<F, T> {
crazyboblee66b415a2006-08-25 02:01:19 +000042
43 /**
44 * Applies the function to an object of type {@code F}, resulting in an object
45 * of type {@code T}. Note that types {@code F} and {@code T} may or may not
46 * be the same.
crazyboblee210bf432009-02-05 06:04:18 +000047 *
48 * @param from the source object
49 * @return the resulting object
crazyboblee66b415a2006-08-25 02:01:19 +000050 */
crazyboblee210bf432009-02-05 06:04:18 +000051 T apply(@Nullable F from);
52
53 /**
54 * Indicates whether some other object is equal to this {@code Function}.
55 * This method can return {@code true} <i>only</i> if the specified object is
56 * also a {@code Function} and, for every input object {@code o}, it returns
57 * exactly the same value. Thus, {@code function1.equals(function2)} implies
58 * that either {@code function1.apply(o)} and {@code function2.apply(o)} are
59 * both null, or {@code function1.apply(o).equals(function2.apply(o))}.
60 *
61 * <p>Note that it is always safe <em>not</em> to override
62 * {@link Object#equals}.
63 */
64 boolean equals(@Nullable Object obj);
crazyboblee66b415a2006-08-25 02:01:19 +000065}