Home | History | Annotate | Download | only in codegen
      1 /*
      2  * Copyright (C) 2014 Google, Inc.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package dagger.internal.codegen;
     17 
     18 import com.google.common.base.Function;
     19 
     20 /**
     21  * A formatter which transforms an instance of a particular type into a string
     22  * representation.
     23  *
     24  * @param <T> the type of the object to be transformed.
     25  * @author Christian Gruber
     26  * @since 2.0
     27  */
     28 abstract class Formatter<T> implements Function<T, String> {
     29 
     30   /**
     31    * Performs the transformation of an object into a string representation.
     32    */
     33   public abstract String format(T object);
     34 
     35   /**
     36    * Performs the transformation of an object into a string representation in
     37    * conformity with the {@link Function}{@code <T, String>} contract, delegating
     38    * to {@link #format(Object)}.
     39    *
     40    * @deprecated Call {@link #format(T)} instead.  This method exists to make
     41    * formatters easy to use when functions are required, but shouldn't be called directly.
     42    */
     43   @SuppressWarnings("javadoc")
     44   @Deprecated
     45   @Override final public String apply(T object) {
     46     return format(object);
     47   }
     48 }
     49