#3113 Use LinkedHashSet, LinkedHashSet new factory methods for java >= 19

This commit is contained in:
Obolrom 2024-09-02 11:26:48 +03:00 committed by GitHub
parent 23f4802374
commit 4d9894ba25
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 1605 additions and 19 deletions

View File

@ -16,23 +16,34 @@ public class ImplementationType {
private final Type type;
private final boolean initialCapacityConstructor;
private final boolean loadFactorAdjustment;
private final String factoryMethodName;
private ImplementationType(Type type, boolean initialCapacityConstructor, boolean loadFactorAdjustment) {
private ImplementationType(
Type type,
boolean initialCapacityConstructor,
boolean loadFactorAdjustment,
String factoryMethodName
) {
this.type = type;
this.initialCapacityConstructor = initialCapacityConstructor;
this.loadFactorAdjustment = loadFactorAdjustment;
this.factoryMethodName = factoryMethodName;
}
public static ImplementationType withDefaultConstructor(Type type) {
return new ImplementationType( type, false, false );
return new ImplementationType( type, false, false, null );
}
public static ImplementationType withInitialCapacity(Type type) {
return new ImplementationType( type, true, false );
return new ImplementationType( type, true, false, null );
}
public static ImplementationType withLoadFactorAdjustment(Type type) {
return new ImplementationType( type, true, true );
return new ImplementationType( type, true, true, null );
}
public static ImplementationType withFactoryMethod(Type type, String factoryMethodName) {
return new ImplementationType( type, true, false, factoryMethodName );
}
/**
@ -44,7 +55,7 @@ public class ImplementationType {
* @return a new implementation type with the given {@code type}
*/
public ImplementationType createNew(Type type) {
return new ImplementationType( type, initialCapacityConstructor, loadFactorAdjustment );
return new ImplementationType( type, initialCapacityConstructor, loadFactorAdjustment, factoryMethodName );
}
/**
@ -71,4 +82,8 @@ public class ImplementationType {
public boolean isLoadFactorAdjustment() {
return loadFactorAdjustment;
}
public String getFactoryMethodName() {
return factoryMethodName;
}
}

View File

@ -38,12 +38,11 @@ import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.TypeVariable;
import javax.lang.model.type.WildcardType;
import org.mapstruct.ap.internal.util.ElementUtils;
import org.mapstruct.ap.internal.util.TypeUtils;
import org.mapstruct.ap.internal.gem.BuilderGem;
import org.mapstruct.ap.internal.util.AnnotationProcessingException;
import org.mapstruct.ap.internal.util.Collections;
import org.mapstruct.ap.internal.util.ElementUtils;
import org.mapstruct.ap.internal.util.Extractor;
import org.mapstruct.ap.internal.util.FormattingMessager;
import org.mapstruct.ap.internal.util.JavaStreamConstants;
@ -51,13 +50,16 @@ import org.mapstruct.ap.internal.util.Message;
import org.mapstruct.ap.internal.util.NativeTypes;
import org.mapstruct.ap.internal.util.RoundContext;
import org.mapstruct.ap.internal.util.Strings;
import org.mapstruct.ap.internal.util.TypeUtils;
import org.mapstruct.ap.internal.util.accessor.Accessor;
import org.mapstruct.ap.internal.version.VersionInformation;
import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor;
import org.mapstruct.ap.spi.BuilderInfo;
import org.mapstruct.ap.spi.MoreThanOneBuilderCreationMethodException;
import org.mapstruct.ap.spi.TypeHierarchyErroneousException;
import static org.mapstruct.ap.internal.model.common.ImplementationType.withDefaultConstructor;
import static org.mapstruct.ap.internal.model.common.ImplementationType.withFactoryMethod;
import static org.mapstruct.ap.internal.model.common.ImplementationType.withInitialCapacity;
import static org.mapstruct.ap.internal.model.common.ImplementationType.withLoadFactorAdjustment;
@ -82,6 +84,8 @@ public class TypeFactory {
sb.append( ')' );
return sb.toString();
};
private static final String LINKED_HASH_SET_FACTORY_METHOD_NAME = "newLinkedHashSet";
private static final String LINKED_HASH_MAP_FACTORY_METHOD_NAME = "newLinkedHashMap";
private final ElementUtils elementUtils;
private final TypeUtils typeUtils;
@ -100,7 +104,8 @@ public class TypeFactory {
private final boolean loggingVerbose;
public TypeFactory(ElementUtils elementUtils, TypeUtils typeUtils, FormattingMessager messager,
RoundContext roundContext, Map<String, String> notToBeImportedTypes, boolean loggingVerbose) {
RoundContext roundContext, Map<String, String> notToBeImportedTypes, boolean loggingVerbose,
VersionInformation versionInformation) {
this.elementUtils = elementUtils;
this.typeUtils = typeUtils;
this.messager = messager;
@ -118,11 +123,22 @@ public class TypeFactory {
implementationTypes.put( Collection.class.getName(), withInitialCapacity( getType( ArrayList.class ) ) );
implementationTypes.put( List.class.getName(), withInitialCapacity( getType( ArrayList.class ) ) );
implementationTypes.put( Set.class.getName(), withLoadFactorAdjustment( getType( LinkedHashSet.class ) ) );
boolean sourceVersionAtLeast19 = versionInformation.isSourceVersionAtLeast19();
implementationTypes.put(
Set.class.getName(),
sourceVersionAtLeast19 ?
withFactoryMethod( getType( LinkedHashSet.class ), LINKED_HASH_SET_FACTORY_METHOD_NAME ) :
withLoadFactorAdjustment( getType( LinkedHashSet.class ) )
);
implementationTypes.put( SortedSet.class.getName(), withDefaultConstructor( getType( TreeSet.class ) ) );
implementationTypes.put( NavigableSet.class.getName(), withDefaultConstructor( getType( TreeSet.class ) ) );
implementationTypes.put( Map.class.getName(), withLoadFactorAdjustment( getType( LinkedHashMap.class ) ) );
implementationTypes.put(
Map.class.getName(),
sourceVersionAtLeast19 ?
withFactoryMethod( getType( LinkedHashMap.class ), LINKED_HASH_MAP_FACTORY_METHOD_NAME ) :
withLoadFactorAdjustment( getType( LinkedHashMap.class ) )
);
implementationTypes.put( SortedMap.class.getName(), withDefaultConstructor( getType( TreeMap.class ) ) );
implementationTypes.put( NavigableMap.class.getName(), withDefaultConstructor( getType( TreeMap.class ) ) );
implementationTypes.put(

View File

@ -62,7 +62,8 @@ public class DefaultModelElementProcessorContext implements ProcessorContext {
messager,
roundContext,
notToBeImported,
options.isVerbose()
options.isVerbose(),
versionInformation
);
this.options = options;
}

View File

@ -41,6 +41,7 @@ public class DefaultVersionInformation implements VersionInformation {
private final String runtimeVendor;
private final String compiler;
private final boolean sourceVersionAtLeast9;
private final boolean sourceVersionAtLeast19;
private final boolean eclipseJDT;
private final boolean javac;
@ -53,6 +54,7 @@ public class DefaultVersionInformation implements VersionInformation {
this.javac = compiler.startsWith( COMPILER_NAME_JAVAC );
// If the difference between the source version and RELEASE_6 is more that 2 than we are at least on 9
this.sourceVersionAtLeast9 = sourceVersion.compareTo( SourceVersion.RELEASE_6 ) > 2;
this.sourceVersionAtLeast19 = sourceVersion.compareTo( SourceVersion.RELEASE_6 ) > 12;
}
@Override
@ -80,6 +82,11 @@ public class DefaultVersionInformation implements VersionInformation {
return sourceVersionAtLeast9;
}
@Override
public boolean isSourceVersionAtLeast19() {
return sourceVersionAtLeast19;
}
@Override
public boolean isEclipseJDTCompiler() {
return eclipseJDT;

View File

@ -21,6 +21,8 @@ public interface VersionInformation {
boolean isSourceVersionAtLeast9();
boolean isSourceVersionAtLeast19();
boolean isEclipseJDTCompiler();
boolean isJavacCompiler();

View File

@ -11,13 +11,15 @@
<@includeModel object=factoryMethod targetType=resultType/>
<#elseif enumSet>
EnumSet.noneOf( <@includeModel object=enumSetElementType raw=true/>.class )
<#else>
new
<#if resultType.implementationType??>
<@includeModel object=resultType.implementationType/><#if ext.useSizeIfPossible?? && ext.useSizeIfPossible && canUseSize>( <@sizeForCreation /> )<#else>()</#if>
<#elseif resultType.implementation??>
<#if resultType.implementation.factoryMethodName?? && ext.useSizeIfPossible?? && ext.useSizeIfPossible && canUseSize>
<@includeModel object=resultType.implementationType raw=true />.${resultType.implementation.factoryMethodName}( <@sizeForCreation /> )
<#else>
<@includeModel object=resultType/>()</#if>
new <@includeModel object=resultType.implementationType/><#if ext.useSizeIfPossible?? && ext.useSizeIfPossible && canUseSize>( <@sizeForCreation /> )<#else>()</#if>
</#if>
<#else>
new <@includeModel object=resultType/>()
</#if>
</@compress>
<#macro sizeForCreation>
<@compress single_line=true>

View File

@ -76,4 +76,8 @@ public class CompilationRequest {
public Collection<String> getTestDependencies() {
return testDependencies;
}
public Compiler getCompiler() {
return compiler;
}
}

View File

@ -44,12 +44,15 @@ public class GeneratedSource implements BeforeTestExecutionCallback, AfterTestEx
*/
private ThreadLocal<String> sourceOutputDir = new ThreadLocal<>();
private Compiler compiler;
private List<Class<?>> fixturesFor = new ArrayList<>();
@Override
public void beforeTestExecution(ExtensionContext context) throws Exception {
CompilationRequest compilationRequest = context.getStore( NAMESPACE )
.get( context.getUniqueId() + "-compilationRequest", CompilationRequest.class );
this.compiler = compilationRequest.getCompiler();
setSourceOutputDir( context.getStore( NAMESPACE )
.get( compilationRequest, CompilationCache.class )
.getLastSourceOutputDir() );
@ -118,13 +121,13 @@ public class GeneratedSource implements BeforeTestExecutionCallback, AfterTestEx
private void handleFixtureComparison() throws UnsupportedEncodingException {
for ( Class<?> fixture : fixturesFor ) {
String expectedFixture = FIXTURES_ROOT + getMapperName( fixture );
URL expectedFile = getClass().getClassLoader().getResource( expectedFixture );
String fixtureName = getMapperName( fixture );
URL expectedFile = getExpectedResource( fixtureName );
if ( expectedFile == null ) {
fail( String.format(
"No reference file could be found for Mapper %s. You should create a file %s",
fixture.getName(),
expectedFixture
FIXTURES_ROOT + fixtureName
) );
}
else {
@ -135,4 +138,16 @@ public class GeneratedSource implements BeforeTestExecutionCallback, AfterTestEx
}
}
private URL getExpectedResource( String fixtureName ) {
ClassLoader classLoader = getClass().getClassLoader();
for ( int version = Runtime.version().feature(); version >= 11 && compiler != Compiler.ECLIPSE; version-- ) {
URL resource = classLoader.getResource( FIXTURES_ROOT + "/" + version + "/" + fixtureName );
if ( resource != null ) {
return resource;
}
}
return classLoader.getResource( FIXTURES_ROOT + fixtureName );
}
}

View File

@ -0,0 +1,139 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._1453;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.processing.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-06-18T14:48:39+0200",
comments = "version: , compiler: javac, environment: Java 21.0.2 (Eclipse Adoptium)"
)
public class Issue1453MapperImpl implements Issue1453Mapper {
@Override
public AuctionDto map(Auction auction) {
if ( auction == null ) {
return null;
}
AuctionDto auctionDto = new AuctionDto();
auctionDto.setPayments( paymentListToPaymentDtoList( auction.getPayments() ) );
auctionDto.setOtherPayments( paymentListToPaymentDtoList( auction.getOtherPayments() ) );
auctionDto.setMapPayments( paymentPaymentMapToPaymentDtoPaymentDtoMap( auction.getMapPayments() ) );
auctionDto.setMapSuperPayments( paymentPaymentMapToPaymentDtoPaymentDtoMap( auction.getMapSuperPayments() ) );
return auctionDto;
}
@Override
public List<AuctionDto> mapExtend(List<? extends Auction> auctions) {
if ( auctions == null ) {
return null;
}
List<AuctionDto> list = new ArrayList<AuctionDto>( auctions.size() );
for ( Auction auction : auctions ) {
list.add( map( auction ) );
}
return list;
}
@Override
public List<? super AuctionDto> mapSuper(List<Auction> auctions) {
if ( auctions == null ) {
return null;
}
List<? super AuctionDto> list = new ArrayList<AuctionDto>( auctions.size() );
for ( Auction auction : auctions ) {
list.add( map( auction ) );
}
return list;
}
@Override
public Map<AuctionDto, AuctionDto> mapExtend(Map<? extends Auction, ? extends Auction> auctions) {
if ( auctions == null ) {
return null;
}
Map<AuctionDto, AuctionDto> map = LinkedHashMap.newLinkedHashMap( auctions.size() );
for ( java.util.Map.Entry<? extends Auction, ? extends Auction> entry : auctions.entrySet() ) {
AuctionDto key = map( entry.getKey() );
AuctionDto value = map( entry.getValue() );
map.put( key, value );
}
return map;
}
@Override
public Map<? super AuctionDto, ? super AuctionDto> mapSuper(Map<Auction, Auction> auctions) {
if ( auctions == null ) {
return null;
}
Map<? super AuctionDto, ? super AuctionDto> map = LinkedHashMap.newLinkedHashMap( auctions.size() );
for ( java.util.Map.Entry<Auction, Auction> entry : auctions.entrySet() ) {
AuctionDto key = map( entry.getKey() );
AuctionDto value = map( entry.getValue() );
map.put( key, value );
}
return map;
}
protected PaymentDto paymentToPaymentDto(Payment payment) {
if ( payment == null ) {
return null;
}
PaymentDto paymentDto = new PaymentDto();
paymentDto.setPrice( payment.getPrice() );
return paymentDto;
}
protected List<PaymentDto> paymentListToPaymentDtoList(List<Payment> list) {
if ( list == null ) {
return null;
}
List<PaymentDto> list1 = new ArrayList<PaymentDto>( list.size() );
for ( Payment payment : list ) {
list1.add( paymentToPaymentDto( payment ) );
}
return list1;
}
protected Map<PaymentDto, PaymentDto> paymentPaymentMapToPaymentDtoPaymentDtoMap(Map<Payment, Payment> map) {
if ( map == null ) {
return null;
}
Map<PaymentDto, PaymentDto> map1 = LinkedHashMap.newLinkedHashMap( map.size() );
for ( java.util.Map.Entry<Payment, Payment> entry : map.entrySet() ) {
PaymentDto key = paymentToPaymentDto( entry.getKey() );
PaymentDto value = paymentToPaymentDto( entry.getValue() );
map1.put( key, value );
}
return map1;
}
}

View File

@ -0,0 +1,85 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._3591;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Stream;
import javax.annotation.processing.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-05-25T14:23:23+0200",
comments = "version: , compiler: javac, environment: Java 21.0.2 (Eclipse Adoptium)"
)
public class ContainerBeanMapperImpl implements ContainerBeanMapper {
@Override
public ContainerBeanDto mapWithMapMapping(ContainerBean containerBean, ContainerBeanDto containerBeanDto) {
if ( containerBean == null ) {
return containerBeanDto;
}
if ( containerBeanDto.getBeanMap() != null ) {
Map<String, ContainerBeanDto> map = stringContainerBeanMapToStringContainerBeanDtoMap( containerBean.getBeanMap() );
if ( map != null ) {
containerBeanDto.getBeanMap().clear();
containerBeanDto.getBeanMap().putAll( map );
}
else {
containerBeanDto.setBeanMap( null );
}
}
else {
Map<String, ContainerBeanDto> map = stringContainerBeanMapToStringContainerBeanDtoMap( containerBean.getBeanMap() );
if ( map != null ) {
containerBeanDto.setBeanMap( map );
}
}
containerBeanDto.setBeanStream( containerBeanStreamToContainerBeanDtoStream( containerBean.getBeanStream() ) );
containerBeanDto.setValue( containerBean.getValue() );
return containerBeanDto;
}
protected Stream<ContainerBeanDto> containerBeanStreamToContainerBeanDtoStream(Stream<ContainerBean> stream) {
if ( stream == null ) {
return null;
}
return stream.map( containerBean -> containerBeanToContainerBeanDto( containerBean ) );
}
protected ContainerBeanDto containerBeanToContainerBeanDto(ContainerBean containerBean) {
if ( containerBean == null ) {
return null;
}
ContainerBeanDto containerBeanDto = new ContainerBeanDto();
containerBeanDto.setBeanMap( stringContainerBeanMapToStringContainerBeanDtoMap( containerBean.getBeanMap() ) );
containerBeanDto.setBeanStream( containerBeanStreamToContainerBeanDtoStream( containerBean.getBeanStream() ) );
containerBeanDto.setValue( containerBean.getValue() );
return containerBeanDto;
}
protected Map<String, ContainerBeanDto> stringContainerBeanMapToStringContainerBeanDtoMap(Map<String, ContainerBean> map) {
if ( map == null ) {
return null;
}
Map<String, ContainerBeanDto> map1 = LinkedHashMap.newLinkedHashMap( map.size() );
for ( java.util.Map.Entry<String, ContainerBean> entry : map.entrySet() ) {
String key = entry.getKey();
ContainerBeanDto value = containerBeanToContainerBeanDto( entry.getValue() );
map1.put( key, value );
}
return map1;
}
}

View File

@ -0,0 +1,214 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._913;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.processing.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-06-19T11:20:01+0300",
comments = "version: , compiler: javac, environment: Java 21.0.2 (Amazon.com Inc.)"
)
public class DomainDtoWithNcvsAlwaysMapperImpl implements DomainDtoWithNcvsAlwaysMapper {
private final Helper helper = new Helper();
@Override
public Domain create(DtoWithPresenceCheck source) {
if ( source == null ) {
return null;
}
Domain domain = createNullDomain();
if ( source.hasStrings() ) {
List<String> list = source.getStrings();
domain.setStrings( new LinkedHashSet<String>( list ) );
}
if ( source.hasStrings() ) {
domain.setLongs( stringListToLongSet( source.getStrings() ) );
}
if ( source.hasStringsInitialized() ) {
List<String> list1 = source.getStringsInitialized();
domain.setStringsInitialized( new LinkedHashSet<String>( list1 ) );
}
if ( source.hasStringsInitialized() ) {
domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) );
}
if ( source.hasStringsWithDefault() ) {
List<String> list2 = source.getStringsWithDefault();
domain.setStringsWithDefault( new ArrayList<String>( list2 ) );
}
else {
domain.setStringsWithDefault( helper.toList( "3" ) );
}
return domain;
}
@Override
public void update(DtoWithPresenceCheck source, Domain target) {
if ( source == null ) {
return;
}
if ( target.getStrings() != null ) {
if ( source.hasStrings() ) {
target.getStrings().clear();
target.getStrings().addAll( source.getStrings() );
}
}
else {
if ( source.hasStrings() ) {
List<String> list = source.getStrings();
target.setStrings( new LinkedHashSet<String>( list ) );
}
}
if ( target.getLongs() != null ) {
if ( source.hasStrings() ) {
target.getLongs().clear();
target.getLongs().addAll( stringListToLongSet( source.getStrings() ) );
}
}
else {
if ( source.hasStrings() ) {
target.setLongs( stringListToLongSet( source.getStrings() ) );
}
}
if ( target.getStringsInitialized() != null ) {
if ( source.hasStringsInitialized() ) {
target.getStringsInitialized().clear();
target.getStringsInitialized().addAll( source.getStringsInitialized() );
}
}
else {
if ( source.hasStringsInitialized() ) {
List<String> list1 = source.getStringsInitialized();
target.setStringsInitialized( new LinkedHashSet<String>( list1 ) );
}
}
if ( target.getLongsInitialized() != null ) {
if ( source.hasStringsInitialized() ) {
target.getLongsInitialized().clear();
target.getLongsInitialized().addAll( stringListToLongSet( source.getStringsInitialized() ) );
}
}
else {
if ( source.hasStringsInitialized() ) {
target.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) );
}
}
if ( target.getStringsWithDefault() != null ) {
if ( source.hasStringsWithDefault() ) {
target.getStringsWithDefault().clear();
target.getStringsWithDefault().addAll( source.getStringsWithDefault() );
}
else {
target.setStringsWithDefault( helper.toList( "3" ) );
}
}
else {
if ( source.hasStringsWithDefault() ) {
List<String> list2 = source.getStringsWithDefault();
target.setStringsWithDefault( new ArrayList<String>( list2 ) );
}
else {
target.setStringsWithDefault( helper.toList( "3" ) );
}
}
}
@Override
public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) {
if ( source == null ) {
return target;
}
if ( target.getStrings() != null ) {
if ( source.hasStrings() ) {
target.getStrings().clear();
target.getStrings().addAll( source.getStrings() );
}
}
else {
if ( source.hasStrings() ) {
List<String> list = source.getStrings();
target.setStrings( new LinkedHashSet<String>( list ) );
}
}
if ( target.getLongs() != null ) {
if ( source.hasStrings() ) {
target.getLongs().clear();
target.getLongs().addAll( stringListToLongSet( source.getStrings() ) );
}
}
else {
if ( source.hasStrings() ) {
target.setLongs( stringListToLongSet( source.getStrings() ) );
}
}
if ( target.getStringsInitialized() != null ) {
if ( source.hasStringsInitialized() ) {
target.getStringsInitialized().clear();
target.getStringsInitialized().addAll( source.getStringsInitialized() );
}
}
else {
if ( source.hasStringsInitialized() ) {
List<String> list1 = source.getStringsInitialized();
target.setStringsInitialized( new LinkedHashSet<String>( list1 ) );
}
}
if ( target.getLongsInitialized() != null ) {
if ( source.hasStringsInitialized() ) {
target.getLongsInitialized().clear();
target.getLongsInitialized().addAll( stringListToLongSet( source.getStringsInitialized() ) );
}
}
else {
if ( source.hasStringsInitialized() ) {
target.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) );
}
}
if ( target.getStringsWithDefault() != null ) {
if ( source.hasStringsWithDefault() ) {
target.getStringsWithDefault().clear();
target.getStringsWithDefault().addAll( source.getStringsWithDefault() );
}
else {
target.setStringsWithDefault( helper.toList( "3" ) );
}
}
else {
if ( source.hasStringsWithDefault() ) {
List<String> list2 = source.getStringsWithDefault();
target.setStringsWithDefault( new ArrayList<String>( list2 ) );
}
else {
target.setStringsWithDefault( helper.toList( "3" ) );
}
}
return target;
}
protected Set<Long> stringListToLongSet(List<String> list) {
if ( list == null ) {
return null;
}
Set<Long> set = LinkedHashSet.newLinkedHashSet( list.size() );
for ( String string : list ) {
set.add( Long.parseLong( string ) );
}
return set;
}
}

