de.alpharogroup.bean.mapper.ModelMapperExtensions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of generic-mapper Show documentation
Show all versions of generic-mapper Show documentation
Project for map classes with dozer in a generic way
The newest version!
/**
* The MIT License
*
* Copyright (C) 2015 Asterios Raptis
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package de.alpharogroup.bean.mapper;
import org.modelmapper.ModelMapper;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* The class {@link ModelMapperExtensions}.
*/
public final class ModelMapperExtensions
{
/**
* Constructs new instances of destinationClass and performs mapping between from source.
*
* @param the generic type of the destinationClass
* @param the generic type of the source
* @param mapper the dozer mapper object
* @param sources the collection of source objects
* @param destinationClass the destination class
* @return the new instance of destinationClass mapped to source object.
*/
public static List map(final ModelMapper mapper, final Collection sources,
final Class destinationClass)
{
final List destination = new ArrayList<>();
if ((sources != null) && !sources.isEmpty())
{
for (final S source : sources)
{
destination.add(ModelMapperExtensions.map(mapper, source, destinationClass));
}
}
return destination;
}
/**
* Constructs new instance of destinationClass and performs mapping between from source.
*
* @param
* the generic type of the destinationClass
* @param
* the generic type of the source
* @param mapper
* the dozer mapper object
* @param source
* the source
* @param destinationClass
* the destination class
* @return the new instance of destinationClass mapped to source object.
*/
public static T map(final ModelMapper mapper, final S source,
final Class destinationClass)
{
return mapper.map(source, destinationClass);
}
}