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 input type to the transformer 037 * @param <R> the output type from the transformer 038 * 039 * @since 1.0 040 * @deprecated Use {@link Function}. 041 */ 042@Deprecated 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 (leaving it unchanged) into some output object. 052 * 053 * @param input the object to be transformed, should be left unchanged 054 * @return a transformed object 055 * @throws ClassCastException (runtime) if the input is the wrong class 056 * @throws IllegalArgumentException (runtime) if the input is invalid 057 * @throws FunctorException (runtime) if the transform cannot be completed 058 */ 059 R transform(T input); 060 061}