Source:
public ProductDTO populate( ModelTranslator modelTranslator, ProductData source, ProductDTO dest) { if (source == null) { throw new IllegalArgumentException("source is null"); } if (dest == null) { throw new IllegalArgumentException("dest is null"); } dest.id(source.getId()) .uuid(source.getUuid()) .name(source.getName()) .multiplier(source.getMultiplier()) .created(Util.toDateTime(source.getCreated())) .updated(Util.toDateTime(source.getUpdated())) .attributes(toAttributes(source.getAttributes())) .productContent(new HashSet<>()) .branding(new HashSet<>()) .dependentProductIds(toSet(source)) .href(source.getHref()) .locked(source.isLocked()); if (modelTranslator != null) { Collection<ProductContentData> productContentData = source.getProductContent(); if (productContentData != null && !productContentData.isEmpty()) { ObjectTranslator<ContentData, ContentDTO> contentTranslator = modelTranslator .findTranslatorByClass(ContentData.class, ContentDTO.class); Set<ProductContentDTO> dtos = new HashSet<>(); for (ProductContentData productContent : productContentData) { if (productContent != null && productContent.getContent() != null) { ContentDTO dto = contentTranslator .translate(modelTranslator, productContent.getContent()); dtos.add(createContent(dto, productContent.isEnabled())); } } dest.productContent(dtos); } else { dest.productContent(Collections.emptySet()); } Collection<Branding> productBrandings = source.getBranding(); if (productBrandings != null && !productBrandings.isEmpty()) { Set<BrandingDTO> dtos = new HashSet<>(); for (Branding brand : productBrandings) { if (brand != null) { BrandingDTO dto = modelTranslator.translate(brand, BrandingDTO.class); if (isNullOrIncomplete(dto)) { throw new IllegalArgumentException("branding is null or incomplete"); } dtos.add(dto); } } dest.setBranding(dtos); } else { dest.setBranding(Collections.emptySet()); } } return dest; }

Target:
public ProductDTO populate( ModelTranslator modelTranslator, ProductData source, ProductDTO dest) { if (source == null) { throw new IllegalArgumentException("source is null"); } if (dest == null) { throw new IllegalArgumentException("dest is null"); } dest.id(source.getId()) .uuid(source.getUuid()) .name(source.getName()) .multiplier(source.getMultiplier()) .created(Util.toDateTime(source.getCreated())) .updated(Util.toDateTime(source.getUpdated())) .attributes(toAttributes(source.getAttributes())) .productContent(new HashSet<>()) .branding(new HashSet<>()) .dependentProductIds(toSet(source)) .href(source.getHref()); if (modelTranslator != null) { Collection<ProductContentData> productContentData = source.getProductContent(); if (productContentData != null && !productContentData.isEmpty()) { ObjectTranslator<ContentData, ContentDTO> contentTranslator = modelTranslator .findTranslatorByClass(ContentData.class, ContentDTO.class); Set<ProductContentDTO> dtos = new HashSet<>(); for (ProductContentData productContent : productContentData) { if (productContent != null && productContent.getContent() != null) { ContentDTO dto = contentTranslator .translate(modelTranslator, productContent.getContent()); dtos.add(createContent(dto, productContent.isEnabled())); } } dest.productContent(dtos); } else { dest.productContent(Collections.emptySet()); } Collection<Branding> productBrandings = source.getBranding(); if (productBrandings != null && !productBrandings.isEmpty()) { Set<BrandingDTO> dtos = new HashSet<>(); for (Branding brand : productBrandings) { if (brand != null) { dtos.add(modelTranslator.translate(brand, BrandingDTO.class)); } } dest.setBranding(dtos); } else { dest.setBranding(Collections.emptySet()); } } return dest; }