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.android.mail.lib.base; 18 19 /** 20 * A transformation from one object to another. For example, a 21 * {@code StringToIntegerFunction} may implement 22 * <code>Function<String,Integer></code> and transform integers in 23 * {@code String} format to {@code Integer} format. 24 * 25 * <p>The transformation on the source object does not necessarily result in 26 * an object of a different type. For example, a 27 * {@code FarenheitToCelsiusFunction} may implement 28 * <code>Function<Float,Float></code>. 29 * 30 * <p>Implementations which may cause side effects upon evaluation are strongly 31 * encouraged to state this fact clearly in their API documentation. 32 * 33 * @param <F> the type of the function input 34 * @param <T> the type of the function output 35 * @author Kevin Bourrillion 36 * @author Scott Bonneau 37 * @since 2010.01.04 <b>stable</b> (imported from Google Collections Library) 38 */ 39 public interface Function<F, T> { 40 41 /** 42 * Applies the function to an object of type {@code F}, resulting in an object 43 * of type {@code T}. Note that types {@code F} and {@code T} may or may not 44 * be the same. 45 * 46 * @param from the source object 47 * @return the resulting object 48 */ 49 T apply(F from); 50 51 /** 52 * Indicates whether some other object is equal to this {@code Function}. 53 * This method can return {@code true} <i>only</i> if the specified object is 54 * also a {@code Function} and, for every input object {@code o}, it returns 55 * exactly the same value. Thus, {@code function1.equals(function2)} implies 56 * that either {@code function1.apply(o)} and {@code function2.apply(o)} are 57 * both null, or {@code function1.apply(o).equals(function2.apply(o))}. 58 * 59 * <p>Note that it is always safe <em>not</em> to override 60 * {@link Object#equals}. 61 */ 62 boolean equals(Object obj); 63 } 64