Skip to content

Commit 4563236

Browse files
committed
v1.0.8
1 parent ee6c22f commit 4563236

File tree

6 files changed

+111
-23
lines changed

6 files changed

+111
-23
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This BeanUtils library is a Java bean copy utility with powerful functionality a
88
<dependency>
99
<groupId>com.github.yangtu222</groupId>
1010
<artifactId>BeanUtils</artifactId>
11-
<version>1.0.7</version>
11+
<version>1.0.8</version>
1212
</dependency>
1313
~~~
1414

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>com.github.yangtu222</groupId>
66
<artifactId>BeanUtils</artifactId>
77
<name>BeanUtils</name>
8-
<version>1.0.7</version>
8+
<version>1.0.8</version>
99
<description>BeanUtils library is a Java bean copy utility with powerful functionality and high performance.</description>
1010
<url>https://github.com/yangtu222/BeanUtils</url>
1111

@@ -27,7 +27,7 @@
2727
<connection>scm:git:https://github.com/yangtu222/BeanUtils.git</connection>
2828
<developerConnection>scm:git:https://github.com/yangtu222/BeanUtils.git</developerConnection>
2929
<url>https://github.com/yangtu222/BeanUtils.git</url>
30-
<tag>v1.0.7</tag>
30+
<tag>v1.0.8</tag>
3131
</scm>
3232

3333
<profiles>

src/main/java/com/tuyang/beanutils/internal/dump/BeanCopyDump.java

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,55 +54,62 @@ public static void dumpPropertyMapping(Class<?> sourceClass, Class<?> targetClas
5454
}
5555

5656
public static void dumpPropertyMapping(Class<?> sourceClass, Class<?> targetClass , Class<?> optionClass, List<BeanCopyPropertyItem> itemList) {
57+
58+
List<Long> stackCacheKeyList = localDumpStack.get();
59+
if( stackCacheKeyList == null ) {
60+
stackCacheKeyList = new ArrayList<>();
61+
localDumpStack.set(stackCacheKeyList);
62+
}
63+
64+
long cacheKey = (((long)sourceClass.hashCode() ) << 16 )+ (long) targetClass.hashCode();
65+
if( optionClass != null ) {
66+
cacheKey = (cacheKey <<16) + (long)optionClass.hashCode();
67+
} else {
68+
cacheKey = (cacheKey <<16) + (long)targetClass.hashCode();
69+
}
70+
71+
if( stackCacheKeyList.contains(cacheKey) ) {
72+
return;
73+
}
74+
if( stackCacheKeyList.isEmpty() ) {
75+
logger.info("=============================================================================================");
76+
logger.info("Dump Bean Copy Property Mapping:");
77+
}
78+
5779
Integer dumpLevel = localDumpLevel.get();
5880
if( dumpLevel == null ) {
5981
dumpLevel = -1;
6082
}
6183
if(dumpLevel == -1 ) {
6284
localDumpStack.set(new ArrayList<Long>());
6385
}
86+
6487
localDumpLevel.set(++dumpLevel);
6588

6689
dumpPropertyMappingInternal(sourceClass, targetClass, optionClass, itemList);
6790

6891
localDumpLevel.set(--dumpLevel);
92+
6993
if(dumpLevel == -1 && localDumpStack.get().size() > 0 ) {
7094
logger.info("=============================================================================================");
7195
}
7296
}
7397

