Source:
public ProductDTO populate(ModelTranslator modelTranslator, Product source, ProductDTO destination) { if (source == null) { throw new IllegalArgumentException("source is null"); } if (destination == null) { throw new IllegalArgumentException("destination is null"); } destination.created(Util.toDateTime(source.getCreated())) .updated(Util.toDateTime(source.getUpdated())) .uuid(source.getUuid()) .id(source.getId()) .name(source.getName()) .multiplier(source.getMultiplier()) .href(source.getHref()) .locked(source.isLocked()) .attributes(createAttributes(source.getAttributes())) .productContent(new HashSet<>()) .branding(new HashSet<>()) .dependentProductIds(new HashSet<>(source.getDependentProductIds())); if (modelTranslator != null) { Collection<ProductContent> productContent = source.getProductContent(); if (productContent != null) { ObjectTranslator<ProductContent, ProductContentDTO> contentTranslator = modelTranslator .findTranslatorByClass(ProductContent.class, ProductContentDTO.class); Set<ProductContentDTO> content = new HashSet<>(); for (ProductContent pc : productContent) { if (pc != null) { ProductContentDTO dto = contentTranslator.translate(modelTranslator, pc); if (dto != null) { content.add(dto); } } } destination.productContent(content); } else { destination.productContent(Collections.emptySet()); } Collection<Branding> branding = source.getBranding(); if (branding != null && !branding.isEmpty()) { for (Branding brand : branding) { if (brand != null) { addBranding(destination, modelTranslator.translate(brand, BrandingDTO.class)); } } } else { destination.setBranding(Collections.emptySet()); } } else { destination.productContent(Collections.emptySet()); destination.setBranding(Collections.emptySet()); } return destination; }

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