18b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira/*
28b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * Copyright (C) 2007 Google Inc.
38b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira *
48b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * Licensed under the Apache License, Version 2.0 (the "License");
58b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * you may not use this file except in compliance with the License.
68b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * You may obtain a copy of the License at
78b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira *
88b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * http://www.apache.org/licenses/LICENSE-2.0
98b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira *
108b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * Unless required by applicable law or agreed to in writing, software
118b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * distributed under the License is distributed on an "AS IS" BASIS,
128b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * See the License for the specific language governing permissions and
148b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * limitations under the License.
158b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira */
168b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira
1730e2c24b056542f3b1b438aeb798305d1226d0c8Andy Huangpackage com.android.mail.lib.base;
188b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira
198b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira/**
208b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * A transformation from one object to another. For example, a
218b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * {@code StringToIntegerFunction} may implement
228b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * <code>Function&lt;String,Integer&gt;</code> and transform integers in
238b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * {@code String} format to {@code Integer} format.
248b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira *
258b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * <p>The transformation on the source object does not necessarily result in
268b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * an object of a different type.  For example, a
278b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * {@code FarenheitToCelsiusFunction} may implement
288b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * <code>Function&lt;Float,Float&gt;</code>.
298b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira *
308b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * <p>Implementations which may cause side effects upon evaluation are strongly
318b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * encouraged to state this fact clearly in their API documentation.
328b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira *
338b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * @param <F> the type of the function input
348b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * @param <T> the type of the function output
358b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * @author Kevin Bourrillion
368b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * @author Scott Bonneau
378b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira * @since 2010.01.04 <b>stable</b> (imported from Google Collections Library)
388b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira */
398b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereirapublic interface Function<F, T> {
408b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira
418b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira  /**
428b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira   * Applies the function to an object of type {@code F}, resulting in an object
438b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira   * of type {@code T}.  Note that types {@code F} and {@code T} may or may not
448b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira   * be the same.
458b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira   *
468b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira   * @param from the source object
478b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira   * @return the resulting object
488b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira   */
498b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira  T apply(F from);
508b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira
518b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira  /**
528b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira   * Indicates whether some other object is equal to this {@code Function}.
538b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira   * This method can return {@code true} <i>only</i> if the specified object is
548b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira   * also a {@code Function} and, for every input object {@code o}, it returns
558b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira   * exactly the same value.  Thus, {@code function1.equals(function2)} implies
568b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira   * that either {@code function1.apply(o)} and {@code function2.apply(o)} are
578b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira   * both null, or {@code function1.apply(o).equals(function2.apply(o))}.
588b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira   *
598b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira   * <p>Note that it is always safe <em>not</em> to override
608b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira   * {@link Object#equals}.
618b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira   */
628b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira  boolean equals(Object obj);
638b99ba451db6973978e60f91da2199686a9c85e7Mindy Pereira}
64