    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017package org.apache.commons.collections4;
    018
    019import java.util.function.Function;
    020
    021/**
    022 * Defines a functor interface implemented by classes that transform one
    023 * object into another.
    024 * <p>
    025 * A {@code Transformer} converts the input object to the output object.
    026 * The input object SHOULD be left unchanged.
    027 * Transformers are typically used for type conversions, or extracting data
    028 * from an object.
    029 * </p>
    030 * <p>
    031 * Standard implementations of common transformers are provided by
    032 * {@link TransformerUtils}. These include method invocation, returning a constant,
    033 * cloning and returning the string value.
    034 * </p>
    035 *
    036 * @param <T> the type of the input to the function.
    037 * @param <R> the type of the result of the function.
    038 * @since 1.0
    039 * @deprecated Use {@link Function}.
    040 */
    041@Deprecated
    042@FunctionalInterface
    043public interface Transformer<T, R> extends Function<T, R> {
    044
    045    @Override
    046    default R apply(final T t) {
    047        return transform(t);
    048    }
    049
    050    /**
    051     * Transforms the input object into some output object.
    052     * <p>
    053     * The input object SHOULD be left unchanged.
    054     * </p>
    055     *
    056     * @param input  the object to be transformed, should be left unchanged
    057     * @return a transformed object
    058     * @throws ClassCastException (runtime) if the input is the wrong class
    059     * @throws IllegalArgumentException (runtime) if the input is invalid
    060     * @throws FunctorException (runtime) if the transform cannot be completed
    061     */
    062    R transform(T input);
    063
    064}