View File

@ -0,0 +1,245 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._913;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.processing.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-06-18T14:48:39+0200",
comments = "version: , compiler: javac, environment: Java 21.0.2 (Eclipse Adoptium)"
)
public class DomainDtoWithNvmsDefaultMapperImpl implements DomainDtoWithNvmsDefaultMapper {
private final Helper helper = new Helper();
@Override
public Domain create(Dto source) {
Domain domain = new Domain();
if ( source != null ) {
List<String> list = source.getStrings();
if ( list != null ) {
domain.setStrings( new LinkedHashSet<String>( list ) );
}
domain.setLongs( stringListToLongSet( source.getStrings() ) );
List<String> list1 = source.getStringsInitialized();
if ( list1 != null ) {
domain.setStringsInitialized( new LinkedHashSet<String>( list1 ) );
}
domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) );
List<String> list2 = source.getStringsWithDefault();
if ( list2 != null ) {
domain.setStringsWithDefault( new ArrayList<String>( list2 ) );
}
else {
domain.setStringsWithDefault( helper.toList( "3" ) );
}
}
return domain;
}
@Override
public void update(Dto source, Domain target) {
if ( source != null ) {
if ( target.getStrings() != null ) {
List<String> list = source.getStrings();
if ( list != null ) {
target.getStrings().clear();
target.getStrings().addAll( list );
}
else {
target.setStrings( new LinkedHashSet<String>() );
}
}
else {
List<String> list = source.getStrings();
if ( list != null ) {
target.setStrings( new LinkedHashSet<String>( list ) );
}
}
if ( target.getLongs() != null ) {
Set<Long> set = stringListToLongSet( source.getStrings() );
if ( set != null ) {
target.getLongs().clear();
target.getLongs().addAll( set );
}
else {
target.setLongs( new LinkedHashSet<Long>() );
}
}
else {
Set<Long> set = stringListToLongSet( source.getStrings() );
if ( set != null ) {
target.setLongs( set );
}
}
if ( target.getStringsInitialized() != null ) {
List<String> list1 = source.getStringsInitialized();
if ( list1 != null ) {
target.getStringsInitialized().clear();
target.getStringsInitialized().addAll( list1 );
}
else {
target.setStringsInitialized( new LinkedHashSet<String>() );
}
}
else {
List<String> list1 = source.getStringsInitialized();
if ( list1 != null ) {
target.setStringsInitialized( new LinkedHashSet<String>( list1 ) );
}
}
if ( target.getLongsInitialized() != null ) {
Set<Long> set1 = stringListToLongSet( source.getStringsInitialized() );
if ( set1 != null ) {
target.getLongsInitialized().clear();
target.getLongsInitialized().addAll( set1 );
}
else {
target.setLongsInitialized( new LinkedHashSet<Long>() );
}
}
else {
Set<Long> set1 = stringListToLongSet( source.getStringsInitialized() );
if ( set1 != null ) {
target.setLongsInitialized( set1 );
}
}
if ( target.getStringsWithDefault() != null ) {
List<String> list2 = source.getStringsWithDefault();
if ( list2 != null ) {
target.getStringsWithDefault().clear();
target.getStringsWithDefault().addAll( list2 );
}
else {
target.setStringsWithDefault( helper.toList( "3" ) );
}
}
else {
List<String> list2 = source.getStringsWithDefault();
if ( list2 != null ) {
target.setStringsWithDefault( new ArrayList<String>( list2 ) );
}
else {
target.setStringsWithDefault( helper.toList( "3" ) );
}
}
}
}
@Override
public Domain updateWithReturn(Dto source, Domain target) {
if ( source != null ) {
if ( target.getStrings() != null ) {
List<String> list = source.getStrings();
if ( list != null ) {
target.getStrings().clear();
target.getStrings().addAll( list );
}
else {
target.setStrings( new LinkedHashSet<String>() );
}
}
else {
List<String> list = source.getStrings();
if ( list != null ) {
target.setStrings( new LinkedHashSet<String>( list ) );
}
}
if ( target.getLongs() != null ) {
Set<Long> set = stringListToLongSet( source.getStrings() );
if ( set != null ) {
target.getLongs().clear();
target.getLongs().addAll( set );
}
else {
target.setLongs( new LinkedHashSet<Long>() );
}
}
else {
Set<Long> set = stringListToLongSet( source.getStrings() );
if ( set != null ) {
target.setLongs( set );
}
}
if ( target.getStringsInitialized() != null ) {
List<String> list1 = source.getStringsInitialized();
if ( list1 != null ) {
target.getStringsInitialized().clear();
target.getStringsInitialized().addAll( list1 );
}
else {
target.setStringsInitialized( new LinkedHashSet<String>() );
}
}
else {
List<String> list1 = source.getStringsInitialized();
if ( list1 != null ) {
target.setStringsInitialized( new LinkedHashSet<String>( list1 ) );
}
}
if ( target.getLongsInitialized() != null ) {
Set<Long> set1 = stringListToLongSet( source.getStringsInitialized() );
if ( set1 != null ) {
target.getLongsInitialized().clear();
target.getLongsInitialized().addAll( set1 );
}
else {
target.setLongsInitialized( new LinkedHashSet<Long>() );
}
}
else {
Set<Long> set1 = stringListToLongSet( source.getStringsInitialized() );
if ( set1 != null ) {
target.setLongsInitialized( set1 );
}
}
if ( target.getStringsWithDefault() != null ) {
List<String> list2 = source.getStringsWithDefault();
if ( list2 != null ) {
target.getStringsWithDefault().clear();
target.getStringsWithDefault().addAll( list2 );
}
else {
target.setStringsWithDefault( helper.toList( "3" ) );
}
}
else {
List<String> list2 = source.getStringsWithDefault();
if ( list2 != null ) {
target.setStringsWithDefault( new ArrayList<String>( list2 ) );
}
else {
target.setStringsWithDefault( helper.toList( "3" ) );
}
}
}
return target;
}
protected Set<Long> stringListToLongSet(List<String> list) {
if ( list == null ) {
return new LinkedHashSet<Long>();
}
Set<Long> set = LinkedHashSet.newLinkedHashSet( list.size() );
for ( String string : list ) {
set.add( Long.parseLong( string ) );
}
return set;
}
}

