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 *      https://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 */
017
018package org.apache.commons.collections4;
019
020import java.util.function.Function;
021
022/**
023 * Defines a functor interface implemented by classes that transform one object into another.
024 * <p>
025 * A {@code Transformer} converts the input object to the output object. The input object SHOULD be left unchanged. Transformers are typically used for type
026 * conversions, or extracting data from an object.
027 * </p>
028 * <p>
029 * Standard implementations of common transformers are provided by {@link TransformerUtils}. These include method invocation, returning a constant, cloning and
030 * returning the string value.
031 * </p>
032 *
033 * @param <T> The type of the input to the function.
034 * @param <R> The type of the result of the function.
035 * @since 1.0 This will be deprecated in 5.0 in favor of {@link Function}.
036 */
037//@Deprecated
038@FunctionalInterface
039public interface Transformer<T, R> extends Function<T, R> {
040
041    @Override
042    default R apply(final T t) {
043        return transform(t);
044    }
045
046    /**
047     * Transforms the input object into some output object.
048     * <p>
049     * The input object SHOULD be left unchanged.
050     * </p>
051     *
052     * @param input The object to be transformed, should be left unchanged.
053     * @return A transformed object.
054     * @throws ClassCastException       (runtime) if the input is the wrong class.
055     * @throws IllegalArgumentException (runtime) if the input is invalid.
056     * @throws FunctorException         (runtime) if the transform cannot be completed.
057     */
058    R transform(T input);
059}