11d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert/*
21d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Copyright (C) 2007 The Guava Authors
31d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert *
41d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Licensed under the Apache License, Version 2.0 (the "License");
51d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * you may not use this file except in compliance with the License.
61d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * You may obtain a copy of the License at
71d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert *
81d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * http://www.apache.org/licenses/LICENSE-2.0
91d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert *
101d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Unless required by applicable law or agreed to in writing, software
111d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * distributed under the License is distributed on an "AS IS" BASIS,
121d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * See the License for the specific language governing permissions and
141d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * limitations under the License.
151d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */
161d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
171d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertpackage com.google.common.base;
181d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
191d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertimport com.google.common.annotations.GwtCompatible;
201d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
211d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertimport javax.annotation.Nullable;
221d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
231d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert/**
241d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Determines an output value based on an input value.
251d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert *
267dd252788645e940eada959bdde927426e2531c9Paul Duffin * <p>The {@link Functions} class provides common functions and related utilites.
277dd252788645e940eada959bdde927426e2531c9Paul Duffin *
287dd252788645e940eada959bdde927426e2531c9Paul Duffin * <p>See the Guava User Guide article on <a href=
297dd252788645e940eada959bdde927426e2531c9Paul Duffin * "http://code.google.com/p/guava-libraries/wiki/FunctionalExplained">the use of {@code
307dd252788645e940eada959bdde927426e2531c9Paul Duffin * Function}</a>.
317dd252788645e940eada959bdde927426e2531c9Paul Duffin *
321d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @author Kevin Bourrillion
331d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @since 2.0 (imported from Google Collections Library)
341d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */
351d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert@GwtCompatible
361d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringertpublic interface Function<F, T> {
371d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  /**
381d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * Returns the result of applying this function to {@code input}. This method is <i>generally
391d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * expected</i>, but not absolutely required, to have the following properties:
401d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   *
411d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * <ul>
421d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * <li>Its execution does not cause any observable side effects.
431d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * <li>The computation is <i>consistent with equals</i>; that is, {@link Objects#equal
441d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   *     Objects.equal}{@code (a, b)} implies that {@code Objects.equal(function.apply(a),
451d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   *     function.apply(b))}.
461d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * </ul>
471d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   *
481d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * @throws NullPointerException if {@code input} is null and this function does not accept null
491d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   *     arguments
501d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   */
510888a09821a98ac0680fad765217302858e70fa4Paul Duffin  @Nullable T apply(@Nullable F input);
521d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert
531d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  /**
541d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * Indicates whether another object is equal to this function.
551d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   *
561d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * <p>Most implementations will have no reason to override the behavior of {@link Object#equals}.
571d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * However, an implementation may also choose to return {@code true} whenever {@code object} is a
581d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * {@link Function} that it considers <i>interchangeable</i> with this one. "Interchangeable"
591d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * <i>typically</i> means that {@code Objects.equal(this.apply(f), that.apply(f))} is true for all
601d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * {@code f} of type {@code F}. Note that a {@code false} result from this method does not imply
611d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   * that the functions are known <i>not</i> to be interchangeable.
621d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert   */
630888a09821a98ac0680fad765217302858e70fa4Paul Duffin  @Override
641d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert  boolean equals(@Nullable Object object);
651d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert}
66