Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public class Converter private final Function from Dto; private final Function fromEntity; /** * Constructor. * @param from Dto Function that converts given dto entity
public class Converter private final Function from Dto; private final Function fromEntity; /** * Constructor. * @param from Dto Function that converts given dto entity into the domain entity. * @param fromEntity Function that converts given domain entity into the dto entity. */ public Converter(Final Function from Dto, final Function fromEntity) ( this.fromDto = from Dto; this.fromEntity = fromEntity; } /** * Converts DTO to Entity. * * @param dto DTO entity * @return The domain representation - the result of the converting function application on dto entity. *7 public final U convertFromDto(final T dto) ! return from Dto.apply(dto); } * Converts Entity to DTO. * @param entity domain entity * @return The DTO representation - the result of the converting function application on domain entity. / public final T convertFromEntity(final U entity) { return fromEntity.apply(entity); 3 /** * Converts list of DTOs to list of Entities. @param dtos collection of DTO entities * @return List of domain representation of provided entities retrieved by mapping each of them with the conversion function *1 public final List createFromDtos(final Collection dtos) { return dtos.stream().map(this::convertFrom Dto).collect(Collectors.toList(); 3 /** * Converts list of Entities to list of DTOS. * @param entities collection of domain entities * @return List of domain representation of provided entities retrieved by mapping each of them with the conversion function */ public final List createFromEntities(final Collection entities) return entities.stream().map(this::convertFromEntity).collect(Collectors.toList()); ) 3 public class Converter private final Function from Dto; private final Function fromEntity; /** * Constructor. * @param from Dto Function that converts given dto entity into the domain entity. * @param fromEntity Function that converts given domain entity into the dto entity. */ public Converter(Final Function from Dto, final Function fromEntity) ( this.fromDto = from Dto; this.fromEntity = fromEntity; } /** * Converts DTO to Entity. * * @param dto DTO entity * @return The domain representation - the result of the converting function application on dto entity. *7 public final U convertFromDto(final T dto) ! return from Dto.apply(dto); } * Converts Entity to DTO. * @param entity domain entity * @return The DTO representation - the result of the converting function application on domain entity. / public final T convertFromEntity(final U entity) { return fromEntity.apply(entity); 3 /** * Converts list of DTOs to list of Entities. @param dtos collection of DTO entities * @return List of domain representation of provided entities retrieved by mapping each of them with the conversion function *1 public final List createFromDtos(final Collection dtos) { return dtos.stream().map(this::convertFrom Dto).collect(Collectors.toList(); 3 /** * Converts list of Entities to list of DTOS. * @param entities collection of domain entities * @return List of domain representation of provided entities retrieved by mapping each of them with the conversion function */ public final List createFromEntities(final Collection entities) return entities.stream().map(this::convertFromEntity).collect(Collectors.toList()); ) 3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started