View File

@ -0,0 +1,248 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._913;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.processing.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-06-18T14:48:39+0200",
comments = "version: , compiler: javac, environment: Java 21.0.2 (Eclipse Adoptium)"
)
public class DomainDtoWithNvmsNullMapperImpl implements DomainDtoWithNvmsNullMapper {
private final Helper helper = new Helper();
@Override
public Domain create(Dto source) {
if ( source == null ) {
return null;
}
Domain domain = createNullDomain();
List<String> list = source.getStrings();
if ( list != null ) {
domain.setStrings( new LinkedHashSet<String>( list ) );
}
domain.setLongs( stringListToLongSet( source.getStrings() ) );
List<String> list1 = source.getStringsInitialized();
if ( list1 != null ) {
domain.setStringsInitialized( new LinkedHashSet<String>( list1 ) );
}
domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) );
List<String> list2 = source.getStringsWithDefault();
if ( list2 != null ) {
domain.setStringsWithDefault( new ArrayList<String>( list2 ) );
}
else {
domain.setStringsWithDefault( helper.toList( "3" ) );
}
return domain;
}
@Override
public void update(Dto source, Domain target) {
if ( source == null ) {
return;
}
if ( target.getStrings() != null ) {
List<String> list = source.getStrings();
if ( list != null ) {
target.getStrings().clear();
target.getStrings().addAll( list );
}
else {
target.setStrings( null );
}
}
else {
List<String> list = source.getStrings();
if ( list != null ) {
target.setStrings( new LinkedHashSet<String>( list ) );
}
}
if ( target.getLongs() != null ) {
Set<Long> set = stringListToLongSet( source.getStrings() );
if ( set != null ) {
target.getLongs().clear();
target.getLongs().addAll( set );
}
else {
target.setLongs( null );
}
}
else {
Set<Long> set = stringListToLongSet( source.getStrings() );
if ( set != null ) {
target.setLongs( set );
}
}
if ( target.getStringsInitialized() != null ) {
List<String> list1 = source.getStringsInitialized();
if ( list1 != null ) {
target.getStringsInitialized().clear();
target.getStringsInitialized().addAll( list1 );
}
else {
target.setStringsInitialized( null );
}
}
else {
List<String> list1 = source.getStringsInitialized();
if ( list1 != null ) {
target.setStringsInitialized( new LinkedHashSet<String>( list1 ) );
}
}
if ( target.getLongsInitialized() != null ) {
Set<Long> set1 = stringListToLongSet( source.getStringsInitialized() );
if ( set1 != null ) {
target.getLongsInitialized().clear();
target.getLongsInitialized().addAll( set1 );
}
else {
target.setLongsInitialized( null );
}
}
else {
Set<Long> set1 = stringListToLongSet( source.getStringsInitialized() );
if ( set1 != null ) {
target.setLongsInitialized( set1 );
}
}
if ( target.getStringsWithDefault() != null ) {
List<String> list2 = source.getStringsWithDefault();
if ( list2 != null ) {
target.getStringsWithDefault().clear();
target.getStringsWithDefault().addAll( list2 );
}
else {
target.setStringsWithDefault( helper.toList( "3" ) );
}
}
else {
List<String> list2 = source.getStringsWithDefault();
if ( list2 != null ) {
target.setStringsWithDefault( new ArrayList<String>( list2 ) );
}
else {
target.setStringsWithDefault( helper.toList( "3" ) );
}
}
}
@Override
public Domain updateWithReturn(Dto source, Domain target) {
if ( source == null ) {
return target;
}
if ( target.getStrings() != null ) {
List<String> list = source.getStrings();
if ( list != null ) {
target.getStrings().clear();
target.getStrings().addAll( list );
}
else {
target.setStrings( null );
}
}
else {
List<String> list = source.getStrings();
if ( list != null ) {
target.setStrings( new LinkedHashSet<String>( list ) );
}
}
if ( target.getLongs() != null ) {
Set<Long> set = stringListToLongSet( source.getStrings() );
if ( set != null ) {
target.getLongs().clear();
target.getLongs().addAll( set );
}
else {
target.setLongs( null );
}
}
else {
Set<Long> set = stringListToLongSet( source.getStrings() );
if ( set != null ) {
target.setLongs( set );
}
}
if ( target.getStringsInitialized() != null ) {
List<String> list1 = source.getStringsInitialized();
if ( list1 != null ) {
target.getStringsInitialized().clear();
target.getStringsInitialized().addAll( list1 );
}
else {
target.setStringsInitialized( null );
}
}
else {
List<String> list1 = source.getStringsInitialized();
if ( list1 != null ) {
target.setStringsInitialized( new LinkedHashSet<String>( list1 ) );
}
}
if ( target.getLongsInitialized() != null ) {
Set<Long> set1 = stringListToLongSet( source.getStringsInitialized() );
if ( set1 != null ) {
target.getLongsInitialized().clear();
target.getLongsInitialized().addAll( set1 );
}
else {
target.setLongsInitialized( null );
}
}
else {
Set<Long> set1 = stringListToLongSet( source.getStringsInitialized() );
if ( set1 != null ) {
target.setLongsInitialized( set1 );
}
}
if ( target.getStringsWithDefault() != null ) {
List<String> list2 = source.getStringsWithDefault();
if ( list2 != null ) {
target.getStringsWithDefault().clear();
target.getStringsWithDefault().addAll( list2 );
}
else {
target.setStringsWithDefault( helper.toList( "3" ) );
}
}
else {
List<String> list2 = source.getStringsWithDefault();
if ( list2 != null ) {
target.setStringsWithDefault( new ArrayList<String>( list2 ) );
}
else {
target.setStringsWithDefault( helper.toList( "3" ) );
}
}
return target;
}
protected Set<Long> stringListToLongSet(List<String> list) {
if ( list == null ) {
return null;
}
Set<Long> set = LinkedHashSet.newLinkedHashSet( list.size() );
for ( String string : list ) {
set.add( Long.parseLong( string ) );
}
return set;
}
}

