1 /* 2 * Copyright (C) 2007 Google Inc. 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 17 package com.google.android.mail.common.base; 18 19 20 /** 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. 25 * 26 * <p>The transformation on the source object does not necessarily result in 27 * an object of a different type. For example, a 28 * {@code FarenheitToCelsiusFunction} may implement 29 * <code>Function<Float,Float></code>. 30 * 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 * @param <F> the type of the function input 35 * @param <T> the type of the function output 36 * @author Kevin Bourrillion 37 * @author Scott Bonneau 38 * @since 2010.01.04 <b>stable</b> (imported from Google Collections Library) 39 */ 40 public interface Function<F, T> { 41 42 /** 43 * Applies the function to an object of type {@code F}, resulting in an object 44 * of type {@code T}. Note that types {@code F} and {@code T} may or may not 45 * be the same. 46 * 47 * @param from the source object 48 * @return the resulting object 49 */ apply(F from)50 T apply(F from); 51 52 /** 53 * Indicates whether some other object is equal to this {@code Function}. 54 * This method can return {@code true} <i>only</i> if the specified object is 55 * also a {@code Function} and, for every input object {@code o}, it returns 56 * exactly the same value. Thus, {@code function1.equals(function2)} implies 57 * that either {@code function1.apply(o)} and {@code function2.apply(o)} are 58 * both null, or {@code function1.apply(o).equals(function2.apply(o))}. 59 * 60 * <p>Note that it is always safe <em>not</em> to override 61 * {@link Object#equals}. 62 */ equals(Object obj)63 boolean equals(Object obj); 64 } 65