74-
public static void dumpPropertyMappingInternal(Class<?> sourceClass, Class<?> targetClass , Class<?> optionClass, List<BeanCopyPropertyItem> itemList) {
98+
private static void dumpPropertyMappingInternal(Class<?> sourceClass, Class<?> targetClass , Class<?> optionClass, List<BeanCopyPropertyItem> itemList ) {
7599
if( optionClass == null )
76100
optionClass = targetClass;
77101

78-
Integer dumpLevel = localDumpLevel.get();
79102
List<Long> stackCacheKeyList = localDumpStack.get();
80-
if( stackCacheKeyList == null ) {
81-
stackCacheKeyList = new ArrayList<>();
82-
localDumpStack.set(stackCacheKeyList);
83-
}
84-
85103
long cacheKey = (((long)sourceClass.hashCode() ) << 16 )+ (long) targetClass.hashCode();
86104
if( optionClass != null ) {
87105
cacheKey = (cacheKey <<16) + (long)optionClass.hashCode();
88106
} else {
89107
cacheKey = (cacheKey <<16) + (long)targetClass.hashCode();
90108
}
91-
92109
if( stackCacheKeyList.contains(cacheKey) ) {
93110
return;
94111
}
95-
if( stackCacheKeyList.isEmpty() ) {
96-
logger.info("=============================================================================================");
97-
logger.info("Dump Bean Copy Property Mapping:");
98-
}
99112
stackCacheKeyList.add(cacheKey);
100-
dumpPropertyMappingInternal(sourceClass, targetClass, optionClass, dumpLevel, itemList);
101-
}
102-
103-
private static void dumpPropertyMappingInternal(Class<?> sourceClass, Class<?> targetClass , Class<?> optionClass, int level, List<BeanCopyPropertyItem> itemList ) {
104-
if( optionClass == null )
105-
optionClass = targetClass;
106113

107114
logger.info("---------------------------------------------------------------------------------------------");
108115
logger.info("From: [" + sourceClass.getSimpleName() + "] To: [" + targetClass.getSimpleName() + "] Option: [" + optionClass.getSimpleName() + "]");
@@ -115,7 +122,7 @@ private static void dumpPropertyMappingInternal(Class<?> sourceClass, Class<?> t
115122
BeanCopySource copyAnnotation = targetClass.getAnnotation(BeanCopySource.class);
116123
features = copyAnnotation.features();
117124
}
118-
if( features == null ) {
125+
if( features == null || features.length == 0) {
119126
logger.info("CopyFeature: (NONE)");
120127
} else {
121128
logger.info("CopyFeature:");
@@ -251,7 +258,7 @@ private static void dumpPropertyMappingInternal(Class<?> sourceClass, Class<?> t
251258
continue;
252259
if( sourceProertyType.isEnum() || targetPropertyType.isEnum() )
253260
continue;
254-
dumpPropertyMappingInternal(sourceProertyType, targetPropertyType, item.optionClass, level+1, null );
261+
dumpPropertyMappingInternal(sourceProertyType, targetPropertyType, item.optionClass, null );
255262
}
256263
}
257264
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.tuyang.test.testRecursion2;
2+
3+
public class FromBean {
4+
5+
private String name;
6+
private FromBean parent;
7+
8+
public String getName() {
9+
return name;
10+
}
11+
public void setName(String name) {
12+
this.name = name;
13+
}
14+
public FromBean getParent() {
15+
return parent;
16+
}
17+
public void setParent(FromBean parent) {
18+
this.parent = parent;
19+
}
20+
21+
22+
23+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.tuyang.test.testRecursion2;
2+
3+
import static org.junit.Assert.assertEquals;
4+
5+
import org.junit.Test;
6+
7+
import com.tuyang.beanutils.BeanCopyUtils;
8+
9+
public class TestRecursion {
10+
11+
private FromBean generateBean(int i) {
12+
13+
FromBean newBean = new FromBean();
14+
newBean.setName("S" + i);
15+
if(i == 0) {
16+
newBean.setParent(null);
17+
}
18+
else {
19+
FromBean parentBean = generateBean(i-1);
20+
newBean.setParent(parentBean);
21+
}
22+
return newBean;
23+
}
24+
25+
@Test
26+
public void testRecursion() {
27+
FromBean fromBean = generateBean(10);
28+
ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class);
29+
assertEquals(toBean.getParent().getParent().getParent().getParent().getName(),
30+
fromBean.getParent().getParent().getParent().getParent().getName());
31+
32+
}
33+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.tuyang.test.testRecursion2;
2+
3+
import com.tuyang.beanutils.annotation.BeanCopySource;
4+
import com.tuyang.beanutils.annotation.CopyProperty;
5+
6+
@BeanCopySource(source=FromBean.class)
7+
public class ToBean {
8+
9+
private String name;
10+
11+
@CopyProperty(optionClass=ToBean.class)
12+
private ToBean parent;
13+
public String getName() {
14+
return name;
15+
}
16+
public void setName(String name) {
17+
this.name = name;
18+
}
19+
public ToBean getParent() {
20+
return parent;
21+
}
22+
public void setParent(ToBean parent) {
23+
this.parent = parent;
24+
}
25+
}

0 commit comments

Comments
 (0)