View File

@ -0,0 +1,214 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._913;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.processing.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-06-19T11:03:59+0300",
comments = "version: , compiler: javac, environment: Java 21.0.2 (Amazon.com Inc.)"
)
public class DomainDtoWithPresenceCheckMapperImpl implements DomainDtoWithPresenceCheckMapper {
private final Helper helper = new Helper();
@Override
public Domain create(DtoWithPresenceCheck source) {
if ( source == null ) {
return null;
}
Domain domain = createNullDomain();
if ( source.hasStrings() ) {
List<String> list = source.getStrings();
domain.setStrings( new LinkedHashSet<String>( list ) );
}
if ( source.hasStrings() ) {
domain.setLongs( stringListToLongSet( source.getStrings() ) );
}
if ( source.hasStringsInitialized() ) {
List<String> list1 = source.getStringsInitialized();
domain.setStringsInitialized( new LinkedHashSet<String>( list1 ) );
}
if ( source.hasStringsInitialized() ) {
domain.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) );
}
if ( source.hasStringsWithDefault() ) {
List<String> list2 = source.getStringsWithDefault();
domain.setStringsWithDefault( new ArrayList<String>( list2 ) );
}
else {
domain.setStringsWithDefault( helper.toList( "3" ) );
}
return domain;
}
@Override
public void update(DtoWithPresenceCheck source, Domain target) {
if ( source == null ) {
return;
}
if ( target.getStrings() != null ) {
if ( source.hasStrings() ) {
target.getStrings().clear();
target.getStrings().addAll( source.getStrings() );
}
}
else {
if ( source.hasStrings() ) {
List<String> list = source.getStrings();
target.setStrings( new LinkedHashSet<String>( list ) );
}
}
if ( target.getLongs() != null ) {
if ( source.hasStrings() ) {
target.getLongs().clear();
target.getLongs().addAll( stringListToLongSet( source.getStrings() ) );
}
}
else {
if ( source.hasStrings() ) {
target.setLongs( stringListToLongSet( source.getStrings() ) );
}
}
if ( target.getStringsInitialized() != null ) {
if ( source.hasStringsInitialized() ) {
target.getStringsInitialized().clear();
target.getStringsInitialized().addAll( source.getStringsInitialized() );
}
}
else {
if ( source.hasStringsInitialized() ) {
List<String> list1 = source.getStringsInitialized();
target.setStringsInitialized( new LinkedHashSet<String>( list1 ) );
}
}
if ( target.getLongsInitialized() != null ) {
if ( source.hasStringsInitialized() ) {
target.getLongsInitialized().clear();
target.getLongsInitialized().addAll( stringListToLongSet( source.getStringsInitialized() ) );
}
}
else {
if ( source.hasStringsInitialized() ) {
target.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) );
}
}
if ( target.getStringsWithDefault() != null ) {
if ( source.hasStringsWithDefault() ) {
target.getStringsWithDefault().clear();
target.getStringsWithDefault().addAll( source.getStringsWithDefault() );
}
else {
target.setStringsWithDefault( helper.toList( "3" ) );
}
}
else {
if ( source.hasStringsWithDefault() ) {
List<String> list2 = source.getStringsWithDefault();
target.setStringsWithDefault( new ArrayList<String>( list2 ) );
}
else {
target.setStringsWithDefault( helper.toList( "3" ) );
}
}
}
@Override
public Domain updateWithReturn(DtoWithPresenceCheck source, Domain target) {
if ( source == null ) {
return target;
}
if ( target.getStrings() != null ) {
if ( source.hasStrings() ) {
target.getStrings().clear();
target.getStrings().addAll( source.getStrings() );
}
}
else {
if ( source.hasStrings() ) {
List<String> list = source.getStrings();
target.setStrings( new LinkedHashSet<String>( list ) );
}
}
if ( target.getLongs() != null ) {
if ( source.hasStrings() ) {
target.getLongs().clear();
target.getLongs().addAll( stringListToLongSet( source.getStrings() ) );
}
}
else {
if ( source.hasStrings() ) {
target.setLongs( stringListToLongSet( source.getStrings() ) );
}
}
if ( target.getStringsInitialized() != null ) {
if ( source.hasStringsInitialized() ) {
target.getStringsInitialized().clear();
target.getStringsInitialized().addAll( source.getStringsInitialized() );
}
}
else {
if ( source.hasStringsInitialized() ) {
List<String> list1 = source.getStringsInitialized();
target.setStringsInitialized( new LinkedHashSet<String>( list1 ) );
}
}
if ( target.getLongsInitialized() != null ) {
if ( source.hasStringsInitialized() ) {
target.getLongsInitialized().clear();
target.getLongsInitialized().addAll( stringListToLongSet( source.getStringsInitialized() ) );
}
}
else {
if ( source.hasStringsInitialized() ) {
target.setLongsInitialized( stringListToLongSet( source.getStringsInitialized() ) );
}
}
if ( target.getStringsWithDefault() != null ) {
if ( source.hasStringsWithDefault() ) {
target.getStringsWithDefault().clear();
target.getStringsWithDefault().addAll( source.getStringsWithDefault() );
}
else {
target.setStringsWithDefault( helper.toList( "3" ) );
}
}
else {
if ( source.hasStringsWithDefault() ) {
List<String> list2 = source.getStringsWithDefault();
target.setStringsWithDefault( new ArrayList<String>( list2 ) );
}
else {
target.setStringsWithDefault( helper.toList( "3" ) );
}
}
return target;
}
protected Set<Long> stringListToLongSet(List<String> list) {
if ( list == null ) {
return null;
}
Set<Long> set = LinkedHashSet.newLinkedHashSet( list.size() );
for ( String string : list ) {
set.add( Long.parseLong( string ) );
}
return set;
}
}

