Last active
February 18, 2016 11:55
-
-
Save dilnei/b000dec72dbfff4e2b89 to your computer and use it in GitHub Desktop.
Transformation class to populate the data in XML, following the pattern Transfer Object Assembler.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package br.com.appweb.model.assembler; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| import com.google.common.base.Function; | |
| /** | |
| * Transformation class to populate the data in XML, following the pattern | |
| * Transfer Object Assembler. | |
| * | |
| * @author Dilnei_Cunha | |
| */ | |
| public class Transformer { | |
| /** | |
| * Execute the transformation of an object to an XML. | |
| * | |
| * @param from | |
| * @param function | |
| * @return <F, T> T | |
| */ | |
| public static <F, T> T transform(F from, Function<? super F, ? extends T> function) { | |
| return (from == null) ? null : function.apply(from); | |
| } | |
| /** | |
| * Execute the transformation of a list of objects to a list of XML. | |
| * | |
| * @param fromList | |
| * @param function | |
| * @return <F, T> List<T> | |
| */ | |
| public static <F, T> List<T> transform(List<F> source, Function<? super F, ? extends T> function) { | |
| List<T> out = new ArrayList<>(source.size()); | |
| for (F from : source) { | |
| out.add(function.apply(from)); | |
| } | |
| return out; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment