crazyboblee | 210bf43 | 2009-02-05 06:04:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Google Inc. |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 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 | |
sberlin | 9a27703 | 2010-08-01 19:23:10 +0000 | [diff] [blame] | 17 | package com.google.inject.internal.util; |
| 18 | |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 19 | |
| 20 | /** |
crazyboblee | 210bf43 | 2009-02-05 06:04:18 +0000 | [diff] [blame] | 21 | * A transformation from one object to another. For example, a |
| 22 | * {@code StringToIntegerFunction} may implement |
| 23 | * <code>Function<String,Integer></code> and transform integers in |
| 24 | * {@code String} format to {@code Integer} format. |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 25 | * |
crazyboblee | 210bf43 | 2009-02-05 06:04:18 +0000 | [diff] [blame] | 26 | * <p>The transformation on the source object does not necessarily result in |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 27 | * an object of a different type. For example, a |
crazyboblee | 210bf43 | 2009-02-05 06:04:18 +0000 | [diff] [blame] | 28 | * {@code FarenheitToCelsiusFunction} may implement |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 29 | * <code>Function<Float,Float></code>. |
| 30 | * |
crazyboblee | 210bf43 | 2009-02-05 06:04:18 +0000 | [diff] [blame] | 31 | * <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 |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 40 | */ |
crazyboblee | 210bf43 | 2009-02-05 06:04:18 +0000 | [diff] [blame] | 41 | public interface Function<F, T> { |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 42 | |
| 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. |
crazyboblee | 210bf43 | 2009-02-05 06:04:18 +0000 | [diff] [blame] | 47 | * |
| 48 | * @param from the source object |
| 49 | * @return the resulting object |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 50 | */ |
crazyboblee | 210bf43 | 2009-02-05 06:04:18 +0000 | [diff] [blame] | 51 | 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); |
crazyboblee | 66b415a | 2006-08-25 02:01:19 +0000 | [diff] [blame] | 65 | } |