View File

@ -0,0 +1,259 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.collection.defaultimplementation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.NavigableSet;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import javax.annotation.processing.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-06-18T14:48:39+0200",
comments = "version: , compiler: javac, environment: Java 21.0.2 (Eclipse Adoptium)"
)
public class SourceTargetMapperImpl implements SourceTargetMapper {
@Override
public Target sourceToTarget(Source source) {
if ( source == null ) {
return null;
}
Target target = new Target();
if ( target.getFooListNoSetter() != null ) {
List<TargetFoo> list = sourceFoosToTargetFoos( source.getFooList() );
if ( list != null ) {
target.getFooListNoSetter().addAll( list );
}
}
return target;
}
@Override
public TargetFoo sourceFooToTargetFoo(SourceFoo sourceFoo) {
if ( sourceFoo == null ) {
return null;
}
TargetFoo targetFoo = new TargetFoo();
targetFoo.setName( sourceFoo.getName() );
return targetFoo;
}
@Override
public List<TargetFoo> sourceFoosToTargetFoos(List<SourceFoo> foos) {
if ( foos == null ) {
return null;
}
List<TargetFoo> list = new ArrayList<TargetFoo>( foos.size() );
for ( SourceFoo sourceFoo : foos ) {
list.add( sourceFooToTargetFoo( sourceFoo ) );
}
return list;
}
@Override
public Set<TargetFoo> sourceFoosToTargetFoos(Set<SourceFoo> foos) {
if ( foos == null ) {
return null;
}
Set<TargetFoo> set = LinkedHashSet.newLinkedHashSet( foos.size() );
for ( SourceFoo sourceFoo : foos ) {
set.add( sourceFooToTargetFoo( sourceFoo ) );
}
return set;
}
@Override
public Collection<TargetFoo> sourceFoosToTargetFoos(Collection<SourceFoo> foos) {
if ( foos == null ) {
return null;
}
Collection<TargetFoo> collection = new ArrayList<TargetFoo>( foos.size() );
for ( SourceFoo sourceFoo : foos ) {
collection.add( sourceFooToTargetFoo( sourceFoo ) );
}
return collection;
}
@Override
public Iterable<TargetFoo> sourceFoosToTargetFoos(Iterable<SourceFoo> foos) {
if ( foos == null ) {
return null;
}
ArrayList<TargetFoo> iterable = new ArrayList<TargetFoo>();
for ( SourceFoo sourceFoo : foos ) {
iterable.add( sourceFooToTargetFoo( sourceFoo ) );
}
return iterable;
}
@Override
public void sourceFoosToTargetFoosUsingTargetParameter(List<TargetFoo> targetFoos, Iterable<SourceFoo> sourceFoos) {
if ( sourceFoos == null ) {
return;
}
targetFoos.clear();
for ( SourceFoo sourceFoo : sourceFoos ) {
targetFoos.add( sourceFooToTargetFoo( sourceFoo ) );
}
}
@Override
public Iterable<TargetFoo> sourceFoosToTargetFoosUsingTargetParameterAndReturn(Iterable<SourceFoo> sourceFoos, List<TargetFoo> targetFoos) {
if ( sourceFoos == null ) {
return targetFoos;
}
targetFoos.clear();
for ( SourceFoo sourceFoo : sourceFoos ) {
targetFoos.add( sourceFooToTargetFoo( sourceFoo ) );
}
return targetFoos;
}
@Override
public SortedSet<TargetFoo> sourceFoosToTargetFooSortedSet(Collection<SourceFoo> foos) {
if ( foos == null ) {
return null;
}
SortedSet<TargetFoo> sortedSet = new TreeSet<TargetFoo>();
for ( SourceFoo sourceFoo : foos ) {
sortedSet.add( sourceFooToTargetFoo( sourceFoo ) );
}
return sortedSet;
}
@Override
public NavigableSet<TargetFoo> sourceFoosToTargetFooNavigableSet(Collection<SourceFoo> foos) {
if ( foos == null ) {
return null;
}
NavigableSet<TargetFoo> navigableSet = new TreeSet<TargetFoo>();
for ( SourceFoo sourceFoo : foos ) {
navigableSet.add( sourceFooToTargetFoo( sourceFoo ) );
}
return navigableSet;
}
@Override
public Map<String, TargetFoo> sourceFooMapToTargetFooMap(Map<Long, SourceFoo> foos) {
if ( foos == null ) {
return null;
}
Map<String, TargetFoo> map = LinkedHashMap.newLinkedHashMap( foos.size() );
for ( java.util.Map.Entry<Long, SourceFoo> entry : foos.entrySet() ) {
String key = String.valueOf( entry.getKey() );
TargetFoo value = sourceFooToTargetFoo( entry.getValue() );
map.put( key, value );
}
return map;
}
@Override
public SortedMap<String, TargetFoo> sourceFooMapToTargetFooSortedMap(Map<Long, SourceFoo> foos) {
if ( foos == null ) {
return null;
}
SortedMap<String, TargetFoo> sortedMap = new TreeMap<String, TargetFoo>();
for ( java.util.Map.Entry<Long, SourceFoo> entry : foos.entrySet() ) {
String key = String.valueOf( entry.getKey() );
TargetFoo value = sourceFooToTargetFoo( entry.getValue() );
sortedMap.put( key, value );
}
return sortedMap;
}
@Override
public NavigableMap<String, TargetFoo> sourceFooMapToTargetFooNavigableMap(Map<Long, SourceFoo> foos) {
if ( foos == null ) {
return null;
}
NavigableMap<String, TargetFoo> navigableMap = new TreeMap<String, TargetFoo>();
for ( java.util.Map.Entry<Long, SourceFoo> entry : foos.entrySet() ) {
String key = String.valueOf( entry.getKey() );
TargetFoo value = sourceFooToTargetFoo( entry.getValue() );
navigableMap.put( key, value );
}
return navigableMap;
}
@Override
public ConcurrentMap<String, TargetFoo> sourceFooMapToTargetFooConcurrentMap(Map<Long, SourceFoo> foos) {
if ( foos == null ) {
return null;
}
ConcurrentMap<String, TargetFoo> concurrentMap = new ConcurrentHashMap<String, TargetFoo>( Math.max( (int) ( foos.size() / .75f ) + 1, 16 ) );
for ( java.util.Map.Entry<Long, SourceFoo> entry : foos.entrySet() ) {
String key = String.valueOf( entry.getKey() );
TargetFoo value = sourceFooToTargetFoo( entry.getValue() );
concurrentMap.put( key, value );
}
return concurrentMap;
}
@Override
public ConcurrentNavigableMap<String, TargetFoo> sourceFooMapToTargetFooConcurrentNavigableMap(Map<Long, SourceFoo> foos) {
if ( foos == null ) {
return null;
}
ConcurrentNavigableMap<String, TargetFoo> concurrentNavigableMap = new ConcurrentSkipListMap<String, TargetFoo>();
for ( java.util.Map.Entry<Long, SourceFoo> entry : foos.entrySet() ) {
String key = String.valueOf( entry.getKey() );
TargetFoo value = sourceFooToTargetFoo( entry.getValue() );
concurrentNavigableMap.put( key, value );
}
return concurrentNavigableMap;
}
}

View File

@ -0,0 +1,120 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.updatemethods;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.annotation.processing.Generated;
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2024-06-18T14:48:39+0200",
comments = "version: , compiler: javac, environment: Java 21.0.2 (Eclipse Adoptium)"
)
public class CompanyMapper1Impl implements CompanyMapper1 {
private final DepartmentEntityFactory departmentEntityFactory = new DepartmentEntityFactory();
@Override
public void toCompanyEntity(UnmappableCompanyDto dto, CompanyEntity entity) {
if ( dto == null ) {
return;
}
entity.setName( dto.getName() );
if ( dto.getDepartment() != null ) {
if ( entity.getDepartment() == null ) {
entity.setDepartment( departmentEntityFactory.createDepartmentEntity() );
}
unmappableDepartmentDtoToDepartmentEntity( dto.getDepartment(), entity.getDepartment() );
}
else {
entity.setDepartment( null );
}
}
@Override
public void toInBetween(UnmappableDepartmentDto dto, DepartmentInBetween entity) {
if ( dto == null ) {
return;
}
entity.setName( dto.getName() );
}
@Override
public void toDepartmentEntity(DepartmentInBetween dto, DepartmentEntity entity) {
if ( dto == null ) {
return;
}
entity.setName( dto.getName() );
}
protected SecretaryEntity secretaryDtoToSecretaryEntity(SecretaryDto secretaryDto) {
if ( secretaryDto == null ) {
return null;
}
SecretaryEntity secretaryEntity = new SecretaryEntity();
secretaryEntity.setName( secretaryDto.getName() );
return secretaryEntity;
}
protected EmployeeEntity employeeDtoToEmployeeEntity(EmployeeDto employeeDto) {
if ( employeeDto == null ) {
return null;
}
EmployeeEntity employeeEntity = new EmployeeEntity();
employeeEntity.setName( employeeDto.getName() );
return employeeEntity;
}
protected Map<SecretaryEntity, EmployeeEntity> secretaryDtoEmployeeDtoMapToSecretaryEntityEmployeeEntityMap(Map<SecretaryDto, EmployeeDto> map) {
if ( map == null ) {
return null;
}
Map<SecretaryEntity, EmployeeEntity> map1 = LinkedHashMap.newLinkedHashMap( map.size() );
for ( java.util.Map.Entry<SecretaryDto, EmployeeDto> entry : map.entrySet() ) {
SecretaryEntity key = secretaryDtoToSecretaryEntity( entry.getKey() );
EmployeeEntity value = employeeDtoToEmployeeEntity( entry.getValue() );
map1.put( key, value );
}
return map1;
}
protected void unmappableDepartmentDtoToDepartmentEntity(UnmappableDepartmentDto unmappableDepartmentDto, DepartmentEntity mappingTarget) {
if ( unmappableDepartmentDto == null ) {
return;
}
mappingTarget.setName( unmappableDepartmentDto.getName() );
if ( mappingTarget.getSecretaryToEmployee() != null ) {
Map<SecretaryEntity, EmployeeEntity> map = secretaryDtoEmployeeDtoMapToSecretaryEntityEmployeeEntityMap( unmappableDepartmentDto.getSecretaryToEmployee() );
if ( map != null ) {
mappingTarget.getSecretaryToEmployee().clear();
mappingTarget.getSecretaryToEmployee().putAll( map );
}
else {
mappingTarget.setSecretaryToEmployee( null );
}
}
else {
Map<SecretaryEntity, EmployeeEntity> map = secretaryDtoEmployeeDtoMapToSecretaryEntityEmployeeEntityMap( unmappableDepartmentDto.getSecretaryToEmployee() );
if ( map != null ) {
mappingTarget.setSecretaryToEmployee( map );
}
}
}
}