├── .gitignore ├── LICENSE ├── README.md ├── pom.xml └── src ├── main └── java │ └── com │ └── tuyang │ └── beanutils │ ├── BeanCopier.java │ ├── BeanCopyConvertor.java │ ├── BeanCopyUtils.java │ ├── annotation │ ├── BeanCopySource.java │ ├── CopyCollection.java │ ├── CopyFeature.java │ └── CopyProperty.java │ ├── config │ └── BeanCopyConfig.java │ ├── exception │ └── BeanCopyException.java │ └── internal │ ├── cache │ ├── BeanCopyCache.java │ └── BeanCopyPropertyItem.java │ ├── convertors │ ├── ArrayConvertorFactory.java │ ├── BoolArrayConvertor.java │ ├── BoolObjectArrayConvertor.java │ ├── ByteArrayConvertor.java │ ├── ByteObjectArrayConvertor.java │ ├── CharArrayConvertor.java │ ├── CharObjectArrayConvertor.java │ ├── DoubleArrayConvertor.java │ ├── DoubleObjectArrayConvertor.java │ ├── EnumToEnumArrayConvertor.java │ ├── EnumToStringArrayConvertor.java │ ├── EnumToStringConvertor.java │ ├── FloatArrayConvertor.java │ ├── FloatObjectArrayConvertor.java │ ├── IntArrayConvertor.java │ ├── IntObjectArrayConvertor.java │ ├── ListToEnumArrayConvertor.java │ ├── LongArrayConvertor.java │ ├── LongObjectArrayConvertor.java │ ├── ObjectArrayConvertor.java │ ├── ObjectToEnumConvertor.java │ ├── ObjectToStringArrayConvertor.java │ ├── ObjectToStringConvertor.java │ ├── ShortArrayConvertor.java │ ├── ShortObjectArrayConvertor.java │ └── StringToEnumArrayConvertor.java │ ├── dump │ └── BeanCopyDump.java │ ├── factory │ └── BeanCopierFactory.java │ ├── javassist │ └── JavassistBeanCopyFactory.java │ ├── logger │ └── Logger.java │ ├── reflect │ ├── ReflactBeanCopyFactory.java │ └── ReflectBeanCopy.java │ └── utils │ ├── InstanceUtils.java │ └── PropertyUtils.java └── test └── java └── com └── tuyang └── test ├── perftest ├── BeanCopyInterface.java ├── FromBean.java ├── LoopTest.java ├── TestPerformance.java └── ToBean.java ├── testAnnotation ├── FromBean.java ├── Test03.java └── ToBean.java ├── testAnnotation2 ├── FromBean.java ├── FromBean2.java ├── Test04.java ├── ToBean.java └── ToBean2.java ├── testArray ├── FromBean.java ├── FromBean2.java ├── Test08.java ├── ToBean.java └── ToBean2.java ├── testArrayList ├── FromBean.java ├── FromBean2.java ├── Test08.java ├── ToBean.java └── ToBean2.java ├── testArrayList2 ├── FromBean.java ├── TestArrayList.java └── ToBean.java ├── testBasic ├── FromBean.java ├── Test01.java └── ToBean.java ├── testBeanToString ├── FromBean.java ├── FromBean2.java ├── Test03.java └── ToBean.java ├── testCollection ├── FromBean.java ├── FromBean2.java ├── Test05.java ├── ToBean.java └── ToBean2.java ├── testConvertor ├── FromBean.java ├── GendorConvertor.java ├── MyEnum.java ├── MyEnumConvertor.java ├── Test11.java └── ToBean.java ├── testEnum ├── FromBean.java ├── MyEnum.java ├── Test08.java └── ToBean.java ├── testEnum2 ├── FromBean.java ├── Inside.java ├── MyEnum.java ├── Test08.java └── ToBean.java ├── testFeatureIgnorePimitive ├── FromBean.java ├── TestFeatureIgnorePimitive.java ├── ToBean.java └── ToBeanOption.java ├── testIgnoreAll ├── FromBean.java ├── FromBean2.java ├── TestIgnoreAll.java └── ToBean.java ├── testInheritance ├── FromBean.java ├── FromBeanBase.java ├── Test09.java ├── ToBean.java └── ToBeanBase.java ├── testInheritance2 ├── FromBean.java ├── FromBeanBase.java ├── Test10.java ├── ToBean.java ├── ToBeanBase.java └── ToBeanOption.java ├── testMisc ├── DateConvertor.java ├── FromBean.java ├── FromBean2.java ├── FromBean3.java ├── FromBean4.java ├── Test12.java ├── ToBean.java ├── ToBean2.java ├── ToBean3.java └── ToBean4.java ├── testMultiThread ├── FromBean.java ├── StringToIntegerConverter.java ├── TestMultiThread.java └── ToBean.java ├── testOption ├── FromBean.java ├── Test07.java ├── ToBean.java └── ToBeanOption.java ├── testPrimitive ├── FromBean.java ├── Test02.java └── ToBean.java ├── testRecursion ├── FromBean.java ├── FromBean2.java ├── FromBean3.java ├── FromBean4.java ├── FromBean5.java ├── FromBean6.java ├── FromBean7.java ├── FromBean8.java ├── Test06.java └── ToBean.java └── testRecursion2 ├── FromBean.java ├── TestRecursion.java └── ToBean.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | /target/ 24 | /.classpath 25 | /.project 26 | /.settings/org.eclipse.core.resources.prefs 27 | /.settings/org.eclipse.jdt.core.prefs 28 | /.settings/org.eclipse.m2e.core.prefs 29 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 4.0.0 5 | com.github.yangtu222 6 | BeanUtils 7 | BeanUtils 8 | 1.0.11 9 | BeanUtils library is a Java bean copy utility with powerful functionality and high performance. 10 | https://github.com/yangtu222/BeanUtils 11 | 12 | 13 | UTF-8 14 | UTF-8 15 | 1.5.4.RELEASE 16 | 1.7 17 | 1.7 18 | UTF-8 19 | 20 | 3.0.1 21 | 2.10.4 22 | 2.5.3 23 | 1.6 24 | 25 | 26 | 27 | scm:git:https://github.com/yangtu222/BeanUtils.git 28 | scm:git:https://github.com/yangtu222/BeanUtils.git 29 | https://github.com/yangtu222/BeanUtils.git 30 | v1.0.11 31 | 32 | 33 | 34 | 35 | release 36 | 37 | 38 | 39 | maven-source-plugin 40 | ${maven.source.plugin.version} 41 | 42 | 43 | package 44 | 45 | jar-no-fork 46 | 47 | 48 | 49 | 50 | 51 | org.apache.maven.plugins 52 | maven-javadoc-plugin 53 | ${maven.javadoc.plugin.version} 54 | 55 | com.tuyang.beanutils.internal 56 | 57 | 58 | 59 | package 60 | 61 | jar 62 | 63 | 64 | 65 | 66 | 67 | maven-release-plugin 68 | ${maven.release.plugin.version} 69 | true 70 | 71 | 72 | org.apache.maven.plugins 73 | maven-gpg-plugin 74 | ${maven.gpg.plugin.version} 75 | 76 | 77 | verify 78 | 79 | sign 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | ${project.artifactId}-${project.version} 91 | 92 | 93 | org.sonatype.plugins 94 | nexus-staging-maven-plugin 95 | 1.6.3 96 | true 97 | 98 | ossrh 99 | https://oss.sonatype.org/ 100 | true 101 | 102 | 103 | 104 | org.apache.maven.plugins 105 | maven-compiler-plugin 106 | 3.6.1 107 | 108 | 109 | org.apache.maven.plugins 110 | maven-source-plugin 111 | 2.2.1 112 | 113 | 114 | attach-sources 115 | 116 | jar-no-fork 117 | 118 | 119 | 120 | 121 | 122 | org.apache.maven.plugins 123 | maven-javadoc-plugin 124 | 2.9.1 125 | 126 | 127 | attach-javadocs 128 | 129 | jar 130 | 131 | 132 | 133 | 134 | 135 | org.apache.maven.plugins 136 | maven-gpg-plugin 137 | 1.5 138 | 139 | 140 | sign-artifacts 141 | verify 142 | 143 | sign 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | org.springframework.boot 155 | spring-boot-dependencies 156 | 1.5.4.RELEASE 157 | pom 158 | import 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | org.javassist 168 | javassist 169 | 170 | 171 | 172 | org.springframework.boot 173 | spring-boot-starter 174 | test 175 | 176 | 177 | 178 | 179 | org.apache.commons 180 | commons-lang3 181 | 3.5 182 | test 183 | 184 | 185 | 186 | 187 | org.apache.commons 188 | commons-collections4 189 | 4.1 190 | test 191 | 192 | 193 | 194 | 195 | commons-beanutils 196 | commons-beanutils 197 | test 198 | 199 | 200 | 201 | 202 | net.sf.ezmorph 203 | ezmorph 204 | 1.0.6 205 | test 206 | 207 | 208 | 209 | junit 210 | junit 211 | test 212 | 213 | 214 | 215 | 216 | 217 | 218 | Tu Yang 219 | yangtu222@hotmail.com 220 | 221 | 222 | 223 | 224 | 225 | The Apache License, Version 2.0 226 | http://www.apache.org/licenses/LICENSE-2.0.txt 227 | 228 | 229 | 230 | 231 | 232 | ossrh 233 | https://oss.sonatype.org/content/repositories/snapshots 234 | 235 | 236 | ossrh 237 | https://oss.sonatype.org/service/local/staging/deploy/maven2 238 | 239 | 240 | 241 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/BeanCopier.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils; 31 | 32 | /** 33 | * This interface is to do the real bean copy. 34 | * 35 | */ 36 | public interface BeanCopier { 37 | 38 | /** 39 | * Copy sourceObject properties to targetObject properties. 40 | * @param sourceObject The source object which want to be copied from. 41 | * @param targetObject The target object which want to be copied to. 42 | * @return targetObject The target object is returned. 43 | * 44 | * Exception: if error, RuntimeException will be thrown, and can be BeanCopyException. 45 | */ 46 | public Object copyBean(Object sourceObject, Object targetObject ); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/BeanCopyConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils; 31 | /** 32 | * This interface is to do custom data conversion. 33 | * 34 | * @param The Source Type. 35 | * @param The Target Type. 36 | */ 37 | public interface BeanCopyConvertor { 38 | 39 | /** 40 | * This function is to do custom data conversion. 41 | * @param object : Source Object. 42 | * @return Converted Target Object. 43 | */ 44 | public T convertTo(S object); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/annotation/BeanCopySource.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.annotation; 31 | 32 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 33 | import static java.lang.annotation.ElementType.TYPE; 34 | 35 | import java.lang.annotation.Retention; 36 | import java.lang.annotation.Target; 37 | 38 | @Retention(RUNTIME) 39 | @Target(TYPE) 40 | public @interface BeanCopySource { 41 | 42 | /** 43 | * Specify the source class type. 44 | * @return The source class type. 45 | */ 46 | Class source(); 47 | 48 | CopyFeature[] features() default {}; 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/annotation/CopyCollection.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.annotation; 31 | 32 | import static java.lang.annotation.ElementType.FIELD; 33 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 34 | 35 | import java.lang.annotation.Documented; 36 | import java.lang.annotation.Retention; 37 | import java.lang.annotation.Target; 38 | 39 | @Retention(RUNTIME) 40 | @Target(FIELD) 41 | @Documented 42 | public @interface CopyCollection { 43 | 44 | /** 45 | * The property name in source object that want to be copied from. 46 | *

Note:

47 | *
 "" (empty string, or null): means the property name is same to source object. 
48 | 	 * a.b: means the source value is coming from source object's property a's property b. 
49 | * @return the property name which will be copied from. 50 | */ 51 | String property() default ""; 52 | 53 | /** 54 | * Specify this property will be ignored when do bean copy. 55 | * @return true is ignored. 56 | */ 57 | boolean ignored() default false; 58 | 59 | /** 60 | * Specify the collection's template class type. 61 | * @return The colleciton's template class type. 62 | */ 63 | Class targetClass(); 64 | 65 | /** 66 | * Specify the optionClass when coping when targetClass is a Java bean class. 67 | * @return option class. 68 | */ 69 | Class optionClass() default void.class; 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/annotation/CopyFeature.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.beanutils.annotation; 2 | 3 | public enum CopyFeature { 4 | IGNORE_PRIMITIVE_NULL_SOURCE_VALUE, 5 | IGNORE_ALL_NULL_SOURCE_VALUE, 6 | IGNORE_ENUM_CONVERT_EXCEPTION, 7 | ENABLE_JAVA_BEAN_TO_STRING, 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/annotation/CopyProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.annotation; 31 | 32 | import static java.lang.annotation.ElementType.FIELD; 33 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 34 | 35 | import java.lang.annotation.Documented; 36 | import java.lang.annotation.Retention; 37 | import java.lang.annotation.Target; 38 | 39 | @Retention(RUNTIME) 40 | @Target(FIELD) 41 | @Documented 42 | public @interface CopyProperty { 43 | 44 | /** 45 | * The property name in source object that want to be copied from. 46 | *

Note:

47 | *
 "" (empty string, or null): means the property name is same to source object. 
48 | 	 * a.b: means the source value is coming from source object's property a's property b. 
49 | * @return the property name which will be copied from. 50 | */ 51 | String property() default ""; 52 | 53 | /** 54 | * Specify this property will be ignored when do bean copy. 55 | * @return true is ignored. 56 | */ 57 | boolean ignored() default false; 58 | 59 | /** 60 | * The data convertor of this property. The convertor must be BeanCopyConvertor type. 61 | * @return convertor's class type. 62 | * 63 | * @see com.tuyang.beanutils.BeanCopyConvertor 64 | */ 65 | Class convertor() default void.class ; 66 | 67 | /** 68 | * Specify the optionClass when coping when this property is a Java bean class. 69 | * @return option class. 70 | */ 71 | Class optionClass() default void.class; 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/config/BeanCopyConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.config; 31 | 32 | import java.util.ArrayDeque; 33 | import java.util.ArrayList; 34 | import java.util.HashSet; 35 | 36 | import com.tuyang.beanutils.internal.cache.BeanCopyCache; 37 | import com.tuyang.beanutils.internal.factory.BeanCopierFactory; 38 | import com.tuyang.beanutils.internal.javassist.JavassistBeanCopyFactory; 39 | import com.tuyang.beanutils.internal.logger.Logger; 40 | import com.tuyang.beanutils.internal.reflect.ReflactBeanCopyFactory; 41 | 42 | public class BeanCopyConfig { 43 | 44 | public static enum DumpOption { 45 | AutoDumpNone, 46 | AutoDumpAtFirstCopy, 47 | AutoDumpAlways 48 | } 49 | 50 | private static BeanCopyConfig INSTANCE = new BeanCopyConfig(); 51 | 52 | private int logLevel = Logger.LogLevelWarn; 53 | 54 | private Class setClass = HashSet.class; 55 | private Class listClass = ArrayList.class; 56 | private Class queueClass = ArrayDeque.class; 57 | private Class dequeClass = ArrayDeque.class; 58 | 59 | private Class beanCopyFactory = JavassistBeanCopyFactory.class; 60 | // private Class beanCopyFactory = ReflactBeanCopyFactory.class; 61 | 62 | private DumpOption dumpOption = DumpOption.AutoDumpAtFirstCopy; 63 | 64 | private ClassLoader classLoader = null; 65 | 66 | public ClassLoader getClassLoader() { 67 | return classLoader; 68 | } 69 | 70 | public void setClassLoader(ClassLoader classLoader) { 71 | this.classLoader = classLoader; 72 | } 73 | 74 | public static BeanCopyConfig instance() { 75 | return INSTANCE; 76 | } 77 | 78 | public static void setBeanCopyConfig(BeanCopyConfig beanCopyConfig) { 79 | if( beanCopyConfig == null ) 80 | beanCopyConfig = new BeanCopyConfig(); 81 | BeanCopyConfig.INSTANCE = beanCopyConfig; 82 | BeanCopyCache.setBeanCopyConfig(beanCopyConfig); 83 | } 84 | 85 | public int getLogLevel() { 86 | return logLevel; 87 | } 88 | 89 | public void setLogLevel(int logLevel) { 90 | this.logLevel = logLevel; 91 | } 92 | 93 | public Class getSetClass() { 94 | return setClass; 95 | } 96 | 97 | public void setSetClass(Class setClass) { 98 | this.setClass = setClass; 99 | } 100 | 101 | public Class getListClass() { 102 | return listClass; 103 | } 104 | 105 | public void setListClass(Class listClass) { 106 | this.listClass = listClass; 107 | } 108 | 109 | public Class getBeanCopyFactory() { 110 | return beanCopyFactory; 111 | } 112 | 113 | public void setBeanCopyFactory(Class beanCopyFactory) { 114 | this.beanCopyFactory = beanCopyFactory; 115 | } 116 | 117 | public Class getQueueClass() { 118 | return queueClass; 119 | } 120 | 121 | public void setQueueClass(Class queueClass) { 122 | this.queueClass = queueClass; 123 | } 124 | 125 | public Class getDequeClass() { 126 | return dequeClass; 127 | } 128 | 129 | public void setDequeClass(Class dequeClass) { 130 | this.dequeClass = dequeClass; 131 | } 132 | 133 | public DumpOption getDumpOption() { 134 | return dumpOption; 135 | } 136 | 137 | public void setDumpOption(DumpOption dumpOption) { 138 | this.dumpOption = dumpOption; 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/exception/BeanCopyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.exception; 31 | 32 | /** 33 | * Thrown when generating BeanCopier or new instance in BanCopyUtils methods. 34 | * 35 | **/ 36 | public class BeanCopyException extends RuntimeException { 37 | 38 | private static final long serialVersionUID = 9055425084609925821L; 39 | 40 | public BeanCopyException(String message){ 41 | super(message); 42 | } 43 | 44 | public BeanCopyException( String message, Throwable cause){ 45 | super(message,cause); 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/cache/BeanCopyPropertyItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.cache; 31 | 32 | import java.lang.reflect.Method; 33 | 34 | import com.tuyang.beanutils.BeanCopyConvertor; 35 | import com.tuyang.beanutils.annotation.CopyFeature; 36 | 37 | public class BeanCopyPropertyItem { 38 | 39 | public String propertyName = null; 40 | public Method[] readMethods = null; 41 | public Method writeMethod = null; 42 | 43 | public boolean isCollection = false; 44 | public boolean useBeanCopy = false; 45 | 46 | public Class collectionClass = null; 47 | public Class optionClass = null; 48 | 49 | public Class convertorClass = null; 50 | @SuppressWarnings("rawtypes") 51 | public BeanCopyConvertor convertorObject = null; 52 | 53 | public CopyFeature[] features; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/ArrayConvertorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.convertors; 31 | 32 | import com.tuyang.beanutils.BeanCopyConvertor; 33 | 34 | public class ArrayConvertorFactory { 35 | 36 | @SuppressWarnings("rawtypes") 37 | public static BeanCopyConvertor getArrayConvertor(Class methodSourceType, Class methodTargetType, Class propertyOptionClass) { 38 | 39 | if( !(methodSourceType.isPrimitive() || methodTargetType.isPrimitive() ) ) { 40 | return new ObjectArrayConvertor(methodSourceType, methodTargetType, propertyOptionClass); 41 | } 42 | 43 | if( int.class.equals(methodSourceType) ) { 44 | return new IntArrayConvertor(); 45 | } else if( boolean.class.equals(methodSourceType) ) { 46 | return new BoolArrayConvertor(); 47 | } else if( byte.class.equals(methodSourceType) ) { 48 | return new ByteArrayConvertor(); 49 | } else if( char.class.equals(methodSourceType) ) { 50 | return new CharArrayConvertor(); 51 | } else if( short.class.equals(methodSourceType) ) { 52 | return new ShortArrayConvertor(); 53 | } else if( long.class.equals(methodSourceType) ) { 54 | return new LongArrayConvertor(); 55 | } else if( float.class.equals(methodSourceType) ) { 56 | return new FloatArrayConvertor(); 57 | } else if( double.class.equals(methodSourceType) ) { 58 | return new DoubleArrayConvertor(); 59 | } else if( Integer.class.equals(methodSourceType) ) { 60 | return new IntObjectArrayConvertor(); 61 | } else if( Boolean.class.equals(methodSourceType) ) { 62 | return new BoolObjectArrayConvertor(); 63 | } else if( Character.class.equals(methodSourceType) ) { 64 | return new CharObjectArrayConvertor(); 65 | } else if( Byte.class.equals(methodSourceType) ) { 66 | return new ByteObjectArrayConvertor(); 67 | } else if( Short.class.equals(methodSourceType) ) { 68 | return new ShortObjectArrayConvertor(); 69 | } else if( Long.class.equals(methodSourceType) ) { 70 | return new LongObjectArrayConvertor(); 71 | } else if( Float.class.equals(methodSourceType) ) { 72 | return new FloatObjectArrayConvertor(); 73 | } else if( Double.class.equals(methodSourceType) ) { 74 | return new DoubleObjectArrayConvertor(); 75 | } 76 | 77 | return null; 78 | 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/BoolArrayConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.convertors; 31 | 32 | import com.tuyang.beanutils.BeanCopyConvertor; 33 | 34 | @SuppressWarnings("rawtypes") 35 | public class BoolArrayConvertor implements BeanCopyConvertor { 36 | 37 | @Override 38 | public Object convertTo(Object object) { 39 | boolean[] array = (boolean[])object; 40 | Boolean[] retObject = new Boolean[array.length]; 41 | 42 | for( int i=0;i< array.length; i++) { 43 | retObject[i] = Boolean.valueOf(array[i]); 44 | } 45 | return retObject; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/BoolObjectArrayConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.convertors; 31 | 32 | import com.tuyang.beanutils.BeanCopyConvertor; 33 | 34 | @SuppressWarnings("rawtypes") 35 | public class BoolObjectArrayConvertor implements BeanCopyConvertor { 36 | 37 | @Override 38 | public Object convertTo(Object object) { 39 | Boolean[] array = (Boolean[])object; 40 | boolean[] retObject = new boolean[array.length]; 41 | 42 | for( int i=0;i< array.length; i++) { 43 | retObject[i] = array[i].booleanValue(); 44 | } 45 | return retObject; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/ByteArrayConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.convertors; 31 | 32 | import com.tuyang.beanutils.BeanCopyConvertor; 33 | 34 | @SuppressWarnings("rawtypes") 35 | public class ByteArrayConvertor implements BeanCopyConvertor { 36 | 37 | @Override 38 | public Object convertTo(Object object) { 39 | byte[] array = (byte[])object; 40 | Byte[] retObject = new Byte[array.length]; 41 | 42 | for( int i=0;i< array.length; i++) { 43 | retObject[i] = Byte.valueOf(array[i]); 44 | } 45 | return retObject; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/ByteObjectArrayConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.convertors; 31 | 32 | import com.tuyang.beanutils.BeanCopyConvertor; 33 | 34 | @SuppressWarnings("rawtypes") 35 | public class ByteObjectArrayConvertor implements BeanCopyConvertor { 36 | 37 | @Override 38 | public Object convertTo(Object object) { 39 | Byte[] array = (Byte[]) object; 40 | byte[] retObject = new byte[array.length]; 41 | 42 | for( int i=0;i< array.length; i++) { 43 | retObject[i] = array[i].byteValue(); 44 | } 45 | return retObject; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/CharArrayConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.convertors; 31 | 32 | import com.tuyang.beanutils.BeanCopyConvertor; 33 | 34 | @SuppressWarnings("rawtypes") 35 | public class CharArrayConvertor implements BeanCopyConvertor { 36 | 37 | @Override 38 | public Object convertTo(Object object) { 39 | char[] array = (char[])object; 40 | Character[] retObject = new Character[array.length]; 41 | 42 | for( int i=0;i< array.length; i++) { 43 | retObject[i] = Character.valueOf(array[i]); 44 | } 45 | return retObject; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/CharObjectArrayConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.convertors; 31 | 32 | import com.tuyang.beanutils.BeanCopyConvertor; 33 | 34 | @SuppressWarnings("rawtypes") 35 | public class CharObjectArrayConvertor implements BeanCopyConvertor { 36 | 37 | @Override 38 | public Object convertTo(Object object) { 39 | Character[] array = (Character[]) object; 40 | char[] retObject = new char[array.length]; 41 | 42 | for( int i=0;i< array.length; i++) { 43 | retObject[i] = array[i].charValue(); 44 | } 45 | return retObject; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/DoubleArrayConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.convertors; 31 | 32 | import com.tuyang.beanutils.BeanCopyConvertor; 33 | 34 | @SuppressWarnings("rawtypes") 35 | public class DoubleArrayConvertor implements BeanCopyConvertor { 36 | 37 | @Override 38 | public Object convertTo(Object object) { 39 | double[] array = (double[]) object; 40 | Double[] retObject = new Double[array.length]; 41 | 42 | for( int i=0;i< array.length; i++) { 43 | retObject[i] = Double.valueOf(array[i]); 44 | } 45 | return retObject; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/DoubleObjectArrayConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.convertors; 31 | 32 | import com.tuyang.beanutils.BeanCopyConvertor; 33 | 34 | @SuppressWarnings("rawtypes") 35 | public class DoubleObjectArrayConvertor implements BeanCopyConvertor { 36 | 37 | @Override 38 | public Object convertTo(Object object) { 39 | Double[] array = (Double[]) object; 40 | double[] retObject = new double[array.length]; 41 | 42 | for( int i=0;i< array.length; i++) { 43 | retObject[i] = array[i].doubleValue(); 44 | } 45 | return retObject; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/EnumToEnumArrayConvertor.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.beanutils.internal.convertors; 2 | 3 | import com.tuyang.beanutils.BeanCopyConvertor; 4 | 5 | @SuppressWarnings("rawtypes") 6 | public class EnumToEnumArrayConvertor implements BeanCopyConvertor { 7 | 8 | @Override 9 | public Enum[] convertTo(Enum[] object) { 10 | if( object == null ) 11 | return null; 12 | return object.clone(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/EnumToStringArrayConvertor.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.beanutils.internal.convertors; 2 | 3 | import com.tuyang.beanutils.BeanCopyConvertor; 4 | 5 | @SuppressWarnings("rawtypes") 6 | public class EnumToStringArrayConvertor implements BeanCopyConvertor { 7 | 8 | @Override 9 | public String[] convertTo(Enum[] object) { 10 | if( object == null ) 11 | return null; 12 | String[] retList = new String[object.length]; 13 | int i =0; 14 | for( Enum enum1 : object ) { 15 | retList[i++] = enum1.toString(); 16 | } 17 | return retList; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/EnumToStringConvertor.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.beanutils.internal.convertors; 2 | 3 | import com.tuyang.beanutils.BeanCopyConvertor; 4 | 5 | @SuppressWarnings("rawtypes") 6 | public class EnumToStringConvertor implements BeanCopyConvertor { 7 | 8 | @Override 9 | public String convertTo(Enum object) { 10 | return object.toString(); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/FloatArrayConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.convertors; 31 | 32 | import com.tuyang.beanutils.BeanCopyConvertor; 33 | 34 | @SuppressWarnings("rawtypes") 35 | public class FloatArrayConvertor implements BeanCopyConvertor { 36 | 37 | @Override 38 | public Object convertTo(Object object) { 39 | float[] array = (float[]) object; 40 | Float[] retObject = new Float[array.length]; 41 | 42 | for( int i=0;i< array.length; i++) { 43 | retObject[i] = Float.valueOf(array[i]); 44 | } 45 | return retObject; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/FloatObjectArrayConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.convertors; 31 | 32 | import com.tuyang.beanutils.BeanCopyConvertor; 33 | 34 | @SuppressWarnings("rawtypes") 35 | public class FloatObjectArrayConvertor implements BeanCopyConvertor { 36 | 37 | @Override 38 | public Object convertTo(Object object) { 39 | Float[] array = (Float[]) object; 40 | float[] retObject = new float[array.length]; 41 | 42 | for( int i=0;i< array.length; i++) { 43 | retObject[i] = array[i].floatValue(); 44 | } 45 | return retObject; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/IntArrayConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.convertors; 31 | 32 | import com.tuyang.beanutils.BeanCopyConvertor; 33 | 34 | @SuppressWarnings("rawtypes") 35 | public class IntArrayConvertor implements BeanCopyConvertor { 36 | 37 | @Override 38 | public Object convertTo(Object object) { 39 | int[] array = (int[])object; 40 | Integer[] retObject = new Integer[array.length]; 41 | 42 | for( int i=0;i< array.length; i++) { 43 | retObject[i] = Integer.valueOf(array[i]); 44 | } 45 | return retObject; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/IntObjectArrayConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.convertors; 31 | 32 | import com.tuyang.beanutils.BeanCopyConvertor; 33 | 34 | @SuppressWarnings("rawtypes") 35 | public class IntObjectArrayConvertor implements BeanCopyConvertor { 36 | 37 | @Override 38 | public Object convertTo(Object object) { 39 | Integer[] array = (Integer[]) object; 40 | int[] retObject = new int[array.length]; 41 | 42 | for( int i=0;i< array.length; i++) { 43 | retObject[i] = array[i].intValue(); 44 | } 45 | return retObject; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/ListToEnumArrayConvertor.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.beanutils.internal.convertors; 2 | 3 | import java.lang.reflect.Array; 4 | import java.util.Collection; 5 | 6 | import com.tuyang.beanutils.BeanCopyConvertor; 7 | 8 | @SuppressWarnings("rawtypes") 9 | public class ListToEnumArrayConvertor implements BeanCopyConvertor, Object[]> { 10 | 11 | private Class enumClass; 12 | private boolean throwExceptions; 13 | 14 | public ListToEnumArrayConvertor(Class enumClass, boolean throwExceptions) { 15 | this.enumClass = enumClass; 16 | this.throwExceptions = throwExceptions; 17 | } 18 | 19 | @SuppressWarnings("unchecked") 20 | @Override 21 | public Object[] convertTo(Collection objects) { 22 | if( objects == null ) 23 | return null; 24 | 25 | Object[] retList = (Object[]) Array.newInstance(enumClass, objects.size()); 26 | if( throwExceptions ) { 27 | int i =0; 28 | for(Object object : objects ) { 29 | if( object!=null ) { 30 | String str = object.toString(); 31 | retList[i] = Enum.valueOf(enumClass, str); 32 | } 33 | i++; 34 | } 35 | return retList; 36 | } 37 | Enum[] enums = (Enum[])enumClass.getEnumConstants(); 38 | int i =0; 39 | for(Object object : objects ) { 40 | if( object!=null ) { 41 | String str = object.toString(); 42 | for( Enum enumKey : enums ) { 43 | if( enumKey.name().equals(str)) { 44 | retList[i] = enumKey; 45 | } 46 | } 47 | } 48 | i++; 49 | } 50 | return retList; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/LongArrayConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.convertors; 31 | 32 | import com.tuyang.beanutils.BeanCopyConvertor; 33 | 34 | @SuppressWarnings("rawtypes") 35 | public class LongArrayConvertor implements BeanCopyConvertor { 36 | 37 | @Override 38 | public Object convertTo(Object object) { 39 | long[] array = (long[]) object; 40 | Long[] retObject = new Long[array.length]; 41 | 42 | for( int i=0;i< array.length; i++) { 43 | retObject[i] = Long.valueOf(array[i]); 44 | } 45 | return retObject; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/LongObjectArrayConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.convertors; 31 | 32 | import com.tuyang.beanutils.BeanCopyConvertor; 33 | 34 | @SuppressWarnings("rawtypes") 35 | public class LongObjectArrayConvertor implements BeanCopyConvertor { 36 | 37 | @Override 38 | public Object convertTo(Object object) { 39 | Long[] array = (Long[]) object; 40 | long[] retObject = new long[array.length]; 41 | 42 | for( int i=0;i< array.length; i++) { 43 | retObject[i] = array[i].longValue(); 44 | } 45 | return retObject; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/ObjectArrayConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.convertors; 31 | 32 | import java.lang.reflect.Array; 33 | 34 | import com.tuyang.beanutils.BeanCopyConvertor; 35 | import com.tuyang.beanutils.BeanCopyUtils; 36 | 37 | @SuppressWarnings("rawtypes") 38 | public class ObjectArrayConvertor implements BeanCopyConvertor { 39 | 40 | private Class methodTargetType; 41 | private Class methodSourceType; 42 | private Class propertyOptionClass; 43 | 44 | 45 | public ObjectArrayConvertor( Class methodSourceType, Class methodTargetType, Class propertyOptionClass) { 46 | this.methodSourceType = methodSourceType; 47 | this.methodTargetType = methodTargetType; 48 | this.propertyOptionClass = propertyOptionClass; 49 | } 50 | 51 | @Override 52 | public Object convertTo(Object object) { 53 | if( !object.getClass().isArray() ) 54 | return null; 55 | if( !methodSourceType.equals(object.getClass().getComponentType())) 56 | return null; 57 | int length = Array.getLength(object); 58 | Object[] retObject = (Object[]) Array.newInstance(methodTargetType, length ); 59 | for( int i =0; i { 7 | 8 | private Class enumClass; 9 | private boolean throwExceptions; 10 | 11 | public ObjectToEnumConvertor(Class enumClass, boolean throwExceptions) { 12 | this.enumClass = enumClass; 13 | this.throwExceptions = throwExceptions; 14 | } 15 | 16 | @SuppressWarnings("unchecked") 17 | @Override 18 | public Enum convertTo(Object object) { 19 | if( object == null ) 20 | return null; 21 | if( throwExceptions ) { 22 | return Enum.valueOf(enumClass, object.toString()); 23 | } 24 | Enum[] enums = (Enum[])enumClass.getEnumConstants(); 25 | for( Enum enumKey : enums ) { 26 | if( enumKey.name().equals(object.toString())) { 27 | return enumKey; 28 | } 29 | } 30 | return null; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/ObjectToStringArrayConvertor.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.beanutils.internal.convertors; 2 | 3 | import java.lang.reflect.Array; 4 | import java.util.Collection; 5 | 6 | import com.tuyang.beanutils.BeanCopyConvertor; 7 | 8 | public class ObjectToStringArrayConvertor implements BeanCopyConvertor { 9 | 10 | @SuppressWarnings("rawtypes") 11 | @Override 12 | public String[] convertTo(Object object) { 13 | if( object == null) 14 | return null; 15 | if( object.getClass().isArray() ) { 16 | int count = Array.getLength(object); 17 | String[] retList = new String[count]; 18 | for( int i =0; i< count; i++ ) { 19 | retList[i] = Array.get(object, i) != null ? Array.get(object, i).toString(): null; 20 | } 21 | return retList; 22 | } 23 | else if( object instanceof Collection ) { 24 | Collection collection = (Collection) object; 25 | String[] retList = new String[collection.size()]; 26 | int i =0; 27 | for(Object object2 : collection) { 28 | retList[i++] = object2!=null?object2.toString():null; 29 | } 30 | return retList; 31 | } 32 | return null; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/ObjectToStringConvertor.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.beanutils.internal.convertors; 2 | 3 | import com.tuyang.beanutils.BeanCopyConvertor; 4 | 5 | public class ObjectToStringConvertor implements BeanCopyConvertor { 6 | 7 | @Override 8 | public String convertTo(Object object) { 9 | if( object == null) 10 | return null; 11 | return object.toString(); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/ShortArrayConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.convertors; 31 | 32 | import com.tuyang.beanutils.BeanCopyConvertor; 33 | 34 | @SuppressWarnings("rawtypes") 35 | public class ShortArrayConvertor implements BeanCopyConvertor { 36 | 37 | @Override 38 | public Object convertTo(Object object) { 39 | short[] array = (short[]) object; 40 | Short[] retObject = new Short[array.length]; 41 | 42 | for( int i=0;i< array.length; i++) { 43 | retObject[i] = Short.valueOf(array[i]); 44 | } 45 | return retObject; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/ShortObjectArrayConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.convertors; 31 | 32 | import com.tuyang.beanutils.BeanCopyConvertor; 33 | 34 | @SuppressWarnings("rawtypes") 35 | public class ShortObjectArrayConvertor implements BeanCopyConvertor { 36 | 37 | @Override 38 | public Object convertTo(Object object) { 39 | Short[] array = (Short[]) object; 40 | short[] retObject = new short[array.length]; 41 | 42 | for( int i=0;i< array.length; i++) { 43 | retObject[i] = array[i].shortValue(); 44 | } 45 | return retObject; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/convertors/StringToEnumArrayConvertor.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.beanutils.internal.convertors; 2 | 3 | import java.lang.reflect.Array; 4 | 5 | import com.tuyang.beanutils.BeanCopyConvertor; 6 | 7 | @SuppressWarnings("rawtypes") 8 | public class StringToEnumArrayConvertor implements BeanCopyConvertor { 9 | 10 | private Class enumClass; 11 | private boolean throwExceptions; 12 | 13 | public StringToEnumArrayConvertor(Class enumClass, boolean throwExceptions) { 14 | this.enumClass = enumClass; 15 | this.throwExceptions = throwExceptions; 16 | } 17 | 18 | @SuppressWarnings("unchecked") 19 | @Override 20 | public Object[] convertTo(String[] object) { 21 | if( object == null ) 22 | return null; 23 | 24 | Object[] retList = (Object[]) Array.newInstance(enumClass, object.length); 25 | if( throwExceptions ) { 26 | for( int i =0; i< object.length;i++ ) { 27 | retList[i] = Enum.valueOf(enumClass, object[i]); 28 | } 29 | return retList; 30 | } 31 | Enum[] enums = (Enum[])enumClass.getEnumConstants(); 32 | for( int i =0; i< object.length;i++ ) { 33 | for( Enum enumKey : enums ) { 34 | if( enumKey.name().equals(object[i])) { 35 | retList[i] = enumKey; 36 | } 37 | } 38 | } 39 | return retList; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/factory/BeanCopierFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.factory; 31 | 32 | import java.util.List; 33 | 34 | import com.tuyang.beanutils.BeanCopier; 35 | import com.tuyang.beanutils.annotation.CopyFeature; 36 | import com.tuyang.beanutils.internal.cache.BeanCopyPropertyItem; 37 | 38 | public interface BeanCopierFactory { 39 | 40 | public BeanCopier createBeanCopier(Class sourceClass, Class targetClass, List items, CopyFeature[] features); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/reflect/ReflactBeanCopyFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.reflect; 31 | 32 | import java.util.List; 33 | 34 | import com.tuyang.beanutils.BeanCopier; 35 | import com.tuyang.beanutils.annotation.CopyFeature; 36 | import com.tuyang.beanutils.internal.cache.BeanCopyPropertyItem; 37 | import com.tuyang.beanutils.internal.factory.BeanCopierFactory; 38 | 39 | public class ReflactBeanCopyFactory implements BeanCopierFactory { 40 | 41 | @Override 42 | public BeanCopier createBeanCopier(Class sourceClass, Class targetClass, List items, CopyFeature[] features) { 43 | return new ReflectBeanCopy(items, features); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/reflect/ReflectBeanCopy.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.reflect; 31 | 32 | import java.lang.reflect.InvocationTargetException; 33 | import java.util.Collection; 34 | import java.util.List; 35 | 36 | import com.tuyang.beanutils.BeanCopier; 37 | import com.tuyang.beanutils.BeanCopyConvertor; 38 | import com.tuyang.beanutils.BeanCopyUtils; 39 | import com.tuyang.beanutils.annotation.CopyFeature; 40 | import com.tuyang.beanutils.exception.BeanCopyException; 41 | import com.tuyang.beanutils.internal.cache.BeanCopyPropertyItem; 42 | import com.tuyang.beanutils.internal.logger.Logger; 43 | import com.tuyang.beanutils.internal.utils.InstanceUtils; 44 | 45 | @SuppressWarnings("rawtypes") 46 | public class ReflectBeanCopy implements BeanCopier { 47 | 48 | private static Logger logger = Logger.getLogger(BeanCopyUtils.class); 49 | 50 | private List items ; 51 | private CopyFeature[] features; 52 | 53 | public ReflectBeanCopy(List items, CopyFeature[] features) { 54 | this.items = items; 55 | this.features = features; 56 | } 57 | 58 | @SuppressWarnings( "unchecked") 59 | public Object copyBean(Object sourceObject, Object targetObject) { 60 | 61 | for( BeanCopyPropertyItem item: items ) { 62 | 63 | Class targetPropertyType = item.writeMethod.getParameterTypes()[0]; 64 | 65 | if( item.isCollection ) { 66 | 67 | try { 68 | Object targetValue = sourceObject; 69 | for( int i =0; i< item.readMethods.length; i++ ) { 70 | targetValue = item.readMethods[i].invoke(targetValue); 71 | } 72 | 73 | if( item.useBeanCopy ) { 74 | Object writeObject = null; 75 | if (item.collectionClass != null ) 76 | writeObject = InstanceUtils.unsafeCopyCollection(targetValue, item.collectionClass, item.optionClass, targetPropertyType, features); 77 | else 78 | writeObject = InstanceUtils.unsafeCopyArray(targetValue, targetPropertyType.getComponentType(), item.optionClass, features); 79 | item.writeMethod.invoke(targetObject, writeObject); 80 | } else { 81 | Collection collectionRead = (Collection) targetValue; 82 | Collection collectionWrite = null; 83 | 84 | if(collectionRead!= null ) { 85 | collectionWrite = InstanceUtils.newCollection(targetPropertyType); 86 | if( collectionWrite == null ) { 87 | logger.error("beanCopy: cannot copy collection property " + targetPropertyType.getSimpleName() ); 88 | throw new BeanCopyException("beanCopy: cannot copy collection property " + targetPropertyType.getSimpleName() ); 89 | } 90 | for( Object sourceObj: collectionRead ) { 91 | Object targetCollectionObject = BeanCopyUtils.copyBean(sourceObj, item.collectionClass, item.optionClass ); 92 | collectionWrite.add(targetCollectionObject); 93 | } 94 | } 95 | 96 | item.writeMethod.invoke(targetObject, collectionWrite); 97 | } 98 | 99 | } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { 100 | logger.warn("beanCopy: cannot invoke property copy on " + item.writeMethod.getName(), e ); 101 | throw new BeanCopyException("beanCopy: cannot invoke property copy on " + item.writeMethod.getName(), e ); 102 | } 103 | 104 | } else { 105 | 106 | try { 107 | 108 | Object targetValue = sourceObject; 109 | for( int i =0; i< item.readMethods.length && targetValue != null; i++ ) { 110 | targetValue = item.readMethods[i].invoke(targetValue); 111 | } 112 | 113 | Object sourceData = targetValue; 114 | 115 | if( item.convertorObject != null ) { 116 | sourceData = item.convertorObject.convertTo(sourceData); 117 | } 118 | else if( item.convertorClass != null ) { 119 | BeanCopyConvertor convertor = (BeanCopyConvertor) InstanceUtils.newInstance(item.convertorClass); 120 | sourceData = convertor.convertTo(sourceData); 121 | 122 | } else if( item.optionClass != null ) { 123 | if( sourceData != null ) { 124 | sourceData = BeanCopyUtils.copyBean(sourceData, targetPropertyType, item.optionClass); 125 | } 126 | } else if( item.useBeanCopy ) { 127 | sourceData = BeanCopyUtils.copyBean(sourceData, targetPropertyType); 128 | } 129 | boolean ignoreInvoke = false; 130 | if( targetPropertyType.isPrimitive() && sourceData == null ) { 131 | ignoreInvoke = findFeature( CopyFeature.IGNORE_PRIMITIVE_NULL_SOURCE_VALUE ); 132 | } 133 | if( !ignoreInvoke && sourceData == null) { 134 | ignoreInvoke = findFeature( CopyFeature.IGNORE_ALL_NULL_SOURCE_VALUE ); 135 | } 136 | if( !ignoreInvoke ) { 137 | item.writeMethod.invoke(targetObject, sourceData ); 138 | } 139 | 140 | } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | ClassCastException e) { 141 | logger.warn("beanCopy: cannot invoke property copy on " + item.writeMethod.getName(), e ); 142 | throw new BeanCopyException("beanCopy: cannot invoke property copy on " + item.writeMethod.getName(), e ); 143 | } 144 | } 145 | } 146 | return targetObject; 147 | } 148 | 149 | private boolean findFeature(CopyFeature feature ) { 150 | if( features == null || features.length == 0 ) 151 | return false; 152 | for( CopyFeature f : features ) { 153 | if( f == feature ) 154 | return true; 155 | } 156 | return false; 157 | } 158 | 159 | } 160 | -------------------------------------------------------------------------------- /src/main/java/com/tuyang/beanutils/internal/utils/PropertyUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | BeanUtils Version 1.0.0 3 | 4 | Created by yangtu222 on 2017.08.05 5 | 6 | Distributed under the permissive zlib License 7 | Get the latest version from here: 8 | 9 | https://github.com/yangtu222/BeanUtils 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 24 | 2. Altered source versions must be plainly marked as such, and must not be 25 | misrepresented as being the original software. 26 | 27 | 3. This notice may not be removed or altered from any source distribution. 28 | */ 29 | 30 | package com.tuyang.beanutils.internal.utils; 31 | 32 | import java.beans.BeanInfo; 33 | import java.beans.IntrospectionException; 34 | import java.beans.Introspector; 35 | import java.beans.PropertyDescriptor; 36 | import java.lang.ref.WeakReference; 37 | import java.lang.reflect.Field; 38 | import java.util.HashMap; 39 | import java.util.IdentityHashMap; 40 | import java.util.Map; 41 | 42 | public class PropertyUtils { 43 | 44 | private static Map, WeakReference> cacheMap = new HashMap<>(); 45 | 46 | public static PropertyDescriptor getPropertyDescriptor(Class clazz, String propertyName) { 47 | 48 | PropertyDescriptor[] allPds = null; 49 | synchronized (cacheMap) { 50 | WeakReference pdsRef = cacheMap.get(clazz); 51 | if( pdsRef != null ) { 52 | allPds = pdsRef.get(); 53 | } 54 | } 55 | if( allPds == null ) { 56 | allPds = getPropertyDescriptors(clazz); 57 | 58 | } 59 | for( PropertyDescriptor pd : allPds ) { 60 | if( propertyName.equals(pd.getName() ) ) { 61 | return pd; 62 | } 63 | } 64 | return null; 65 | } 66 | 67 | public static PropertyDescriptor[] getPropertyDescriptors(Class clazz) { 68 | 69 | PropertyDescriptor[] allPds = null; 70 | synchronized (cacheMap) { 71 | WeakReference pdsRef = cacheMap.get(clazz); 72 | if( pdsRef != null ) { 73 | allPds = pdsRef.get(); 74 | if( allPds != null ) 75 | return allPds; 76 | } 77 | } 78 | 79 | try { 80 | BeanInfo beanInfo = Introspector.getBeanInfo(clazz); 81 | allPds = beanInfo.getPropertyDescriptors(); 82 | synchronized (cacheMap) { 83 | cacheMap.put(clazz, new WeakReference(allPds)); 84 | } 85 | return allPds; 86 | } catch (IntrospectionException e) { 87 | return new PropertyDescriptor[0]; 88 | } 89 | } 90 | 91 | public static Field getClassField(Class targetClass, Class optionClass, String propertyName) { 92 | 93 | Field propertyField = null; 94 | 95 | if( optionClass != null ) { 96 | try { 97 | propertyField = optionClass.getDeclaredField(propertyName); 98 | } catch (NoSuchFieldException | SecurityException e) { 99 | } 100 | } 101 | if( propertyField == null ) { 102 | 103 | Class tryClass = targetClass; 104 | while( tryClass != null ) { 105 | try { 106 | propertyField = tryClass.getDeclaredField(propertyName); 107 | return propertyField; 108 | } catch (NoSuchFieldException | SecurityException e) { 109 | tryClass = tryClass.getSuperclass(); 110 | } 111 | } 112 | } 113 | return propertyField; 114 | } 115 | 116 | public static boolean isInterfaceType(Class classType, Class interfaceType) { 117 | 118 | if( classType.equals(interfaceType) ) { 119 | return true; 120 | } 121 | 122 | while( classType != null ) { 123 | Class[] interfaces = classType.getInterfaces(); 124 | 125 | for( Class interClass : interfaces ) { 126 | if( interClass.equals(interfaceType) ) { 127 | return true; 128 | } 129 | } 130 | classType = classType.getSuperclass(); 131 | } 132 | 133 | return false; 134 | } 135 | 136 | private static final Map, Class> primitiveWrapperTypeMap = new IdentityHashMap, Class>(8); 137 | 138 | static { 139 | primitiveWrapperTypeMap.put(Boolean.class, boolean.class); 140 | primitiveWrapperTypeMap.put(Byte.class, byte.class); 141 | primitiveWrapperTypeMap.put(Character.class, char.class); 142 | primitiveWrapperTypeMap.put(Double.class, double.class); 143 | primitiveWrapperTypeMap.put(Float.class, float.class); 144 | primitiveWrapperTypeMap.put(Integer.class, int.class); 145 | primitiveWrapperTypeMap.put(Long.class, long.class); 146 | primitiveWrapperTypeMap.put(Short.class, short.class); 147 | } 148 | 149 | public static boolean isPrimitive(Class classType) { 150 | if( classType.isPrimitive() ) 151 | return true; 152 | 153 | for( Class resolvedWrapper : primitiveWrapperTypeMap.keySet() ) { 154 | if( classType.equals(resolvedWrapper) ) { 155 | return true; 156 | } 157 | } 158 | if( classType.equals(String.class ) ) 159 | return true; 160 | 161 | return false; 162 | } 163 | 164 | public static boolean isAssignable(Class lhsType, Class rhsType) { 165 | if (lhsType.isAssignableFrom(rhsType)) { 166 | return true; 167 | } 168 | if (lhsType.isPrimitive()) { 169 | Class resolvedPrimitive = primitiveWrapperTypeMap.get(rhsType); 170 | if (lhsType == resolvedPrimitive) { 171 | return true; 172 | } 173 | } 174 | else if( rhsType.isPrimitive() ) { 175 | Class resolvedPrimitive = primitiveWrapperTypeMap.get(lhsType); 176 | if (rhsType == resolvedPrimitive) { 177 | return true; 178 | } 179 | } 180 | return false; 181 | } 182 | 183 | } 184 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/perftest/BeanCopyInterface.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.perftest; 2 | 3 | public interface BeanCopyInterface { 4 | 5 | String getMethodName(); 6 | ToBean callCopyBean(FromBean fromBean) throws Exception; 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/perftest/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.perftest; 2 | 3 | public class FromBean { 4 | 5 | private boolean beanBool; 6 | private byte beanByte; 7 | private char beanChar; 8 | private short beanShort; 9 | private int beanInt; 10 | private long beanLong; 11 | private float beanFloat; 12 | private double beanDouble; 13 | private String beanString; 14 | public boolean isBeanBool() { 15 | return beanBool; 16 | } 17 | public void setBeanBool(boolean beanBool) { 18 | this.beanBool = beanBool; 19 | } 20 | public byte getBeanByte() { 21 | return beanByte; 22 | } 23 | public void setBeanByte(byte beanByte) { 24 | this.beanByte = beanByte; 25 | } 26 | public char getBeanChar() { 27 | return beanChar; 28 | } 29 | public void setBeanChar(char beanChar) { 30 | this.beanChar = beanChar; 31 | } 32 | public short getBeanShort() { 33 | return beanShort; 34 | } 35 | public void setBeanShort(short beanShort) { 36 | this.beanShort = beanShort; 37 | } 38 | public int getBeanInt() { 39 | return beanInt; 40 | } 41 | public void setBeanInt(int beanInt) { 42 | this.beanInt = beanInt; 43 | } 44 | public long getBeanLong() { 45 | return beanLong; 46 | } 47 | public void setBeanLong(long beanLong) { 48 | this.beanLong = beanLong; 49 | } 50 | public float getBeanFloat() { 51 | return beanFloat; 52 | } 53 | public void setBeanFloat(float beanFloat) { 54 | this.beanFloat = beanFloat; 55 | } 56 | public double getBeanDouble() { 57 | return beanDouble; 58 | } 59 | public void setBeanDouble(double beanDouble) { 60 | this.beanDouble = beanDouble; 61 | } 62 | public String getBeanString() { 63 | return beanString; 64 | } 65 | public void setBeanString(String beanString) { 66 | this.beanString = beanString; 67 | } 68 | 69 | 70 | 71 | 72 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/perftest/LoopTest.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.perftest; 2 | 3 | public class LoopTest { 4 | 5 | private int count; 6 | 7 | public LoopTest( int count) { 8 | this.count = count; 9 | System.out.println("=================================="); 10 | System.out.println(String.format("Run Test for %d times:", count)); 11 | } 12 | 13 | public ToBean run(BeanCopyInterface method, FromBean fromBean ) { 14 | try { 15 | ToBean toBean = null; 16 | String methodName = method.getMethodName(); 17 | long begin = System.currentTimeMillis(); 18 | 19 | for (int i = 0; i < count; i++) { 20 | toBean = method.callCopyBean(fromBean); 21 | } 22 | long end = System.currentTimeMillis(); 23 | System.out.println(String.format("Run %s: %d ms", methodName, end - begin)); 24 | return toBean; 25 | } catch (Exception e) { 26 | e.printStackTrace(); 27 | } 28 | return null; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/perftest/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.perftest; 2 | 3 | public class ToBean { 4 | 5 | private boolean beanBool; 6 | private byte beanByte; 7 | private char beanChar; 8 | private short beanShort; 9 | private int beanInt; 10 | private long beanLong; 11 | private float beanFloat; 12 | private double beanDouble; 13 | private String beanString; 14 | 15 | public boolean isBeanBool() { 16 | return beanBool; 17 | } 18 | public void setBeanBool(boolean beanBool) { 19 | this.beanBool = beanBool; 20 | } 21 | public byte getBeanByte() { 22 | return beanByte; 23 | } 24 | public void setBeanByte(byte beanByte) { 25 | this.beanByte = beanByte; 26 | } 27 | public char getBeanChar() { 28 | return beanChar; 29 | } 30 | public void setBeanChar(char beanChar) { 31 | this.beanChar = beanChar; 32 | } 33 | public short getBeanShort() { 34 | return beanShort; 35 | } 36 | public void setBeanShort(short beanShort) { 37 | this.beanShort = beanShort; 38 | } 39 | public int getBeanInt() { 40 | return beanInt; 41 | } 42 | public void setBeanInt(int beanInt) { 43 | this.beanInt = beanInt; 44 | } 45 | public long getBeanLong() { 46 | return beanLong; 47 | } 48 | public void setBeanLong(long beanLong) { 49 | this.beanLong = beanLong; 50 | } 51 | public float getBeanFloat() { 52 | return beanFloat; 53 | } 54 | public void setBeanFloat(float beanFloat) { 55 | this.beanFloat = beanFloat; 56 | } 57 | public double getBeanDouble() { 58 | return beanDouble; 59 | } 60 | public void setBeanDouble(double beanDouble) { 61 | this.beanDouble = beanDouble; 62 | } 63 | public String getBeanString() { 64 | return beanString; 65 | } 66 | public void setBeanString(String beanString) { 67 | this.beanString = beanString; 68 | } 69 | 70 | 71 | 72 | 73 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testAnnotation/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testAnnotation; 2 | 3 | public class FromBean { 4 | 5 | private int beanInt; 6 | private long beanLong; 7 | 8 | private String beanString; 9 | 10 | public int getBeanInt() { 11 | return beanInt; 12 | } 13 | 14 | public void setBeanInt(int beanInt) { 15 | this.beanInt = beanInt; 16 | } 17 | 18 | public long getBeanLong() { 19 | return beanLong; 20 | } 21 | 22 | public void setBeanLong(long beanLong) { 23 | this.beanLong = beanLong; 24 | } 25 | public String getBeanString() { 26 | return beanString; 27 | } 28 | 29 | public void setBeanString(String beanString) { 30 | this.beanString = beanString; 31 | } 32 | 33 | 34 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testAnnotation/Test03.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testAnnotation; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | import com.tuyang.beanutils.BeanCopyUtils; 8 | 9 | public class Test03 { 10 | 11 | private FromBean getFromBean() { 12 | FromBean fromBean = new FromBean(); 13 | fromBean.setBeanInt(100); 14 | fromBean.setBeanLong(200); 15 | fromBean.setBeanString("Test test Test test."); 16 | return fromBean; 17 | } 18 | 19 | @Test 20 | public void testAnnotation() { 21 | FromBean fromBean = getFromBean(); 22 | ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class); 23 | assertEquals( fromBean.getBeanInt(), toBean.getToInt().intValue() ); 24 | assertEquals( 0, toBean.getBeanLong()); 25 | assertEquals( fromBean.getBeanString(), toBean.getBeanString() ); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testAnnotation/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testAnnotation; 2 | 3 | import com.tuyang.beanutils.annotation.CopyProperty; 4 | import com.tuyang.beanutils.annotation.BeanCopySource; 5 | 6 | @BeanCopySource(source=FromBean.class) 7 | public class ToBean { 8 | 9 | @CopyProperty(property="beanInt") 10 | private Integer toInt; 11 | @CopyProperty(ignored=true) 12 | private long beanLong; 13 | 14 | private String beanString; 15 | 16 | public Integer getToInt() { 17 | return toInt; 18 | } 19 | public void setToInt(Integer toInt) { 20 | this.toInt = toInt; 21 | } 22 | public long getBeanLong() { 23 | return beanLong; 24 | } 25 | public void setBeanLong(long beanLong) { 26 | this.beanLong = beanLong; 27 | } 28 | public String getBeanString() { 29 | return beanString; 30 | } 31 | public void setBeanString(String beanString) { 32 | this.beanString = beanString; 33 | } 34 | 35 | 36 | 37 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testAnnotation2/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testAnnotation2; 2 | 3 | import java.util.List; 4 | 5 | public class FromBean { 6 | 7 | private int beanInt; 8 | private long beanLong; 9 | 10 | private String beanString; 11 | 12 | FromBean2 bean2; 13 | 14 | private List beanList; 15 | 16 | public int getBeanInt() { 17 | return beanInt; 18 | } 19 | 20 | public void setBeanInt(int beanInt) { 21 | this.beanInt = beanInt; 22 | } 23 | 24 | public long getBeanLong() { 25 | return beanLong; 26 | } 27 | 28 | public void setBeanLong(long beanLong) { 29 | this.beanLong = beanLong; 30 | } 31 | 32 | public String getBeanString() { 33 | return beanString; 34 | } 35 | 36 | public void setBeanString(String beanString) { 37 | this.beanString = beanString; 38 | } 39 | 40 | public FromBean2 getBean2() { 41 | return bean2; 42 | } 43 | 44 | public void setBean2(FromBean2 bean2) { 45 | this.bean2 = bean2; 46 | } 47 | 48 | public List getBeanList() { 49 | return beanList; 50 | } 51 | 52 | public void setBeanList(List beanList) { 53 | this.beanList = beanList; 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testAnnotation2/FromBean2.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testAnnotation2; 2 | 3 | public class FromBean2 { 4 | 5 | private Float beanFloat; 6 | private String beanString; 7 | 8 | public Float getBeanFloat() { 9 | return beanFloat; 10 | } 11 | public void setBeanFloat(Float beanFloat) { 12 | this.beanFloat = beanFloat; 13 | } 14 | public String getBeanString() { 15 | return beanString; 16 | } 17 | public void setBeanString(String beanString) { 18 | this.beanString = beanString; 19 | } 20 | 21 | 22 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testAnnotation2/Test04.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testAnnotation2; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | 10 | import com.tuyang.beanutils.BeanCopyUtils; 11 | 12 | public class Test04 { 13 | 14 | private FromBean getFromBean() { 15 | FromBean fromBean = new FromBean(); 16 | fromBean.setBeanInt(100); 17 | fromBean.setBeanLong(200); 18 | fromBean.setBeanString("Test test Test test."); 19 | 20 | FromBean2 bean2 = new FromBean2(); 21 | bean2.setBeanFloat(10.4f); 22 | bean2.setBeanString("bean2"); 23 | 24 | fromBean.setBean2(bean2); 25 | 26 | List list = new ArrayList<>(); 27 | list.add(bean2); 28 | list.add(bean2); 29 | fromBean.setBeanList(list); 30 | 31 | return fromBean; 32 | } 33 | 34 | @Test 35 | public void testAnnotation2() { 36 | FromBean fromBean = getFromBean(); 37 | ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class); 38 | assertNotNull(toBean.getBean2()); 39 | assertEquals( toBean.getBeanList().size(), 2 ); 40 | assertEquals( fromBean.getBeanInt(), toBean.getBeanInt().intValue() ); 41 | assertEquals( fromBean.getBeanLong(), toBean.getBeanLong()); 42 | assertEquals( fromBean.getBeanString(), toBean.getBeanString() ); 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testAnnotation2/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testAnnotation2; 2 | 3 | import java.util.List; 4 | 5 | import com.tuyang.beanutils.annotation.CopyProperty; 6 | import com.tuyang.beanutils.annotation.BeanCopySource; 7 | 8 | @BeanCopySource(source=FromBean.class) 9 | public class ToBean { 10 | 11 | private Integer beanInt; 12 | private long beanLong; 13 | private String beanString; 14 | 15 | @CopyProperty 16 | private ToBean2 bean2; 17 | 18 | private List beanList; 19 | 20 | public Integer getBeanInt() { 21 | return beanInt; 22 | } 23 | 24 | public void setBeanInt(Integer beanInt) { 25 | this.beanInt = beanInt; 26 | } 27 | 28 | public long getBeanLong() { 29 | return beanLong; 30 | } 31 | 32 | public void setBeanLong(long beanLong) { 33 | this.beanLong = beanLong; 34 | } 35 | 36 | public String getBeanString() { 37 | return beanString; 38 | } 39 | 40 | public void setBeanString(String beanString) { 41 | this.beanString = beanString; 42 | } 43 | 44 | public List getBeanList() { 45 | return beanList; 46 | } 47 | 48 | public void setBeanList(List beanList) { 49 | this.beanList = beanList; 50 | } 51 | 52 | public ToBean2 getBean2() { 53 | return bean2; 54 | } 55 | 56 | public void setBean2(ToBean2 bean2) { 57 | this.bean2 = bean2; 58 | } 59 | 60 | 61 | 62 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testAnnotation2/ToBean2.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testAnnotation2; 2 | 3 | public class ToBean2 { 4 | 5 | private Float beanFloat; 6 | private String beanString; 7 | 8 | public Float getBeanFloat() { 9 | return beanFloat; 10 | } 11 | public void setBeanFloat(Float beanFloat) { 12 | this.beanFloat = beanFloat; 13 | } 14 | public String getBeanString() { 15 | return beanString; 16 | } 17 | public void setBeanString(String beanString) { 18 | this.beanString = beanString; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testArray/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testArray; 2 | 3 | public class FromBean { 4 | 5 | private boolean beanBool; 6 | private int beanInt; 7 | private String beanString; 8 | 9 | private int[] beanIntArray; 10 | private long[] beanLongArray; 11 | private Float[] beanFloatArray; 12 | private Double[] beanDoubleArray; 13 | 14 | private FromBean2[] bean2s; 15 | 16 | public boolean isBeanBool() { 17 | return beanBool; 18 | } 19 | public void setBeanBool(boolean beanBool) { 20 | this.beanBool = beanBool; 21 | } 22 | public int getBeanInt() { 23 | return beanInt; 24 | } 25 | public void setBeanInt(int beanInt) { 26 | this.beanInt = beanInt; 27 | } 28 | public String getBeanString() { 29 | return beanString; 30 | } 31 | public void setBeanString(String beanString) { 32 | this.beanString = beanString; 33 | } 34 | public int[] getBeanIntArray() { 35 | return beanIntArray; 36 | } 37 | public void setBeanIntArray(int[] beanIntArray) { 38 | this.beanIntArray = beanIntArray; 39 | } 40 | public long[] getBeanLongArray() { 41 | return beanLongArray; 42 | } 43 | public void setBeanLongArray(long[] beanLongArray) { 44 | this.beanLongArray = beanLongArray; 45 | } 46 | public Float[] getBeanFloatArray() { 47 | return beanFloatArray; 48 | } 49 | public void setBeanFloatArray(Float[] beanFloatArray) { 50 | this.beanFloatArray = beanFloatArray; 51 | } 52 | public Double[] getBeanDoubleArray() { 53 | return beanDoubleArray; 54 | } 55 | public void setBeanDoubleArray(Double[] beanDoubleArray) { 56 | this.beanDoubleArray = beanDoubleArray; 57 | } 58 | public FromBean2[] getBean2s() { 59 | return bean2s; 60 | } 61 | public void setBean2s(FromBean2[] bean2s) { 62 | this.bean2s = bean2s; 63 | } 64 | 65 | 66 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testArray/FromBean2.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testArray; 2 | 3 | public class FromBean2 { 4 | 5 | private Float beanFloat; 6 | private String beanString; 7 | 8 | public Float getBeanFloat() { 9 | return beanFloat; 10 | } 11 | public void setBeanFloat(Float beanFloat) { 12 | this.beanFloat = beanFloat; 13 | } 14 | public String getBeanString() { 15 | return beanString; 16 | } 17 | public void setBeanString(String beanString) { 18 | this.beanString = beanString; 19 | } 20 | 21 | 22 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testArray/Test08.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testArray; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | import com.tuyang.beanutils.BeanCopyUtils; 8 | 9 | public class Test08 { 10 | 11 | private FromBean getFromBean() { 12 | FromBean fromBean = new FromBean(); 13 | fromBean.setBeanBool(true); 14 | fromBean.setBeanInt(100); 15 | fromBean.setBeanString("Test test Test test."); 16 | 17 | int[] intArray = new int[3]; 18 | intArray[0] = 100; 19 | intArray[1] = 200; 20 | intArray[2] = 300; 21 | fromBean.setBeanIntArray(intArray); 22 | 23 | long[] longArray = new long[3]; 24 | longArray[0] = 1000; 25 | longArray[1] = 2000; 26 | longArray[2] = 3000; 27 | fromBean.setBeanLongArray(longArray); 28 | 29 | Float[] floatArray = new Float[3]; 30 | floatArray[0] = new Float(100.1); 31 | floatArray[1] = new Float(100.2); 32 | floatArray[2] = new Float(100.3); 33 | fromBean.setBeanFloatArray(floatArray); 34 | 35 | 36 | Double[] doubles = new Double[3]; 37 | doubles[0] = new Double(100.11); 38 | doubles[1] = new Double(100.22); 39 | doubles[2] = new Double(100.33); 40 | fromBean.setBeanDoubleArray(doubles); 41 | 42 | FromBean2[] bean2s = new FromBean2[3]; 43 | 44 | FromBean2 bean2 = new FromBean2(); 45 | bean2.setBeanFloat(10.5f); 46 | bean2.setBeanString("bean2"); 47 | bean2s[0] = bean2; 48 | bean2s[1] = bean2; 49 | bean2s[2] = bean2; 50 | fromBean.setBean2s(bean2s); 51 | 52 | return fromBean; 53 | } 54 | 55 | @Test 56 | public void testArray() { 57 | FromBean fromBean = getFromBean(); 58 | ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class); 59 | assertEquals(fromBean.getBean2s().length, toBean.getToBeans().length); 60 | assertEquals(fromBean.getBeanIntArray().length, toBean.getBeanIntArray().length); 61 | assertEquals(fromBean.getBeanLongArray().length, toBean.getBeanLongArray().length); 62 | assertEquals(fromBean.getBeanFloatArray().length, toBean.getBeanFloatArray().length); 63 | assertEquals(fromBean.getBeanDoubleArray().length, toBean.getBeanDoubleArray().length); 64 | 65 | assertEquals(fromBean.isBeanBool(), toBean.isBeanBool() ); 66 | assertEquals( fromBean.getBeanInt(), toBean.getBeanInt() ); 67 | assertEquals( fromBean.getBeanString(), toBean.getBeanString() ); 68 | } 69 | } 70 | 71 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testArray/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testArray; 2 | 3 | import com.tuyang.beanutils.annotation.CopyProperty; 4 | import com.tuyang.beanutils.annotation.BeanCopySource; 5 | 6 | @BeanCopySource(source=FromBean.class) 7 | public class ToBean { 8 | 9 | private boolean beanBool; 10 | private int beanInt; 11 | private String beanString; 12 | 13 | private int[] beanIntArray; 14 | private Long[] beanLongArray; 15 | private Float[] beanFloatArray; 16 | private double[] beanDoubleArray; 17 | 18 | @CopyProperty(property="bean2s") 19 | private ToBean2[] toBeans; 20 | 21 | public boolean isBeanBool() { 22 | return beanBool; 23 | } 24 | public void setBeanBool(boolean beanBool) { 25 | this.beanBool = beanBool; 26 | } 27 | public int getBeanInt() { 28 | return beanInt; 29 | } 30 | public void setBeanInt(int beanInt) { 31 | this.beanInt = beanInt; 32 | } 33 | public String getBeanString() { 34 | return beanString; 35 | } 36 | public void setBeanString(String beanString) { 37 | this.beanString = beanString; 38 | } 39 | public int[] getBeanIntArray() { 40 | return beanIntArray; 41 | } 42 | public void setBeanIntArray(int[] beanIntArray) { 43 | this.beanIntArray = beanIntArray; 44 | } 45 | public Long[] getBeanLongArray() { 46 | return beanLongArray; 47 | } 48 | public void setBeanLongArray(Long[] beanLongArray) { 49 | this.beanLongArray = beanLongArray; 50 | } 51 | public Float[] getBeanFloatArray() { 52 | return beanFloatArray; 53 | } 54 | public void setBeanFloatArray(Float[] beanFloatArray) { 55 | this.beanFloatArray = beanFloatArray; 56 | } 57 | public double[] getBeanDoubleArray() { 58 | return beanDoubleArray; 59 | } 60 | public void setBeanDoubleArray(double[] beanDoubleArray) { 61 | this.beanDoubleArray = beanDoubleArray; 62 | } 63 | public ToBean2[] getToBeans() { 64 | return toBeans; 65 | } 66 | public void setToBeans(ToBean2[] toBeans) { 67 | this.toBeans = toBeans; 68 | } 69 | 70 | 71 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testArray/ToBean2.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testArray; 2 | 3 | public class ToBean2 { 4 | 5 | private Float beanFloat; 6 | private String beanString; 7 | 8 | public Float getBeanFloat() { 9 | return beanFloat; 10 | } 11 | public void setBeanFloat(Float beanFloat) { 12 | this.beanFloat = beanFloat; 13 | } 14 | public String getBeanString() { 15 | return beanString; 16 | } 17 | public void setBeanString(String beanString) { 18 | this.beanString = beanString; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testArrayList/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testArrayList; 2 | 3 | import java.util.List; 4 | 5 | public class FromBean { 6 | 7 | private boolean beanBool; 8 | private int beanInt; 9 | private String beanString; 10 | 11 | private int[] beanIntArray; 12 | private Long[] beanLongArray; 13 | private List beanFloatArray; 14 | private List beanDoubleArray; 15 | 16 | private FromBean2[] bean2s; 17 | 18 | private List bean2sList; 19 | 20 | public boolean isBeanBool() { 21 | return beanBool; 22 | } 23 | 24 | public void setBeanBool(boolean beanBool) { 25 | this.beanBool = beanBool; 26 | } 27 | 28 | public int getBeanInt() { 29 | return beanInt; 30 | } 31 | 32 | public void setBeanInt(int beanInt) { 33 | this.beanInt = beanInt; 34 | } 35 | 36 | public String getBeanString() { 37 | return beanString; 38 | } 39 | 40 | public void setBeanString(String beanString) { 41 | this.beanString = beanString; 42 | } 43 | 44 | public int[] getBeanIntArray() { 45 | return beanIntArray; 46 | } 47 | 48 | public void setBeanIntArray(int[] beanIntArray) { 49 | this.beanIntArray = beanIntArray; 50 | } 51 | 52 | public Long[] getBeanLongArray() { 53 | return beanLongArray; 54 | } 55 | 56 | public void setBeanLongArray(Long[] beanLongArray) { 57 | this.beanLongArray = beanLongArray; 58 | } 59 | 60 | public List getBeanFloatArray() { 61 | return beanFloatArray; 62 | } 63 | 64 | public void setBeanFloatArray(List beanFloatArray) { 65 | this.beanFloatArray = beanFloatArray; 66 | } 67 | 68 | public List getBeanDoubleArray() { 69 | return beanDoubleArray; 70 | } 71 | 72 | public void setBeanDoubleArray(List beanDoubleArray) { 73 | this.beanDoubleArray = beanDoubleArray; 74 | } 75 | 76 | public FromBean2[] getBean2s() { 77 | return bean2s; 78 | } 79 | 80 | public void setBean2s(FromBean2[] bean2s) { 81 | this.bean2s = bean2s; 82 | } 83 | 84 | public List getBean2sList() { 85 | return bean2sList; 86 | } 87 | 88 | public void setBean2sList(List bean2sList) { 89 | this.bean2sList = bean2sList; 90 | } 91 | 92 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testArrayList/FromBean2.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testArrayList; 2 | 3 | public class FromBean2 { 4 | 5 | private Float beanFloat; 6 | private String beanString; 7 | 8 | public Float getBeanFloat() { 9 | return beanFloat; 10 | } 11 | public void setBeanFloat(Float beanFloat) { 12 | this.beanFloat = beanFloat; 13 | } 14 | public String getBeanString() { 15 | return beanString; 16 | } 17 | public void setBeanString(String beanString) { 18 | this.beanString = beanString; 19 | } 20 | 21 | 22 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testArrayList/Test08.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testArrayList; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | 10 | import com.tuyang.beanutils.BeanCopyUtils; 11 | 12 | public class Test08 { 13 | 14 | private FromBean getFromBean() { 15 | FromBean fromBean = new FromBean(); 16 | fromBean.setBeanBool(true); 17 | fromBean.setBeanInt(100); 18 | fromBean.setBeanString("Test test Test test."); 19 | 20 | int[] intArray = new int[3]; 21 | intArray[0] = 100; 22 | intArray[1] = 200; 23 | intArray[2] = 300; 24 | fromBean.setBeanIntArray(intArray); 25 | 26 | Long[] longArray = new Long[3]; 27 | longArray[0] = Long.valueOf(1000); 28 | longArray[1] = Long.valueOf(2000); 29 | longArray[2] = Long.valueOf(3000); 30 | fromBean.setBeanLongArray(longArray); 31 | 32 | List floatArray = new ArrayList<>(); 33 | floatArray.add(new Float(100.1)); 34 | floatArray.add(new Float(100.2)); 35 | floatArray.add(new Float(100.3)); 36 | fromBean.setBeanFloatArray(floatArray); 37 | 38 | 39 | List doubles = new ArrayList<>(); 40 | doubles.add(new Double(100.11)); 41 | doubles.add(new Double(100.22)); 42 | doubles.add(new Double(100.33)); 43 | 44 | fromBean.setBeanDoubleArray(doubles); 45 | 46 | FromBean2[] bean2s = new FromBean2[3]; 47 | 48 | FromBean2 bean2 = new FromBean2(); 49 | bean2.setBeanFloat(10.5f); 50 | bean2.setBeanString("bean2"); 51 | bean2s[0] = bean2; 52 | bean2s[1] = bean2; 53 | bean2s[2] = bean2; 54 | fromBean.setBean2s(bean2s); 55 | 56 | List bean2sList = new ArrayList<>(); 57 | bean2sList.add(bean2); 58 | bean2sList.add(bean2); 59 | bean2sList.add(bean2); 60 | bean2sList.add(bean2); 61 | 62 | fromBean.setBean2sList(bean2sList); 63 | return fromBean; 64 | } 65 | 66 | @Test 67 | public void testArrayList() { 68 | FromBean fromBean = getFromBean(); 69 | ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class); 70 | assertEquals(fromBean.getBean2s().length, toBean.getToBeans().size()); 71 | assertEquals(fromBean.getBean2sList().size(), toBean.getBean2sList().length); 72 | 73 | assertEquals(fromBean.getBeanIntArray().length, toBean.getBeanIntArray().size()); 74 | assertEquals(fromBean.getBeanLongArray().length, toBean.getBeanLongArray().size()); 75 | assertEquals(fromBean.getBeanFloatArray().size(), toBean.getBeanFloatArray().length); 76 | assertEquals(fromBean.getBeanDoubleArray().size(), toBean.getBeanDoubleArray().length); 77 | 78 | assertEquals(fromBean.isBeanBool(), toBean.isBeanBool() ); 79 | assertEquals( fromBean.getBeanInt(), toBean.getBeanInt() ); 80 | assertEquals( fromBean.getBeanString(), toBean.getBeanString() ); 81 | } 82 | } 83 | 84 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testArrayList/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testArrayList; 2 | 3 | import com.tuyang.beanutils.annotation.CopyProperty; 4 | 5 | import java.util.List; 6 | 7 | import com.tuyang.beanutils.annotation.BeanCopySource; 8 | import com.tuyang.beanutils.annotation.CopyCollection; 9 | 10 | @BeanCopySource(source=FromBean.class) 11 | public class ToBean { 12 | 13 | private boolean beanBool; 14 | private int beanInt; 15 | private String beanString; 16 | 17 | @CopyCollection(targetClass=Integer.class) 18 | private List beanIntArray; 19 | @CopyCollection(targetClass=Long.class) 20 | private List beanLongArray; 21 | @CopyProperty 22 | private Float[] beanFloatArray; 23 | @CopyProperty 24 | private double[] beanDoubleArray; 25 | 26 | @CopyCollection(property="bean2s", targetClass=ToBean2.class) 27 | private List toBeans; 28 | 29 | @CopyProperty(property="bean2sList") 30 | private ToBean2[] bean2sList; 31 | 32 | public boolean isBeanBool() { 33 | return beanBool; 34 | } 35 | 36 | public void setBeanBool(boolean beanBool) { 37 | this.beanBool = beanBool; 38 | } 39 | 40 | public int getBeanInt() { 41 | return beanInt; 42 | } 43 | 44 | public void setBeanInt(int beanInt) { 45 | this.beanInt = beanInt; 46 | } 47 | 48 | public String getBeanString() { 49 | return beanString; 50 | } 51 | 52 | public void setBeanString(String beanString) { 53 | this.beanString = beanString; 54 | } 55 | 56 | public List getBeanIntArray() { 57 | return beanIntArray; 58 | } 59 | 60 | public void setBeanIntArray(List beanIntArray) { 61 | this.beanIntArray = beanIntArray; 62 | } 63 | 64 | public List getBeanLongArray() { 65 | return beanLongArray; 66 | } 67 | 68 | public void setBeanLongArray(List beanLongArray) { 69 | this.beanLongArray = beanLongArray; 70 | } 71 | 72 | public Float[] getBeanFloatArray() { 73 | return beanFloatArray; 74 | } 75 | 76 | public void setBeanFloatArray(Float[] beanFloatArray) { 77 | this.beanFloatArray = beanFloatArray; 78 | } 79 | 80 | public double[] getBeanDoubleArray() { 81 | return beanDoubleArray; 82 | } 83 | 84 | public void setBeanDoubleArray(double[] beanDoubleArray) { 85 | this.beanDoubleArray = beanDoubleArray; 86 | } 87 | 88 | public List getToBeans() { 89 | return toBeans; 90 | } 91 | 92 | public void setToBeans(List toBeans) { 93 | this.toBeans = toBeans; 94 | } 95 | 96 | public ToBean2[] getBean2sList() { 97 | return bean2sList; 98 | } 99 | 100 | public void setBean2sList(ToBean2[] bean2sList) { 101 | this.bean2sList = bean2sList; 102 | } 103 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testArrayList/ToBean2.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testArrayList; 2 | 3 | public class ToBean2 { 4 | 5 | private Float beanFloat; 6 | private String beanString; 7 | 8 | public Float getBeanFloat() { 9 | return beanFloat; 10 | } 11 | public void setBeanFloat(Float beanFloat) { 12 | this.beanFloat = beanFloat; 13 | } 14 | public String getBeanString() { 15 | return beanString; 16 | } 17 | public void setBeanString(String beanString) { 18 | this.beanString = beanString; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testArrayList2/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testArrayList2; 2 | 3 | public class FromBean { 4 | 5 | private boolean beanBool; 6 | private int beanInt; 7 | private String beanString; 8 | 9 | public boolean isBeanBool() { 10 | return beanBool; 11 | } 12 | public void setBeanBool(boolean beanBool) { 13 | this.beanBool = beanBool; 14 | } 15 | public int getBeanInt() { 16 | return beanInt; 17 | } 18 | public void setBeanInt(int beanInt) { 19 | this.beanInt = beanInt; 20 | } 21 | public String getBeanString() { 22 | return beanString; 23 | } 24 | public void setBeanString(String beanString) { 25 | this.beanString = beanString; 26 | } 27 | 28 | 29 | 30 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testArrayList2/TestArrayList.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testArrayList2; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | 10 | import com.tuyang.beanutils.BeanCopyUtils; 11 | 12 | public class TestArrayList { 13 | 14 | private FromBean getFromBean() { 15 | FromBean fromBean = new FromBean(); 16 | fromBean.setBeanBool(true); 17 | fromBean.setBeanInt(100); 18 | fromBean.setBeanString("Test test Test test."); 19 | 20 | return fromBean; 21 | } 22 | 23 | @Test 24 | public void testListToArray() { 25 | FromBean fromBean = getFromBean(); 26 | List fromBeanList = Arrays.asList(fromBean, fromBean, fromBean); 27 | ToBean[] toBeanArray = BeanCopyUtils.copyArray(fromBeanList, ToBean.class); 28 | 29 | assertEquals(fromBean.isBeanBool(), toBeanArray[0].isBeanBool() ); 30 | assertEquals( fromBean.getBeanInt(), toBeanArray[1].getBeanInt() ); 31 | assertEquals( fromBean.getBeanString(), toBeanArray[2].getBeanString() ); 32 | } 33 | 34 | @Test 35 | public void testListToList() { 36 | FromBean fromBean = getFromBean(); 37 | List fromBeanList = Arrays.asList(fromBean, fromBean, fromBean); 38 | List toBeanList = BeanCopyUtils.copyList(fromBeanList, ToBean.class); 39 | 40 | assertEquals(fromBean.isBeanBool(), toBeanList.get(0).isBeanBool() ); 41 | assertEquals( fromBean.getBeanInt(), toBeanList.get(1).getBeanInt() ); 42 | assertEquals( fromBean.getBeanString(), toBeanList.get(2).getBeanString() ); 43 | } 44 | 45 | @Test 46 | public void testArrayToArray() { 47 | FromBean fromBean = getFromBean(); 48 | FromBean[] fromBeanList = new FromBean[3]; 49 | fromBeanList[0] = fromBean; 50 | fromBeanList[1] = fromBean; 51 | fromBeanList[2] = fromBean; 52 | ToBean[] toBeanArray = BeanCopyUtils.copyArray(fromBeanList, ToBean.class); 53 | 54 | assertEquals(fromBean.isBeanBool(), toBeanArray[0].isBeanBool() ); 55 | assertEquals( fromBean.getBeanInt(), toBeanArray[1].getBeanInt() ); 56 | assertEquals( fromBean.getBeanString(), toBeanArray[2].getBeanString() ); 57 | } 58 | 59 | @Test 60 | public void testArrayToList() { 61 | FromBean fromBean = getFromBean(); 62 | FromBean[] fromBeanList = new FromBean[3]; 63 | fromBeanList[0] = fromBean; 64 | fromBeanList[1] = fromBean; 65 | fromBeanList[2] = fromBean; 66 | List toBeanList = BeanCopyUtils.copyList(fromBeanList, ToBean.class); 67 | 68 | assertEquals(fromBean.isBeanBool(), toBeanList.get(0).isBeanBool() ); 69 | assertEquals( fromBean.getBeanInt(), toBeanList.get(1).getBeanInt() ); 70 | assertEquals( fromBean.getBeanString(), toBeanList.get(2).getBeanString() ); 71 | } 72 | } 73 | 74 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testArrayList2/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testArrayList2; 2 | 3 | import com.tuyang.beanutils.annotation.BeanCopySource; 4 | 5 | @BeanCopySource(source=FromBean.class) 6 | public class ToBean { 7 | 8 | private boolean beanBool; 9 | private int beanInt; 10 | private String beanString; 11 | public boolean isBeanBool() { 12 | return beanBool; 13 | } 14 | public void setBeanBool(boolean beanBool) { 15 | this.beanBool = beanBool; 16 | } 17 | public int getBeanInt() { 18 | return beanInt; 19 | } 20 | public void setBeanInt(int beanInt) { 21 | this.beanInt = beanInt; 22 | } 23 | public String getBeanString() { 24 | return beanString; 25 | } 26 | public void setBeanString(String beanString) { 27 | this.beanString = beanString; 28 | } 29 | 30 | 31 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testBasic/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testBasic; 2 | 3 | public class FromBean { 4 | 5 | private boolean beanBool; 6 | private byte beanByte; 7 | private char beanChar; 8 | private short beanShort; 9 | private int beanInt; 10 | private long beanLong; 11 | private float beanFloat; 12 | private double beanDouble; 13 | private String beanString; 14 | 15 | private int mId; 16 | 17 | public boolean isBeanBool() { 18 | return beanBool; 19 | } 20 | 21 | public void setBeanBool(boolean beanBool) { 22 | this.beanBool = beanBool; 23 | } 24 | 25 | public byte getBeanByte() { 26 | return beanByte; 27 | } 28 | 29 | public void setBeanByte(byte beanByte) { 30 | this.beanByte = beanByte; 31 | } 32 | 33 | public char getBeanChar() { 34 | return beanChar; 35 | } 36 | 37 | public void setBeanChar(char beanChar) { 38 | this.beanChar = beanChar; 39 | } 40 | 41 | public short getBeanShort() { 42 | return beanShort; 43 | } 44 | 45 | public void setBeanShort(short beanShort) { 46 | this.beanShort = beanShort; 47 | } 48 | 49 | public int getBeanInt() { 50 | return beanInt; 51 | } 52 | 53 | public void setBeanInt(int beanInt) { 54 | this.beanInt = beanInt; 55 | } 56 | 57 | public long getBeanLong() { 58 | return beanLong; 59 | } 60 | 61 | public void setBeanLong(long beanLong) { 62 | this.beanLong = beanLong; 63 | } 64 | 65 | public float getBeanFloat() { 66 | return beanFloat; 67 | } 68 | 69 | public void setBeanFloat(float beanFloat) { 70 | this.beanFloat = beanFloat; 71 | } 72 | 73 | public double getBeanDouble() { 74 | return beanDouble; 75 | } 76 | 77 | public void setBeanDouble(double beanDouble) { 78 | this.beanDouble = beanDouble; 79 | } 80 | 81 | public String getBeanString() { 82 | return beanString; 83 | } 84 | 85 | public void setBeanString(String beanString) { 86 | this.beanString = beanString; 87 | } 88 | 89 | public int getmId() { 90 | return mId; 91 | } 92 | 93 | public void setmId(int mId) { 94 | this.mId = mId; 95 | } 96 | 97 | 98 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testBasic/Test01.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testBasic; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | import com.tuyang.beanutils.BeanCopyUtils; 8 | import com.tuyang.beanutils.config.BeanCopyConfig; 9 | 10 | public class Test01 { 11 | 12 | private FromBean getFromBean() { 13 | FromBean fromBean = new FromBean(); 14 | fromBean.setBeanBool(true); 15 | fromBean.setBeanByte((byte)5); 16 | fromBean.setBeanChar((char)40); 17 | fromBean.setBeanShort((short)50); 18 | fromBean.setBeanInt(100); 19 | fromBean.setBeanFloat(100.50f); 20 | fromBean.setBeanLong(234323243243243234L); 21 | fromBean.setBeanDouble(2342332423.23432432523523); 22 | fromBean.setBeanString("Test test Test test."); 23 | fromBean.setmId(1000); 24 | return fromBean; 25 | } 26 | 27 | @Test 28 | public void testBasic() { 29 | FromBean fromBean = getFromBean(); 30 | ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class); 31 | assertEquals(fromBean.isBeanBool(), toBean.isBeanBool() ); 32 | assertEquals( fromBean.getBeanByte(), toBean.getBeanByte() ); 33 | assertEquals( fromBean.getBeanChar(), toBean.getBeanChar() ); 34 | assertEquals( fromBean.getBeanShort(), toBean.getBeanShort() ); 35 | assertEquals( fromBean.getBeanInt(), toBean.getBeanInt() ); 36 | assertEquals( fromBean.getBeanLong(), toBean.getBeanLong() ); 37 | assertEquals( fromBean.getBeanFloat(), toBean.getBeanFloat() , 0); 38 | assertEquals( fromBean.getBeanDouble(), toBean.getBeanDouble(), 0 ); 39 | assertEquals( fromBean.getBeanString(), toBean.getBeanString() ); 40 | assertEquals(fromBean.getmId(), toBean.getmId()); 41 | 42 | BeanCopyConfig.setBeanCopyConfig(null); 43 | 44 | ToBean toBean2 = BeanCopyUtils.copyBean(fromBean, ToBean.class); 45 | assertEquals(fromBean.isBeanBool(), toBean2.isBeanBool() ); 46 | 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testBasic/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testBasic; 2 | 3 | public class ToBean { 4 | 5 | private boolean beanBool; 6 | private byte beanByte; 7 | private char beanChar; 8 | private short beanShort; 9 | private int beanInt; 10 | private long beanLong; 11 | private float beanFloat; 12 | private double beanDouble; 13 | private String beanString; 14 | 15 | private int mId; 16 | 17 | public boolean isBeanBool() { 18 | return beanBool; 19 | } 20 | 21 | public void setBeanBool(boolean beanBool) { 22 | this.beanBool = beanBool; 23 | } 24 | 25 | public byte getBeanByte() { 26 | return beanByte; 27 | } 28 | 29 | public void setBeanByte(byte beanByte) { 30 | this.beanByte = beanByte; 31 | } 32 | 33 | public char getBeanChar() { 34 | return beanChar; 35 | } 36 | 37 | public void setBeanChar(char beanChar) { 38 | this.beanChar = beanChar; 39 | } 40 | 41 | public short getBeanShort() { 42 | return beanShort; 43 | } 44 | 45 | public void setBeanShort(short beanShort) { 46 | this.beanShort = beanShort; 47 | } 48 | 49 | public int getBeanInt() { 50 | return beanInt; 51 | } 52 | 53 | public void setBeanInt(int beanInt) { 54 | this.beanInt = beanInt; 55 | } 56 | 57 | public long getBeanLong() { 58 | return beanLong; 59 | } 60 | 61 | public void setBeanLong(long beanLong) { 62 | this.beanLong = beanLong; 63 | } 64 | 65 | public float getBeanFloat() { 66 | return beanFloat; 67 | } 68 | 69 | public void setBeanFloat(float beanFloat) { 70 | this.beanFloat = beanFloat; 71 | } 72 | 73 | public double getBeanDouble() { 74 | return beanDouble; 75 | } 76 | 77 | public void setBeanDouble(double beanDouble) { 78 | this.beanDouble = beanDouble; 79 | } 80 | 81 | public String getBeanString() { 82 | return beanString; 83 | } 84 | 85 | public void setBeanString(String beanString) { 86 | this.beanString = beanString; 87 | } 88 | 89 | public int getmId() { 90 | return mId; 91 | } 92 | 93 | public void setmId(int mId) { 94 | this.mId = mId; 95 | } 96 | 97 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testBeanToString/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testBeanToString; 2 | 3 | import java.util.List; 4 | 5 | public class FromBean { 6 | 7 | private int beanInt; 8 | private long beanLong; 9 | 10 | private String beanString; 11 | 12 | FromBean2 fromBean2; 13 | 14 | FromBean2[] fromBean2s; 15 | 16 | List fromBean2s2; 17 | 18 | public List getFromBean2s2() { 19 | return fromBean2s2; 20 | } 21 | 22 | public void setFromBean2s2(List fromBean2s2) { 23 | this.fromBean2s2 = fromBean2s2; 24 | } 25 | 26 | public int getBeanInt() { 27 | return beanInt; 28 | } 29 | 30 | public void setBeanInt(int beanInt) { 31 | this.beanInt = beanInt; 32 | } 33 | 34 | public long getBeanLong() { 35 | return beanLong; 36 | } 37 | 38 | public void setBeanLong(long beanLong) { 39 | this.beanLong = beanLong; 40 | } 41 | 42 | public String getBeanString() { 43 | return beanString; 44 | } 45 | 46 | public void setBeanString(String beanString) { 47 | this.beanString = beanString; 48 | } 49 | 50 | public FromBean2 getFromBean2() { 51 | return fromBean2; 52 | } 53 | 54 | public void setFromBean2(FromBean2 fromBean2) { 55 | this.fromBean2 = fromBean2; 56 | } 57 | 58 | public FromBean2[] getFromBean2s() { 59 | return fromBean2s; 60 | } 61 | 62 | public void setFromBean2s(FromBean2[] fromBean2s) { 63 | this.fromBean2s = fromBean2s; 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testBeanToString/FromBean2.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testBeanToString; 2 | 3 | public class FromBean2 { 4 | 5 | private Float beanFloat; 6 | private String beanString; 7 | 8 | public Float getBeanFloat() { 9 | return beanFloat; 10 | } 11 | public void setBeanFloat(Float beanFloat) { 12 | this.beanFloat = beanFloat; 13 | } 14 | public String getBeanString() { 15 | return beanString; 16 | } 17 | public void setBeanString(String beanString) { 18 | this.beanString = beanString; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return beanString + "|" + beanFloat; 24 | } 25 | 26 | 27 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testBeanToString/Test03.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testBeanToString; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.Arrays; 6 | 7 | import org.junit.Test; 8 | 9 | import com.tuyang.beanutils.BeanCopyUtils; 10 | 11 | public class Test03 { 12 | 13 | private FromBean getFromBean() { 14 | FromBean fromBean = new FromBean(); 15 | fromBean.setBeanInt(100); 16 | fromBean.setBeanLong(200); 17 | fromBean.setBeanString("Test test Test test."); 18 | 19 | FromBean2 bean2 = new FromBean2(); 20 | bean2.setBeanFloat(10.4f); 21 | bean2.setBeanString("bean2"); 22 | fromBean.setFromBean2(bean2); 23 | 24 | FromBean2[] bean2s = new FromBean2[2]; 25 | bean2s[0] = bean2; 26 | bean2s[1] = bean2; 27 | fromBean.setFromBean2s(bean2s); 28 | 29 | fromBean.setFromBean2s2(Arrays.asList(bean2s)); 30 | 31 | return fromBean; 32 | } 33 | 34 | @Test 35 | public void testAnnotation() { 36 | FromBean fromBean = getFromBean(); 37 | ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class); 38 | assertEquals( fromBean.getBeanInt(), toBean.getToInt().intValue() ); 39 | assertEquals( 0, toBean.getBeanLong()); 40 | assertEquals( fromBean.getBeanString(), toBean.getBeanString() ); 41 | assertEquals(fromBean.getFromBean2().toString(), toBean.getFromBean2()); 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testBeanToString/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testBeanToString; 2 | 3 | import com.tuyang.beanutils.annotation.CopyProperty; 4 | 5 | import java.util.List; 6 | 7 | import com.tuyang.beanutils.annotation.BeanCopySource; 8 | import com.tuyang.beanutils.annotation.CopyCollection; 9 | import com.tuyang.beanutils.annotation.CopyFeature; 10 | 11 | @BeanCopySource(source=FromBean.class, features={CopyFeature.ENABLE_JAVA_BEAN_TO_STRING}) 12 | public class ToBean { 13 | 14 | @CopyProperty(property="beanInt") 15 | private Integer toInt; 16 | @CopyProperty(ignored=true) 17 | private long beanLong; 18 | 19 | private String beanString; 20 | 21 | @CopyProperty 22 | private String fromBean2; 23 | 24 | @CopyProperty 25 | private String[] fromBean2s; 26 | 27 | @CopyCollection(property="fromBean2s2", targetClass=String.class) 28 | List fromBean2s2_1; 29 | 30 | @CopyProperty(property="fromBean2s2") 31 | private String[] fromBean2s2_2; 32 | 33 | public List getFromBean2s2_1() { 34 | return fromBean2s2_1; 35 | } 36 | 37 | public void setFromBean2s2_1(List fromBean2s2_1) { 38 | this.fromBean2s2_1 = fromBean2s2_1; 39 | } 40 | 41 | public String[] getFromBean2s2_2() { 42 | return fromBean2s2_2; 43 | } 44 | 45 | public void setFromBean2s2_2(String[] fromBean2s2_2) { 46 | this.fromBean2s2_2 = fromBean2s2_2; 47 | } 48 | 49 | public Integer getToInt() { 50 | return toInt; 51 | } 52 | 53 | public void setToInt(Integer toInt) { 54 | this.toInt = toInt; 55 | } 56 | 57 | public long getBeanLong() { 58 | return beanLong; 59 | } 60 | 61 | public void setBeanLong(long beanLong) { 62 | this.beanLong = beanLong; 63 | } 64 | 65 | public String getBeanString() { 66 | return beanString; 67 | } 68 | 69 | public void setBeanString(String beanString) { 70 | this.beanString = beanString; 71 | } 72 | 73 | public String getFromBean2() { 74 | return fromBean2; 75 | } 76 | 77 | public void setFromBean2(String fromBean2) { 78 | this.fromBean2 = fromBean2; 79 | } 80 | 81 | public String[] getFromBean2s() { 82 | return fromBean2s; 83 | } 84 | 85 | public void setFromBean2s(String[] fromBean2s) { 86 | this.fromBean2s = fromBean2s; 87 | } 88 | 89 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testCollection/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testCollection; 2 | 3 | import java.util.List; 4 | 5 | public class FromBean { 6 | 7 | private int beanInt; 8 | private long beanLong; 9 | 10 | private String beanString; 11 | 12 | private List beanList; 13 | 14 | public int getBeanInt() { 15 | return beanInt; 16 | } 17 | 18 | public void setBeanInt(int beanInt) { 19 | this.beanInt = beanInt; 20 | } 21 | 22 | public long getBeanLong() { 23 | return beanLong; 24 | } 25 | 26 | public void setBeanLong(long beanLong) { 27 | this.beanLong = beanLong; 28 | } 29 | public String getBeanString() { 30 | return beanString; 31 | } 32 | 33 | public void setBeanString(String beanString) { 34 | this.beanString = beanString; 35 | } 36 | 37 | public List getBeanList() { 38 | return beanList; 39 | } 40 | 41 | public void setBeanList(List beanList) { 42 | this.beanList = beanList; 43 | } 44 | 45 | 46 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testCollection/FromBean2.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testCollection; 2 | 3 | public class FromBean2 { 4 | 5 | private Float beanFloat; 6 | private String beanString; 7 | 8 | public Float getBeanFloat() { 9 | return beanFloat; 10 | } 11 | public void setBeanFloat(Float beanFloat) { 12 | this.beanFloat = beanFloat; 13 | } 14 | public String getBeanString() { 15 | return beanString; 16 | } 17 | public void setBeanString(String beanString) { 18 | this.beanString = beanString; 19 | } 20 | 21 | 22 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testCollection/Test05.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testCollection; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | 10 | import com.tuyang.beanutils.BeanCopyUtils; 11 | 12 | public class Test05 { 13 | 14 | private FromBean getFromBean() { 15 | FromBean fromBean = new FromBean(); 16 | fromBean.setBeanInt(100); 17 | fromBean.setBeanLong(200); 18 | fromBean.setBeanString("Test test Test test."); 19 | 20 | FromBean2 bean2 = new FromBean2(); 21 | bean2.setBeanFloat(10.4f); 22 | bean2.setBeanString("bean2"); 23 | 24 | List list = new ArrayList<>(); 25 | list.add(bean2); 26 | list.add(bean2); 27 | fromBean.setBeanList(list); 28 | 29 | return fromBean; 30 | } 31 | 32 | @Test 33 | public void testCollection() { 34 | FromBean fromBean = getFromBean(); 35 | ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class); 36 | assertEquals( toBean.getBeanList().size(), 2 ); 37 | assertEquals( fromBean.getBeanInt(), toBean.getBeanInt().intValue() ); 38 | assertEquals( fromBean.getBeanLong(), toBean.getBeanLong()); 39 | assertEquals( fromBean.getBeanString(), toBean.getBeanString() ); 40 | } 41 | 42 | @Test 43 | public void testCollection2() { 44 | FromBean fromBean = getFromBean(); 45 | List fromList = new ArrayList<>(); 46 | fromList.add(fromBean); 47 | fromList.add(fromBean); 48 | fromList.add(fromBean); 49 | 50 | List toList = BeanCopyUtils.copyList(fromList, ToBean.class); 51 | 52 | assertEquals(toList.size(), 3); 53 | 54 | assertEquals( fromBean.getBeanInt(), toList.get(0).getBeanInt().intValue() ); 55 | assertEquals( fromBean.getBeanLong(), toList.get(1).getBeanLong()); 56 | assertEquals( fromBean.getBeanString(), toList.get(2).getBeanString() ); 57 | 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testCollection/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testCollection; 2 | 3 | import java.util.List; 4 | 5 | import com.tuyang.beanutils.annotation.CopyCollection; 6 | import com.tuyang.beanutils.annotation.BeanCopySource; 7 | 8 | @BeanCopySource(source=FromBean.class) 9 | public class ToBean { 10 | 11 | private Integer beanInt; 12 | private long beanLong; 13 | private String beanString; 14 | 15 | @CopyCollection(targetClass=ToBean2.class) 16 | private List beanList; 17 | 18 | public Integer getBeanInt() { 19 | return beanInt; 20 | } 21 | 22 | public void setBeanInt(Integer beanInt) { 23 | this.beanInt = beanInt; 24 | } 25 | 26 | public long getBeanLong() { 27 | return beanLong; 28 | } 29 | 30 | public void setBeanLong(long beanLong) { 31 | this.beanLong = beanLong; 32 | } 33 | 34 | public String getBeanString() { 35 | return beanString; 36 | } 37 | 38 | public void setBeanString(String beanString) { 39 | this.beanString = beanString; 40 | } 41 | 42 | public List getBeanList() { 43 | return beanList; 44 | } 45 | 46 | public void setBeanList(List beanList) { 47 | this.beanList = beanList; 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testCollection/ToBean2.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testCollection; 2 | 3 | public class ToBean2 { 4 | 5 | private Float beanFloat; 6 | private String beanString; 7 | 8 | public Float getBeanFloat() { 9 | return beanFloat; 10 | } 11 | public void setBeanFloat(Float beanFloat) { 12 | this.beanFloat = beanFloat; 13 | } 14 | public String getBeanString() { 15 | return beanString; 16 | } 17 | public void setBeanString(String beanString) { 18 | this.beanString = beanString; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testConvertor/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testConvertor; 2 | 3 | import java.util.Date; 4 | 5 | public class FromBean { 6 | 7 | private boolean beanBool; 8 | private String beanString; 9 | 10 | private int gendor; 11 | 12 | private MyEnum myEnum; 13 | 14 | private String fromEnumString; 15 | 16 | private Date dateNow; 17 | 18 | public boolean isBeanBool() { 19 | return beanBool; 20 | } 21 | 22 | public void setBeanBool(boolean beanBool) { 23 | this.beanBool = beanBool; 24 | } 25 | 26 | public String getBeanString() { 27 | return beanString; 28 | } 29 | 30 | public void setBeanString(String beanString) { 31 | this.beanString = beanString; 32 | } 33 | 34 | public int getGendor() { 35 | return gendor; 36 | } 37 | 38 | public void setGendor(int gendor) { 39 | this.gendor = gendor; 40 | } 41 | 42 | public MyEnum getMyEnum() { 43 | return myEnum; 44 | } 45 | 46 | public void setMyEnum(MyEnum myEnum) { 47 | this.myEnum = myEnum; 48 | } 49 | 50 | public String getFromEnumString() { 51 | return fromEnumString; 52 | } 53 | 54 | public void setFromEnumString(String fromEnumString) { 55 | this.fromEnumString = fromEnumString; 56 | } 57 | 58 | public Date getDateNow() { 59 | return dateNow; 60 | } 61 | 62 | public void setDateNow(Date dateNow) { 63 | this.dateNow = dateNow; 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testConvertor/GendorConvertor.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testConvertor; 2 | 3 | import com.tuyang.beanutils.BeanCopyConvertor; 4 | 5 | public class GendorConvertor implements BeanCopyConvertor { 6 | 7 | @Override 8 | public String convertTo(Integer object) { 9 | if( object == 1 ) 10 | return "Male"; 11 | if( object == 2) 12 | return "Female"; 13 | return "Unknown"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testConvertor/MyEnum.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testConvertor; 2 | 3 | public enum MyEnum { 4 | One, 5 | Two, 6 | Three 7 | } 8 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testConvertor/MyEnumConvertor.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testConvertor; 2 | 3 | import com.tuyang.beanutils.BeanCopyConvertor; 4 | 5 | public class MyEnumConvertor implements BeanCopyConvertor { 6 | 7 | @Override 8 | public String convertTo(MyEnum object) { 9 | if( object == MyEnum.One) 10 | return "One"; 11 | if( object == MyEnum.Two) 12 | return "Two"; 13 | if( object == MyEnum.Three) 14 | return "Three"; 15 | return ""; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testConvertor/Test11.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testConvertor; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.Date; 6 | 7 | import org.junit.Test; 8 | 9 | import com.tuyang.beanutils.BeanCopyUtils; 10 | 11 | public class Test11 { 12 | 13 | private FromBean getFromBean() { 14 | FromBean fromBean = new FromBean(); 15 | fromBean.setBeanBool(true); 16 | fromBean.setBeanString("Test test Test test."); 17 | 18 | fromBean.setGendor(1); 19 | fromBean.setMyEnum(MyEnum.Two); 20 | fromBean.setFromEnumString("Three"); 21 | fromBean.setDateNow(new Date()); 22 | 23 | return fromBean; 24 | } 25 | 26 | @Test 27 | public void testBasic() { 28 | 29 | FromBean fromBean = getFromBean(); 30 | 31 | ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class); 32 | assertEquals(fromBean.isBeanBool(), toBean.isBeanBool() ); 33 | assertEquals( fromBean.getBeanString(), toBean.getBeanString() ); 34 | 35 | assertEquals(toBean.getGendor(), "Male"); 36 | assertEquals(toBean.getMyEnumString(), "Two"); 37 | assertEquals(toBean.getToEnum(), MyEnum.Three); 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testConvertor/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testConvertor; 2 | 3 | import com.tuyang.beanutils.annotation.BeanCopySource; 4 | import com.tuyang.beanutils.annotation.CopyFeature; 5 | import com.tuyang.beanutils.annotation.CopyProperty; 6 | 7 | @BeanCopySource(source=FromBean.class, features={CopyFeature.IGNORE_ENUM_CONVERT_EXCEPTION, CopyFeature.ENABLE_JAVA_BEAN_TO_STRING}) 8 | public class ToBean { 9 | 10 | private boolean beanBool; 11 | private String beanString; 12 | 13 | @CopyProperty(property="myEnum") 14 | private String myEnumString; 15 | 16 | @CopyProperty(convertor=GendorConvertor.class) 17 | private String gendor; 18 | 19 | @CopyProperty(property="fromEnumString") 20 | private MyEnum toEnum; 21 | 22 | @CopyProperty 23 | private String dateNow; 24 | 25 | public boolean isBeanBool() { 26 | return beanBool; 27 | } 28 | 29 | public void setBeanBool(boolean beanBool) { 30 | this.beanBool = beanBool; 31 | } 32 | 33 | public String getBeanString() { 34 | return beanString; 35 | } 36 | 37 | public void setBeanString(String beanString) { 38 | this.beanString = beanString; 39 | } 40 | 41 | public String getMyEnumString() { 42 | return myEnumString; 43 | } 44 | 45 | public void setMyEnumString(String myEnumString) { 46 | this.myEnumString = myEnumString; 47 | } 48 | 49 | public String getGendor() { 50 | return gendor; 51 | } 52 | 53 | public void setGendor(String gendor) { 54 | this.gendor = gendor; 55 | } 56 | 57 | public MyEnum getToEnum() { 58 | return toEnum; 59 | } 60 | 61 | public void setToEnum(MyEnum toEnum) { 62 | this.toEnum = toEnum; 63 | } 64 | 65 | public String getDateNow() { 66 | return dateNow; 67 | } 68 | 69 | public void setDateNow(String dateNow) { 70 | this.dateNow = dateNow; 71 | } 72 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testEnum/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testEnum; 2 | 3 | import java.util.List; 4 | 5 | public class FromBean { 6 | 7 | private MyEnum myEnum1; 8 | private MyEnum myEnum2; 9 | 10 | private String enumString; 11 | 12 | private MyEnum[] myEnums1; 13 | private MyEnum[] myEnums2; 14 | 15 | private String[] enumStrings; 16 | 17 | private List myEnums3; 18 | 19 | private List eStrings; 20 | 21 | public MyEnum getMyEnum1() { 22 | return myEnum1; 23 | } 24 | 25 | public void setMyEnum1(MyEnum myEnum1) { 26 | this.myEnum1 = myEnum1; 27 | } 28 | 29 | public MyEnum getMyEnum2() { 30 | return myEnum2; 31 | } 32 | 33 | public void setMyEnum2(MyEnum myEnum2) { 34 | this.myEnum2 = myEnum2; 35 | } 36 | 37 | public String getEnumString() { 38 | return enumString; 39 | } 40 | 41 | public void setEnumString(String enumString) { 42 | this.enumString = enumString; 43 | } 44 | 45 | public MyEnum[] getMyEnums1() { 46 | return myEnums1; 47 | } 48 | 49 | public void setMyEnums1(MyEnum[] myEnums1) { 50 | this.myEnums1 = myEnums1; 51 | } 52 | 53 | public MyEnum[] getMyEnums2() { 54 | return myEnums2; 55 | } 56 | 57 | public void setMyEnums2(MyEnum[] myEnums2) { 58 | this.myEnums2 = myEnums2; 59 | } 60 | 61 | public String[] getEnumStrings() { 62 | return enumStrings; 63 | } 64 | 65 | public void setEnumStrings(String[] enumStrings) { 66 | this.enumStrings = enumStrings; 67 | } 68 | 69 | public List getMyEnums3() { 70 | return myEnums3; 71 | } 72 | 73 | public void setMyEnums3(List myEnums3) { 74 | this.myEnums3 = myEnums3; 75 | } 76 | 77 | public List geteStrings() { 78 | return eStrings; 79 | } 80 | 81 | public void seteStrings(List eStrings) { 82 | this.eStrings = eStrings; 83 | } 84 | 85 | 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testEnum/MyEnum.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testEnum; 2 | 3 | public enum MyEnum { 4 | One, 5 | Two, 6 | Three 7 | } 8 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testEnum/Test08.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testEnum; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.lang.reflect.Array; 6 | import java.util.Arrays; 7 | 8 | import org.junit.Test; 9 | 10 | import com.tuyang.beanutils.BeanCopyUtils; 11 | 12 | public class Test08 { 13 | 14 | private FromBean getFromBean() { 15 | FromBean fromBean = new FromBean(); 16 | 17 | fromBean.setMyEnum1(MyEnum.One); 18 | fromBean.setMyEnum2(MyEnum.Two); 19 | fromBean.setEnumString(MyEnum.Three.toString()); 20 | 21 | MyEnum[] array = new MyEnum[2]; 22 | array[0]= MyEnum.One; 23 | array[1] = MyEnum.Three; 24 | fromBean.setMyEnums1(array); 25 | fromBean.setMyEnums2(array); 26 | fromBean.setMyEnums3(Arrays.asList(array)); 27 | 28 | String[] enumStrings = new String[2]; 29 | enumStrings[0] = MyEnum.Three.toString(); 30 | enumStrings[1] = MyEnum.Two.toString(); 31 | 32 | fromBean.setEnumStrings(enumStrings); 33 | fromBean.seteStrings(Arrays.asList(enumStrings)); 34 | 35 | return fromBean; 36 | } 37 | 38 | @Test 39 | public void testEnum() { 40 | FromBean fromBean = getFromBean(); 41 | ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class); 42 | 43 | assertEquals(toBean.getMyEnum1(), MyEnum.One); 44 | assertEquals(toBean.getMyEnum2(), MyEnum.Two.toString()); 45 | assertEquals(toBean.getEnumString(), MyEnum.Three); 46 | assertEquals(toBean.getMyEnums1()[1], MyEnum.Three); 47 | assertEquals(toBean.getMyEnums2()[1], MyEnum.Three.toString()); 48 | assertEquals(toBean.getMyEnums3().get(1), MyEnum.Three); 49 | assertEquals(toBean.geteStrings().get(1), MyEnum.Two); 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testEnum/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testEnum; 2 | 3 | import com.tuyang.beanutils.annotation.CopyProperty; 4 | 5 | import java.util.List; 6 | 7 | import com.tuyang.beanutils.annotation.BeanCopySource; 8 | import com.tuyang.beanutils.annotation.CopyCollection; 9 | 10 | @BeanCopySource(source=FromBean.class) 11 | public class ToBean { 12 | 13 | private MyEnum myEnum1; 14 | 15 | @CopyProperty 16 | private String myEnum2; 17 | 18 | @CopyProperty 19 | private MyEnum enumString; 20 | 21 | @CopyProperty 22 | private MyEnum[] myEnums1; 23 | 24 | @CopyProperty 25 | private String[] myEnums2; 26 | 27 | @CopyProperty 28 | private MyEnum[] enumStrings; 29 | 30 | @CopyCollection(targetClass = MyEnum.class) 31 | private List myEnums3; 32 | 33 | @CopyCollection(targetClass= MyEnum.class) 34 | private List eStrings; 35 | 36 | public MyEnum getMyEnum1() { 37 | return myEnum1; 38 | } 39 | 40 | public void setMyEnum1(MyEnum myEnum1) { 41 | this.myEnum1 = myEnum1; 42 | } 43 | 44 | public String getMyEnum2() { 45 | return myEnum2; 46 | } 47 | 48 | public void setMyEnum2(String myEnum2) { 49 | this.myEnum2 = myEnum2; 50 | } 51 | 52 | public MyEnum getEnumString() { 53 | return enumString; 54 | } 55 | 56 | public void setEnumString(MyEnum enumString) { 57 | this.enumString = enumString; 58 | } 59 | 60 | public MyEnum[] getMyEnums1() { 61 | return myEnums1; 62 | } 63 | 64 | public void setMyEnums1(MyEnum[] myEnums1) { 65 | this.myEnums1 = myEnums1; 66 | } 67 | 68 | public String[] getMyEnums2() { 69 | return myEnums2; 70 | } 71 | 72 | public void setMyEnums2(String[] myEnums2) { 73 | this.myEnums2 = myEnums2; 74 | } 75 | 76 | public MyEnum[] getEnumStrings() { 77 | return enumStrings; 78 | } 79 | 80 | public void setEnumStrings(MyEnum[] enumStrings) { 81 | this.enumStrings = enumStrings; 82 | } 83 | 84 | public List getMyEnums3() { 85 | return myEnums3; 86 | } 87 | 88 | public void setMyEnums3(List myEnums3) { 89 | this.myEnums3 = myEnums3; 90 | } 91 | 92 | public List geteStrings() { 93 | return eStrings; 94 | } 95 | 96 | public void seteStrings(List eStrings) { 97 | this.eStrings = eStrings; 98 | } 99 | 100 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testEnum2/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testEnum2; 2 | 3 | import java.util.List; 4 | 5 | public class FromBean { 6 | 7 | private MyEnum myEnum1; 8 | private MyEnum myEnum2; 9 | 10 | private String enumString; 11 | 12 | private MyEnum[] myEnums1; 13 | private MyEnum[] myEnums2; 14 | 15 | private String[] enumStrings; 16 | 17 | private List myEnums3; 18 | 19 | private List eStrings; 20 | 21 | private Inside inside; 22 | 23 | public Inside getInside() { 24 | return inside; 25 | } 26 | 27 | public void setInside(Inside inside) { 28 | this.inside = inside; 29 | } 30 | 31 | public MyEnum getMyEnum1() { 32 | return myEnum1; 33 | } 34 | 35 | public void setMyEnum1(MyEnum myEnum1) { 36 | this.myEnum1 = myEnum1; 37 | } 38 | 39 | public MyEnum getMyEnum2() { 40 | return myEnum2; 41 | } 42 | 43 | public void setMyEnum2(MyEnum myEnum2) { 44 | this.myEnum2 = myEnum2; 45 | } 46 | 47 | public String getEnumString() { 48 | return enumString; 49 | } 50 | 51 | public void setEnumString(String enumString) { 52 | this.enumString = enumString; 53 | } 54 | 55 | public MyEnum[] getMyEnums1() { 56 | return myEnums1; 57 | } 58 | 59 | public void setMyEnums1(MyEnum[] myEnums1) { 60 | this.myEnums1 = myEnums1; 61 | } 62 | 63 | public MyEnum[] getMyEnums2() { 64 | return myEnums2; 65 | } 66 | 67 | public void setMyEnums2(MyEnum[] myEnums2) { 68 | this.myEnums2 = myEnums2; 69 | } 70 | 71 | public String[] getEnumStrings() { 72 | return enumStrings; 73 | } 74 | 75 | public void setEnumStrings(String[] enumStrings) { 76 | this.enumStrings = enumStrings; 77 | } 78 | 79 | public List getMyEnums3() { 80 | return myEnums3; 81 | } 82 | 83 | public void setMyEnums3(List myEnums3) { 84 | this.myEnums3 = myEnums3; 85 | } 86 | 87 | public List geteStrings() { 88 | return eStrings; 89 | } 90 | 91 | public void seteStrings(List eStrings) { 92 | this.eStrings = eStrings; 93 | } 94 | 95 | 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testEnum2/Inside.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testEnum2; 2 | 3 | public class Inside { 4 | 5 | private String a; 6 | private MyEnum b; 7 | 8 | public String getA() { 9 | return a; 10 | } 11 | public void setA(String a) { 12 | this.a = a; 13 | } 14 | public MyEnum getB() { 15 | return b; 16 | } 17 | public void setB(MyEnum b) { 18 | this.b = b; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testEnum2/MyEnum.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testEnum2; 2 | 3 | public enum MyEnum { 4 | One, 5 | Two, 6 | Three 7 | } 8 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testEnum2/Test08.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testEnum2; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.lang.reflect.Array; 6 | import java.util.Arrays; 7 | 8 | import org.junit.Test; 9 | 10 | import com.tuyang.beanutils.BeanCopyUtils; 11 | 12 | public class Test08 { 13 | 14 | private FromBean getFromBean() { 15 | FromBean fromBean = new FromBean(); 16 | 17 | fromBean.setMyEnum1(MyEnum.One); 18 | fromBean.setMyEnum2(MyEnum.Two); 19 | fromBean.setEnumString(MyEnum.Three.toString()); 20 | 21 | MyEnum[] array = new MyEnum[2]; 22 | array[0]= MyEnum.One; 23 | array[1] = MyEnum.Three; 24 | fromBean.setMyEnums1(array); 25 | fromBean.setMyEnums2(array); 26 | fromBean.setMyEnums3(Arrays.asList(array)); 27 | 28 | String[] enumStrings = new String[2]; 29 | enumStrings[0] = MyEnum.Three.toString(); 30 | enumStrings[1] = MyEnum.Two.toString(); 31 | 32 | fromBean.setEnumStrings(enumStrings); 33 | fromBean.seteStrings(Arrays.asList(enumStrings)); 34 | fromBean.setInside(new Inside()); 35 | fromBean.getInside().setB(MyEnum.One); 36 | 37 | return fromBean; 38 | } 39 | 40 | @Test 41 | public void testEnum() { 42 | FromBean fromBean = getFromBean(); 43 | ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class); 44 | 45 | assertEquals(toBean.getMyEnum(), MyEnum.One); 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testEnum2/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testEnum2; 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 | @CopyProperty(property = "inside.b") 10 | private MyEnum myEnum; 11 | 12 | public MyEnum getMyEnum() { 13 | return myEnum; 14 | } 15 | 16 | public void setMyEnum(MyEnum myEnum) { 17 | this.myEnum = myEnum; 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testFeatureIgnorePimitive/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testFeatureIgnorePimitive; 2 | 3 | public class FromBean { 4 | 5 | private boolean beanBool; 6 | private byte beanByte; 7 | private char beanChar; 8 | private short beanShort; 9 | private int beanInt; 10 | private Long beanLong; 11 | private Float beanFloat; 12 | private Double beanDouble; 13 | private String beanString; 14 | 15 | public boolean isBeanBool() { 16 | return beanBool; 17 | } 18 | public void setBeanBool(boolean beanBool) { 19 | this.beanBool = beanBool; 20 | } 21 | public byte getBeanByte() { 22 | return beanByte; 23 | } 24 | public void setBeanByte(byte beanByte) { 25 | this.beanByte = beanByte; 26 | } 27 | public char getBeanChar() { 28 | return beanChar; 29 | } 30 | public void setBeanChar(char beanChar) { 31 | this.beanChar = beanChar; 32 | } 33 | public short getBeanShort() { 34 | return beanShort; 35 | } 36 | public void setBeanShort(short beanShort) { 37 | this.beanShort = beanShort; 38 | } 39 | public int getBeanInt() { 40 | return beanInt; 41 | } 42 | public void setBeanInt(int beanInt) { 43 | this.beanInt = beanInt; 44 | } 45 | public Long getBeanLong() { 46 | return beanLong; 47 | } 48 | public void setBeanLong(Long beanLong) { 49 | this.beanLong = beanLong; 50 | } 51 | public Float getBeanFloat() { 52 | return beanFloat; 53 | } 54 | public void setBeanFloat(Float beanFloat) { 55 | this.beanFloat = beanFloat; 56 | } 57 | public Double getBeanDouble() { 58 | return beanDouble; 59 | } 60 | public void setBeanDouble(Double beanDouble) { 61 | this.beanDouble = beanDouble; 62 | } 63 | public String getBeanString() { 64 | return beanString; 65 | } 66 | public void setBeanString(String beanString) { 67 | this.beanString = beanString; 68 | } 69 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testFeatureIgnorePimitive/TestFeatureIgnorePimitive.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testFeatureIgnorePimitive; 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 TestFeatureIgnorePimitive { 10 | 11 | private FromBean getFromBean() { 12 | 13 | FromBean fromBean = new FromBean(); 14 | 15 | fromBean.setBeanBool(true); 16 | fromBean.setBeanByte((byte)5); 17 | fromBean.setBeanChar((char)40); 18 | fromBean.setBeanShort((short)50); 19 | fromBean.setBeanInt(100); 20 | fromBean.setBeanFloat(null); 21 | fromBean.setBeanLong(null); 22 | fromBean.setBeanDouble(null); 23 | fromBean.setBeanString("Test test Test test."); 24 | return fromBean; 25 | } 26 | 27 | 28 | @Test 29 | public void testPrimitiveTypeWithFeature() { 30 | FromBean fromBean = getFromBean(); 31 | BeanCopyUtils.dumpPropertyMapping(fromBean, ToBean.class, ToBeanOption.class); 32 | ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class, ToBeanOption.class); 33 | assertEquals(fromBean.isBeanBool(), toBean.getBeanBool().booleanValue()); 34 | assertEquals( fromBean.getBeanByte(), toBean.getBeanByte().byteValue() ); 35 | assertEquals( fromBean.getBeanChar(), toBean.getBeanChar().charValue() ); 36 | assertEquals( fromBean.getBeanShort(), toBean.getBeanShort().shortValue() ); 37 | assertEquals( fromBean.getBeanInt(), toBean.getBeanInt().intValue() ); 38 | assertEquals( 0, toBean.getBeanLong()); 39 | assertEquals( 0.0f, toBean.getBeanFloat(), 0); 40 | assertEquals( 0.0f, toBean.getBeanDouble(), 0 ); 41 | assertEquals( fromBean.getBeanString(), toBean.getBeanString() ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testFeatureIgnorePimitive/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testFeatureIgnorePimitive; 2 | 3 | public class ToBean { 4 | 5 | private Boolean beanBool; 6 | private Byte beanByte; 7 | private Character beanChar; 8 | private Short beanShort; 9 | private Integer beanInt; 10 | private long beanLong; 11 | private float beanFloat; 12 | private double beanDouble; 13 | private String beanString; 14 | 15 | public Boolean getBeanBool() { 16 | return beanBool; 17 | } 18 | public void setBeanBool(Boolean beanBool) { 19 | this.beanBool = beanBool; 20 | } 21 | public Byte getBeanByte() { 22 | return beanByte; 23 | } 24 | public void setBeanByte(Byte beanByte) { 25 | this.beanByte = beanByte; 26 | } 27 | public Character getBeanChar() { 28 | return beanChar; 29 | } 30 | public void setBeanChar(Character beanChar) { 31 | this.beanChar = beanChar; 32 | } 33 | public Short getBeanShort() { 34 | return beanShort; 35 | } 36 | public void setBeanShort(Short beanShort) { 37 | this.beanShort = beanShort; 38 | } 39 | public Integer getBeanInt() { 40 | return beanInt; 41 | } 42 | public void setBeanInt(Integer beanInt) { 43 | this.beanInt = beanInt; 44 | } 45 | public long getBeanLong() { 46 | return beanLong; 47 | } 48 | public void setBeanLong(long beanLong) { 49 | this.beanLong = beanLong; 50 | } 51 | public float getBeanFloat() { 52 | return beanFloat; 53 | } 54 | public void setBeanFloat(float beanFloat) { 55 | this.beanFloat = beanFloat; 56 | } 57 | public double getBeanDouble() { 58 | return beanDouble; 59 | } 60 | public void setBeanDouble(double beanDouble) { 61 | this.beanDouble = beanDouble; 62 | } 63 | public String getBeanString() { 64 | return beanString; 65 | } 66 | public void setBeanString(String beanString) { 67 | this.beanString = beanString; 68 | } 69 | 70 | 71 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testFeatureIgnorePimitive/ToBeanOption.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testFeatureIgnorePimitive; 2 | 3 | import com.tuyang.beanutils.annotation.BeanCopySource; 4 | import com.tuyang.beanutils.annotation.CopyFeature; 5 | 6 | @BeanCopySource(source=FromBean.class, features= {CopyFeature.IGNORE_PRIMITIVE_NULL_SOURCE_VALUE}) 7 | public class ToBeanOption { 8 | 9 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testIgnoreAll/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testIgnoreAll; 2 | 3 | public class FromBean { 4 | 5 | private int beanInt; 6 | private long beanLong; 7 | 8 | private String beanString; 9 | 10 | private FromBean2 bean2; 11 | 12 | public int getBeanInt() { 13 | return beanInt; 14 | } 15 | 16 | public void setBeanInt(int beanInt) { 17 | this.beanInt = beanInt; 18 | } 19 | 20 | public long getBeanLong() { 21 | return beanLong; 22 | } 23 | 24 | public void setBeanLong(long beanLong) { 25 | this.beanLong = beanLong; 26 | } 27 | 28 | public String getBeanString() { 29 | return beanString; 30 | } 31 | 32 | public void setBeanString(String beanString) { 33 | this.beanString = beanString; 34 | } 35 | 36 | public FromBean2 getBean2() { 37 | return bean2; 38 | } 39 | 40 | public void setBean2(FromBean2 bean2) { 41 | this.bean2 = bean2; 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testIgnoreAll/FromBean2.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testIgnoreAll; 2 | 3 | public class FromBean2 { 4 | 5 | private Float beanFloat; 6 | private String beanString; 7 | 8 | public Float getBeanFloat() { 9 | return beanFloat; 10 | } 11 | public void setBeanFloat(Float beanFloat) { 12 | this.beanFloat = beanFloat; 13 | } 14 | public String getBeanString() { 15 | return beanString; 16 | } 17 | public void setBeanString(String beanString) { 18 | this.beanString = beanString; 19 | } 20 | 21 | 22 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testIgnoreAll/TestIgnoreAll.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testIgnoreAll; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.junit.Test; 9 | 10 | import com.tuyang.beanutils.BeanCopyUtils; 11 | 12 | public class TestIgnoreAll { 13 | 14 | private FromBean getFromBean() { 15 | FromBean fromBean = new FromBean(); 16 | fromBean.setBeanInt(100); 17 | fromBean.setBeanLong(200); 18 | fromBean.setBeanString(null); 19 | 20 | FromBean2 bean2 = new FromBean2(); 21 | bean2.setBeanFloat(10.4f); 22 | bean2.setBeanString(null); 23 | 24 | fromBean.setBean2(bean2); 25 | 26 | return fromBean; 27 | } 28 | 29 | @Test 30 | public void testIgnoreAll() { 31 | FromBean fromBean = getFromBean(); 32 | ToBean toBean = new ToBean(); 33 | toBean.setBeanString("Not Empty"); 34 | toBean.setBean2String("Not Empty"); 35 | BeanCopyUtils.copyBean(fromBean, toBean); 36 | assertEquals( toBean.getBeanString(), "Not Empty" ); 37 | assertEquals( toBean.getBean2String(), "Not Empty" ); 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testIgnoreAll/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testIgnoreAll; 2 | 3 | import com.tuyang.beanutils.annotation.BeanCopySource; 4 | import com.tuyang.beanutils.annotation.CopyProperty; 5 | import com.tuyang.beanutils.annotation.CopyFeature; 6 | 7 | @BeanCopySource(source=FromBean.class, features={CopyFeature.IGNORE_ALL_NULL_SOURCE_VALUE}) 8 | public class ToBean { 9 | 10 | private Integer beanInt; 11 | private long beanLong; 12 | private String beanString; 13 | 14 | @CopyProperty(property="bean2.beanString") 15 | private String bean2String; 16 | 17 | public Integer getBeanInt() { 18 | return beanInt; 19 | } 20 | 21 | public void setBeanInt(Integer beanInt) { 22 | this.beanInt = beanInt; 23 | } 24 | 25 | public long getBeanLong() { 26 | return beanLong; 27 | } 28 | 29 | public void setBeanLong(long beanLong) { 30 | this.beanLong = beanLong; 31 | } 32 | 33 | public String getBeanString() { 34 | return beanString; 35 | } 36 | 37 | public void setBeanString(String beanString) { 38 | this.beanString = beanString; 39 | } 40 | 41 | public String getBean2String() { 42 | return bean2String; 43 | } 44 | 45 | public void setBean2String(String bean2String) { 46 | this.bean2String = bean2String; 47 | } 48 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testInheritance/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testInheritance; 2 | 3 | public class FromBean extends FromBeanBase { 4 | 5 | private boolean beanBool; 6 | private int beanInt; 7 | private String beanString; 8 | 9 | public boolean isBeanBool() { 10 | return beanBool; 11 | } 12 | 13 | public void setBeanBool(boolean beanBool) { 14 | this.beanBool = beanBool; 15 | } 16 | 17 | 18 | public int getBeanInt() { 19 | return beanInt; 20 | } 21 | public void setBeanInt(int beanInt) { 22 | this.beanInt = beanInt; 23 | } 24 | 25 | public String getBeanString() { 26 | return beanString; 27 | } 28 | public void setBeanString(String beanString) { 29 | this.beanString = beanString; 30 | } 31 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testInheritance/FromBeanBase.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testInheritance; 2 | 3 | public class FromBeanBase { 4 | 5 | private boolean baseBool; 6 | private byte baseByte; 7 | private char baseChar; 8 | private short baseShort; 9 | private int baseInt; 10 | private long baseLong; 11 | private float baseFloat; 12 | private double baseDouble; 13 | private String baseString; 14 | public boolean isBaseBool() { 15 | return baseBool; 16 | } 17 | public void setBaseBool(boolean baseBool) { 18 | this.baseBool = baseBool; 19 | } 20 | public byte getBaseByte() { 21 | return baseByte; 22 | } 23 | public void setBaseByte(byte baseByte) { 24 | this.baseByte = baseByte; 25 | } 26 | public char getBaseChar() { 27 | return baseChar; 28 | } 29 | public void setBaseChar(char baseChar) { 30 | this.baseChar = baseChar; 31 | } 32 | public short getBaseShort() { 33 | return baseShort; 34 | } 35 | public void setBaseShort(short baseShort) { 36 | this.baseShort = baseShort; 37 | } 38 | public int getBaseInt() { 39 | return baseInt; 40 | } 41 | public void setBaseInt(int baseInt) { 42 | this.baseInt = baseInt; 43 | } 44 | public long getBaseLong() { 45 | return baseLong; 46 | } 47 | public void setBaseLong(long baseLong) { 48 | this.baseLong = baseLong; 49 | } 50 | public float getBaseFloat() { 51 | return baseFloat; 52 | } 53 | public void setBaseFloat(float baseFloat) { 54 | this.baseFloat = baseFloat; 55 | } 56 | public double getBaseDouble() { 57 | return baseDouble; 58 | } 59 | public void setBaseDouble(double baseDouble) { 60 | this.baseDouble = baseDouble; 61 | } 62 | public String getBaseString() { 63 | return baseString; 64 | } 65 | public void setBaseString(String baseString) { 66 | this.baseString = baseString; 67 | } 68 | 69 | 70 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testInheritance/Test09.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testInheritance; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | import com.tuyang.beanutils.BeanCopyUtils; 8 | 9 | public class Test09 { 10 | 11 | private FromBean getFromBean() { 12 | FromBean fromBean = new FromBean(); 13 | fromBean.setBeanBool(true); 14 | fromBean.setBeanInt(100); 15 | fromBean.setBeanString("Test test Test test."); 16 | 17 | fromBean.setBaseBool(true); 18 | fromBean.setBaseByte((byte)5); 19 | fromBean.setBaseChar((char)40); 20 | fromBean.setBaseShort((short)50); 21 | fromBean.setBaseInt(100); 22 | fromBean.setBaseFloat(100.50f); 23 | fromBean.setBaseLong(234323243243243234L); 24 | fromBean.setBaseDouble(2342332423.23432432523523); 25 | fromBean.setBaseString("Test test Test test."); 26 | 27 | return fromBean; 28 | } 29 | 30 | @Test 31 | public void testInheritance() { 32 | FromBean fromBean = getFromBean(); 33 | ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class); 34 | assertEquals(fromBean.isBeanBool(), toBean.isBeanBool() ); 35 | assertEquals( fromBean.getBeanInt(), toBean.getToBeanInt() ); 36 | assertEquals( fromBean.getBeanString(), toBean.getToBeanString() ); 37 | assertEquals(fromBean.getBaseByte(), toBean.getBaseByte() ); 38 | assertEquals(fromBean.getBaseChar(), toBean.getBaseChar() ); 39 | assertEquals(fromBean.getBaseDouble(), toBean.getBaseDouble(), 0 ); 40 | assertEquals(fromBean.getBaseFloat(), toBean.getBaseFloat(), 0 ); 41 | assertEquals(fromBean.getBaseInt(), toBean.getBaseInt() ); 42 | assertEquals(fromBean.getBaseLong(), toBean.getBaseLong() ); 43 | assertEquals(fromBean.getBaseShort(), toBean.getBaseShort() ); 44 | assertEquals(fromBean.getBaseString(), toBean.getBaseString() ); 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testInheritance/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testInheritance; 2 | 3 | import com.tuyang.beanutils.annotation.CopyProperty; 4 | import com.tuyang.beanutils.annotation.BeanCopySource; 5 | 6 | @BeanCopySource(source=FromBean.class) 7 | public class ToBean extends ToBeanBase { 8 | 9 | private boolean beanBool; 10 | @CopyProperty(property="beanInt") 11 | private int toBeanInt; 12 | @CopyProperty(property="beanString") 13 | private String toBeanString; 14 | 15 | public boolean isBeanBool() { 16 | return beanBool; 17 | } 18 | public void setBeanBool(boolean beanBool) { 19 | this.beanBool = beanBool; 20 | } 21 | public int getToBeanInt() { 22 | return toBeanInt; 23 | } 24 | public void setToBeanInt(int toBeanInt) { 25 | this.toBeanInt = toBeanInt; 26 | } 27 | public String getToBeanString() { 28 | return toBeanString; 29 | } 30 | public void setToBeanString(String toBeanString) { 31 | this.toBeanString = toBeanString; 32 | } 33 | 34 | 35 | 36 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testInheritance/ToBeanBase.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testInheritance; 2 | 3 | public class ToBeanBase { 4 | 5 | private boolean baseBool; 6 | private byte baseByte; 7 | private char baseChar; 8 | private short baseShort; 9 | private int baseInt; 10 | private long baseLong; 11 | private float baseFloat; 12 | private double baseDouble; 13 | private String baseString; 14 | 15 | public boolean isBaseBool() { 16 | return baseBool; 17 | } 18 | public void setBaseBool(boolean baseBool) { 19 | this.baseBool = baseBool; 20 | } 21 | public byte getBaseByte() { 22 | return baseByte; 23 | } 24 | public void setBaseByte(byte baseByte) { 25 | this.baseByte = baseByte; 26 | } 27 | public char getBaseChar() { 28 | return baseChar; 29 | } 30 | public void setBaseChar(char baseChar) { 31 | this.baseChar = baseChar; 32 | } 33 | public short getBaseShort() { 34 | return baseShort; 35 | } 36 | public void setBaseShort(short baseShort) { 37 | this.baseShort = baseShort; 38 | } 39 | public int getBaseInt() { 40 | return baseInt; 41 | } 42 | public void setBaseInt(int baseInt) { 43 | this.baseInt = baseInt; 44 | } 45 | public long getBaseLong() { 46 | return baseLong; 47 | } 48 | public void setBaseLong(long baseLong) { 49 | this.baseLong = baseLong; 50 | } 51 | public float getBaseFloat() { 52 | return baseFloat; 53 | } 54 | public void setBaseFloat(float baseFloat) { 55 | this.baseFloat = baseFloat; 56 | } 57 | public double getBaseDouble() { 58 | return baseDouble; 59 | } 60 | public void setBaseDouble(double baseDouble) { 61 | this.baseDouble = baseDouble; 62 | } 63 | public String getBaseString() { 64 | return baseString; 65 | } 66 | public void setBaseString(String baseString) { 67 | this.baseString = baseString; 68 | } 69 | 70 | 71 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testInheritance2/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testInheritance2; 2 | 3 | public class FromBean extends FromBeanBase { 4 | 5 | private boolean beanBool; 6 | private int beanInt; 7 | private String beanString; 8 | 9 | public boolean isBeanBool() { 10 | return beanBool; 11 | } 12 | 13 | public void setBeanBool(boolean beanBool) { 14 | this.beanBool = beanBool; 15 | } 16 | 17 | public int getBeanInt() { 18 | return beanInt; 19 | } 20 | public void setBeanInt(int beanInt) { 21 | this.beanInt = beanInt; 22 | } 23 | 24 | public String getBeanString() { 25 | return beanString; 26 | } 27 | public void setBeanString(String beanString) { 28 | this.beanString = beanString; 29 | } 30 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testInheritance2/FromBeanBase.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testInheritance2; 2 | 3 | public class FromBeanBase { 4 | 5 | private boolean baseBool; 6 | private byte baseByte; 7 | private char baseChar; 8 | private short baseShort; 9 | private int baseInt; 10 | private long baseLong; 11 | private float baseFloat; 12 | private double baseDouble; 13 | private String baseString; 14 | public boolean isBaseBool() { 15 | return baseBool; 16 | } 17 | public void setBaseBool(boolean baseBool) { 18 | this.baseBool = baseBool; 19 | } 20 | public byte getBaseByte() { 21 | return baseByte; 22 | } 23 | public void setBaseByte(byte baseByte) { 24 | this.baseByte = baseByte; 25 | } 26 | public char getBaseChar() { 27 | return baseChar; 28 | } 29 | public void setBaseChar(char baseChar) { 30 | this.baseChar = baseChar; 31 | } 32 | public short getBaseShort() { 33 | return baseShort; 34 | } 35 | public void setBaseShort(short baseShort) { 36 | this.baseShort = baseShort; 37 | } 38 | public int getBaseInt() { 39 | return baseInt; 40 | } 41 | public void setBaseInt(int baseInt) { 42 | this.baseInt = baseInt; 43 | } 44 | public long getBaseLong() { 45 | return baseLong; 46 | } 47 | public void setBaseLong(long baseLong) { 48 | this.baseLong = baseLong; 49 | } 50 | public float getBaseFloat() { 51 | return baseFloat; 52 | } 53 | public void setBaseFloat(float baseFloat) { 54 | this.baseFloat = baseFloat; 55 | } 56 | public double getBaseDouble() { 57 | return baseDouble; 58 | } 59 | public void setBaseDouble(double baseDouble) { 60 | this.baseDouble = baseDouble; 61 | } 62 | public String getBaseString() { 63 | return baseString; 64 | } 65 | public void setBaseString(String baseString) { 66 | this.baseString = baseString; 67 | } 68 | 69 | 70 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testInheritance2/Test10.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testInheritance2; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | import com.tuyang.beanutils.BeanCopyUtils; 8 | 9 | public class Test10 { 10 | 11 | private FromBean getFromBean() { 12 | FromBean fromBean = new FromBean(); 13 | fromBean.setBeanBool(true); 14 | fromBean.setBeanInt(100); 15 | fromBean.setBeanString("Test test Test test."); 16 | 17 | fromBean.setBaseBool(true); 18 | fromBean.setBaseByte((byte)5); 19 | fromBean.setBaseChar((char)40); 20 | fromBean.setBaseShort((short)50); 21 | fromBean.setBaseInt(100); 22 | fromBean.setBaseFloat(100.50f); 23 | fromBean.setBaseLong(234323243243243234L); 24 | fromBean.setBaseDouble(2342332423.23432432523523); 25 | fromBean.setBaseString("Test test Test test."); 26 | 27 | return fromBean; 28 | } 29 | 30 | @Test 31 | public void testInheritance() { 32 | FromBean fromBean = getFromBean(); 33 | ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class, ToBeanOption.class); 34 | assertEquals(fromBean.isBeanBool(), toBean.isBeanBool() ); 35 | assertEquals( fromBean.getBeanInt(), toBean.getToBeanInt() ); 36 | assertEquals( fromBean.getBeanString(), toBean.getToBeanString() ); 37 | assertEquals(fromBean.getBaseByte(), toBean.getToBaseByte() ); 38 | assertEquals(fromBean.getBaseChar(), toBean.getToBaseChar() ); 39 | assertEquals(fromBean.getBaseDouble(), toBean.getToBaseDouble(), 0 ); 40 | assertEquals(fromBean.getBaseFloat(), toBean.getToBaseFloat(), 0 ); 41 | assertEquals(fromBean.getBaseInt(), toBean.getToBaseInt() ); 42 | assertEquals(fromBean.getBaseLong(), toBean.getToBaseLong() ); 43 | assertEquals(fromBean.getBaseShort(), toBean.getToBaseShort() ); 44 | assertEquals(fromBean.getBaseString(), toBean.getToBaseString() ); 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testInheritance2/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testInheritance2; 2 | 3 | public class ToBean extends ToBeanBase { 4 | 5 | private boolean beanBool; 6 | private int toBeanInt; 7 | private String toBeanString; 8 | 9 | public boolean isBeanBool() { 10 | return beanBool; 11 | } 12 | public void setBeanBool(boolean beanBool) { 13 | this.beanBool = beanBool; 14 | } 15 | public int getToBeanInt() { 16 | return toBeanInt; 17 | } 18 | public void setToBeanInt(int toBeanInt) { 19 | this.toBeanInt = toBeanInt; 20 | } 21 | public String getToBeanString() { 22 | return toBeanString; 23 | } 24 | public void setToBeanString(String toBeanString) { 25 | this.toBeanString = toBeanString; 26 | } 27 | 28 | 29 | 30 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testInheritance2/ToBeanBase.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testInheritance2; 2 | 3 | public class ToBeanBase { 4 | 5 | private boolean toBaseBool; 6 | private byte toBaseByte; 7 | private char toBaseChar; 8 | private short toBaseShort; 9 | private int toBaseInt; 10 | private long toBaseLong; 11 | private float toBaseFloat; 12 | private double toBaseDouble; 13 | private String toBaseString; 14 | 15 | public boolean isToBaseBool() { 16 | return toBaseBool; 17 | } 18 | public void setToBaseBool(boolean toBaseBool) { 19 | this.toBaseBool = toBaseBool; 20 | } 21 | public byte getToBaseByte() { 22 | return toBaseByte; 23 | } 24 | public void setToBaseByte(byte toBaseByte) { 25 | this.toBaseByte = toBaseByte; 26 | } 27 | public char getToBaseChar() { 28 | return toBaseChar; 29 | } 30 | public void setToBaseChar(char toBaseChar) { 31 | this.toBaseChar = toBaseChar; 32 | } 33 | public short getToBaseShort() { 34 | return toBaseShort; 35 | } 36 | public void setToBaseShort(short toBaseShort) { 37 | this.toBaseShort = toBaseShort; 38 | } 39 | public int getToBaseInt() { 40 | return toBaseInt; 41 | } 42 | public void setToBaseInt(int toBaseInt) { 43 | this.toBaseInt = toBaseInt; 44 | } 45 | public long getToBaseLong() { 46 | return toBaseLong; 47 | } 48 | public void setToBaseLong(long toBaseLong) { 49 | this.toBaseLong = toBaseLong; 50 | } 51 | public float getToBaseFloat() { 52 | return toBaseFloat; 53 | } 54 | public void setToBaseFloat(float toBaseFloat) { 55 | this.toBaseFloat = toBaseFloat; 56 | } 57 | public double getToBaseDouble() { 58 | return toBaseDouble; 59 | } 60 | public void setToBaseDouble(double toBaseDouble) { 61 | this.toBaseDouble = toBaseDouble; 62 | } 63 | public String getToBaseString() { 64 | return toBaseString; 65 | } 66 | public void setToBaseString(String toBaseString) { 67 | this.toBaseString = toBaseString; 68 | } 69 | 70 | 71 | 72 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testInheritance2/ToBeanOption.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testInheritance2; 2 | 3 | import com.tuyang.beanutils.annotation.CopyProperty; 4 | import com.tuyang.beanutils.annotation.BeanCopySource; 5 | 6 | @BeanCopySource(source=FromBean.class) 7 | public class ToBeanOption { 8 | 9 | @CopyProperty(property="beanInt") 10 | private int toBeanInt; 11 | @CopyProperty(property="beanString") 12 | private String toBeanString; 13 | @CopyProperty(property="baseBool") 14 | private boolean toBaseBool; 15 | @CopyProperty(property="baseByte") 16 | private byte toBaseByte; 17 | @CopyProperty(property="baseChar") 18 | private char toBaseChar; 19 | @CopyProperty(property="baseShort") 20 | private short toBaseShort; 21 | @CopyProperty(property="baseInt") 22 | private int toBaseInt; 23 | @CopyProperty(property="baseLong") 24 | private long toBaseLong; 25 | @CopyProperty(property="baseFloat") 26 | private float toBaseFloat; 27 | @CopyProperty(property="baseDouble") 28 | private double toBaseDouble; 29 | @CopyProperty(property="baseString") 30 | private String toBaseString; 31 | 32 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testMisc/DateConvertor.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testMisc; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | 6 | import com.tuyang.beanutils.BeanCopyConvertor; 7 | 8 | public class DateConvertor implements BeanCopyConvertor { 9 | 10 | @Override 11 | public String convertTo(Date object) { 12 | if( object == null ) 13 | object = new Date(); 14 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 15 | return format.format(object); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testMisc/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testMisc; 2 | 3 | import java.util.Date; 4 | import java.util.List; 5 | 6 | public class FromBean { 7 | 8 | private boolean beanBool; 9 | private byte beanByte; 10 | private char beanChar; 11 | private short beanShort; 12 | private int beanInt; 13 | private Long beanLong; 14 | private Float beanFloat; 15 | private Double beanDouble; 16 | private String beanString; 17 | 18 | private Date beanDate; 19 | 20 | private int[] beanIntArray; 21 | private FromBean2 bean2; 22 | private List bean3List; 23 | private FromBean4[] bean4Array; 24 | 25 | public boolean isBeanBool() { 26 | return beanBool; 27 | } 28 | public void setBeanBool(boolean beanBool) { 29 | this.beanBool = beanBool; 30 | } 31 | public byte getBeanByte() { 32 | return beanByte; 33 | } 34 | public void setBeanByte(byte beanByte) { 35 | this.beanByte = beanByte; 36 | } 37 | public char getBeanChar() { 38 | return beanChar; 39 | } 40 | public void setBeanChar(char beanChar) { 41 | this.beanChar = beanChar; 42 | } 43 | public short getBeanShort() { 44 | return beanShort; 45 | } 46 | public void setBeanShort(short beanShort) { 47 | this.beanShort = beanShort; 48 | } 49 | public int getBeanInt() { 50 | return beanInt; 51 | } 52 | public void setBeanInt(int beanInt) { 53 | this.beanInt = beanInt; 54 | } 55 | public Long getBeanLong() { 56 | return beanLong; 57 | } 58 | public void setBeanLong(Long beanLong) { 59 | this.beanLong = beanLong; 60 | } 61 | public Float getBeanFloat() { 62 | return beanFloat; 63 | } 64 | public void setBeanFloat(Float beanFloat) { 65 | this.beanFloat = beanFloat; 66 | } 67 | public Double getBeanDouble() { 68 | return beanDouble; 69 | } 70 | public void setBeanDouble(Double beanDouble) { 71 | this.beanDouble = beanDouble; 72 | } 73 | public String getBeanString() { 74 | return beanString; 75 | } 76 | public void setBeanString(String beanString) { 77 | this.beanString = beanString; 78 | } 79 | public Date getBeanDate() { 80 | return beanDate; 81 | } 82 | public void setBeanDate(Date beanDate) { 83 | this.beanDate = beanDate; 84 | } 85 | public int[] getBeanIntArray() { 86 | return beanIntArray; 87 | } 88 | public void setBeanIntArray(int[] beanIntArray) { 89 | this.beanIntArray = beanIntArray; 90 | } 91 | public FromBean2 getBean2() { 92 | return bean2; 93 | } 94 | public void setBean2(FromBean2 bean2) { 95 | this.bean2 = bean2; 96 | } 97 | public List getBean3List() { 98 | return bean3List; 99 | } 100 | public void setBean3List(List bean3List) { 101 | this.bean3List = bean3List; 102 | } 103 | public FromBean4[] getBean4Array() { 104 | return bean4Array; 105 | } 106 | public void setBean4Array(FromBean4[] bean4Array) { 107 | this.bean4Array = bean4Array; 108 | } 109 | 110 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testMisc/FromBean2.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testMisc; 2 | 3 | public class FromBean2 { 4 | 5 | private Float beanFloat; 6 | private String beanString; 7 | 8 | public Float getBeanFloat() { 9 | return beanFloat; 10 | } 11 | public void setBeanFloat(Float beanFloat) { 12 | this.beanFloat = beanFloat; 13 | } 14 | public String getBeanString() { 15 | return beanString; 16 | } 17 | public void setBeanString(String beanString) { 18 | this.beanString = beanString; 19 | } 20 | 21 | 22 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testMisc/FromBean3.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testMisc; 2 | 3 | public class FromBean3 { 4 | 5 | private Float beanFloat; 6 | private String beanString; 7 | 8 | public Float getBeanFloat() { 9 | return beanFloat; 10 | } 11 | public void setBeanFloat(Float beanFloat) { 12 | this.beanFloat = beanFloat; 13 | } 14 | public String getBeanString() { 15 | return beanString; 16 | } 17 | public void setBeanString(String beanString) { 18 | this.beanString = beanString; 19 | } 20 | 21 | 22 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testMisc/FromBean4.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testMisc; 2 | 3 | public class FromBean4 { 4 | 5 | private Float beanFloat; 6 | private String beanString; 7 | 8 | public Float getBeanFloat() { 9 | return beanFloat; 10 | } 11 | public void setBeanFloat(Float beanFloat) { 12 | this.beanFloat = beanFloat; 13 | } 14 | public String getBeanString() { 15 | return beanString; 16 | } 17 | public void setBeanString(String beanString) { 18 | this.beanString = beanString; 19 | } 20 | 21 | 22 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testMisc/Test12.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testMisc; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Date; 7 | import java.util.List; 8 | 9 | import org.junit.Test; 10 | 11 | import com.tuyang.beanutils.BeanCopyUtils; 12 | 13 | public class Test12 { 14 | 15 | private FromBean getFromBean() { 16 | FromBean fromBean = new FromBean(); 17 | fromBean.setBeanBool(true); 18 | fromBean.setBeanByte((byte)5); 19 | fromBean.setBeanChar((char)40); 20 | fromBean.setBeanShort((short)50); 21 | fromBean.setBeanInt(100); 22 | fromBean.setBeanFloat(100.50f); 23 | fromBean.setBeanLong(234323243243243234L); 24 | fromBean.setBeanDouble(2342332423.23432432523523); 25 | fromBean.setBeanString("Test test Test test."); 26 | 27 | FromBean2 bean2 = new FromBean2(); 28 | bean2.setBeanFloat(20.5f); 29 | bean2.setBeanString("bean2"); 30 | fromBean.setBean2(bean2); 31 | 32 | fromBean.setBeanDate(new Date()); 33 | fromBean.setBeanIntArray(new int[] {1,2,3}); 34 | 35 | FromBean3 bean3 = new FromBean3(); 36 | bean3.setBeanFloat(152.654f); 37 | bean3.setBeanString("bean3"); 38 | 39 | List bean3List = new ArrayList<>(); 40 | bean3List.add(bean3); 41 | bean3List.add(bean3); 42 | bean3List.add(bean3); 43 | 44 | fromBean.setBean3List(bean3List); 45 | 46 | FromBean4[] bean4Array = new FromBean4[3]; 47 | FromBean4 bean4 = new FromBean4(); 48 | bean4.setBeanFloat(789.2f); 49 | bean4.setBeanString("bean4"); 50 | 51 | bean4Array[0] = bean4; 52 | bean4Array[1] = bean4; 53 | bean4Array[2] = bean4; 54 | 55 | fromBean.setBean4Array(bean4Array); 56 | 57 | 58 | return fromBean; 59 | } 60 | 61 | @Test 62 | public void testBasic() { 63 | FromBean fromBean = getFromBean(); 64 | ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class); 65 | assertEquals(fromBean.isBeanBool(), toBean.getBeanBool().booleanValue() ); 66 | assertEquals( fromBean.getBeanByte(), toBean.getBeanByte().byteValue() ); 67 | assertEquals( fromBean.getBeanChar(), toBean.getBeanChar().charValue() ); 68 | assertEquals( fromBean.getBeanShort(), toBean.getBeanShort().shortValue() ); 69 | assertEquals( fromBean.getBeanInt(), toBean.getBeanInt().intValue() ); 70 | assertEquals( fromBean.getBeanLong().longValue(), toBean.getBeanLong() ); 71 | assertEquals( fromBean.getBeanFloat().floatValue(), toBean.getBeanFloat() , 0); 72 | assertEquals( fromBean.getBeanDouble().doubleValue(), toBean.getBeanDouble(), 0 ); 73 | assertEquals( fromBean.getBeanString(), toBean.getBeanString() ); 74 | 75 | assertArrayEquals(fromBean.getBeanIntArray(), toBean.getBeanIntArray()); 76 | 77 | assertEquals(fromBean.getBean2().getBeanFloat().floatValue(), toBean.getBean2().getBeanFloat().floatValue(), 0); 78 | 79 | assertNotNull(toBean.getBeanDate()); 80 | assertEquals(fromBean.getBean3List().get(1).getBeanFloat().floatValue(), toBean.getBean3List().get(1).getBeanFloat().floatValue(), 0); 81 | 82 | assertEquals(fromBean.getBean4Array()[1].getBeanFloat().floatValue(), toBean.getBean4Array()[1].getBeanFloat().floatValue(), 0); 83 | } 84 | 85 | } 86 | 87 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testMisc/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testMisc; 2 | 3 | import java.util.List; 4 | 5 | import com.tuyang.beanutils.annotation.CopyProperty; 6 | import com.tuyang.beanutils.annotation.CopyCollection; 7 | import com.tuyang.beanutils.annotation.BeanCopySource; 8 | 9 | @BeanCopySource(source=FromBean.class) 10 | public class ToBean { 11 | 12 | private Boolean beanBool; 13 | private Byte beanByte; 14 | private Character beanChar; 15 | private Short beanShort; 16 | private Integer beanInt; 17 | private long beanLong; 18 | private float beanFloat; 19 | private double beanDouble; 20 | private String beanString; 21 | 22 | @CopyProperty(convertor=DateConvertor.class) 23 | private String beanDate; 24 | 25 | private int[] beanIntArray; 26 | 27 | @CopyProperty 28 | private ToBean2 bean2; 29 | 30 | @CopyCollection(targetClass=ToBean3.class) 31 | private List bean3List; 32 | 33 | @CopyProperty 34 | private ToBean4[] bean4Array; 35 | 36 | @CopyProperty(property="beanInt") 37 | private int beanId; 38 | 39 | @CopyProperty(property="bean2.beanString") 40 | private String bean2String; 41 | 42 | public int getBeanId() { 43 | return beanId; 44 | } 45 | public void setBeanId(int beanId) { 46 | this.beanId = beanId; 47 | } 48 | public String getBean2String() { 49 | return bean2String; 50 | } 51 | public void setBean2String(String bean2String) { 52 | this.bean2String = bean2String; 53 | } 54 | public Boolean getBeanBool() { 55 | return beanBool; 56 | } 57 | public void setBeanBool(Boolean beanBool) { 58 | this.beanBool = beanBool; 59 | } 60 | public Byte getBeanByte() { 61 | return beanByte; 62 | } 63 | public void setBeanByte(Byte beanByte) { 64 | this.beanByte = beanByte; 65 | } 66 | public Character getBeanChar() { 67 | return beanChar; 68 | } 69 | public void setBeanChar(Character beanChar) { 70 | this.beanChar = beanChar; 71 | } 72 | public Short getBeanShort() { 73 | return beanShort; 74 | } 75 | public void setBeanShort(Short beanShort) { 76 | this.beanShort = beanShort; 77 | } 78 | public Integer getBeanInt() { 79 | return beanInt; 80 | } 81 | public void setBeanInt(Integer beanInt) { 82 | this.beanInt = beanInt; 83 | } 84 | public long getBeanLong() { 85 | return beanLong; 86 | } 87 | public void setBeanLong(long beanLong) { 88 | this.beanLong = beanLong; 89 | } 90 | public float getBeanFloat() { 91 | return beanFloat; 92 | } 93 | public void setBeanFloat(float beanFloat) { 94 | this.beanFloat = beanFloat; 95 | } 96 | public double getBeanDouble() { 97 | return beanDouble; 98 | } 99 | public void setBeanDouble(double beanDouble) { 100 | this.beanDouble = beanDouble; 101 | } 102 | public String getBeanString() { 103 | return beanString; 104 | } 105 | public void setBeanString(String beanString) { 106 | this.beanString = beanString; 107 | } 108 | public String getBeanDate() { 109 | return beanDate; 110 | } 111 | public void setBeanDate(String beanDate) { 112 | this.beanDate = beanDate; 113 | } 114 | public int[] getBeanIntArray() { 115 | return beanIntArray; 116 | } 117 | public void setBeanIntArray(int[] beanIntArray) { 118 | this.beanIntArray = beanIntArray; 119 | } 120 | public ToBean2 getBean2() { 121 | return bean2; 122 | } 123 | public void setBean2(ToBean2 bean2) { 124 | this.bean2 = bean2; 125 | } 126 | public List getBean3List() { 127 | return bean3List; 128 | } 129 | public void setBean3List(List bean3List) { 130 | this.bean3List = bean3List; 131 | } 132 | public ToBean4[] getBean4Array() { 133 | return bean4Array; 134 | } 135 | public void setBean4Array(ToBean4[] bean4Array) { 136 | this.bean4Array = bean4Array; 137 | } 138 | 139 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testMisc/ToBean2.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testMisc; 2 | 3 | public class ToBean2 { 4 | 5 | private Float beanFloat; 6 | private String beanString; 7 | 8 | public Float getBeanFloat() { 9 | return beanFloat; 10 | } 11 | public void setBeanFloat(Float beanFloat) { 12 | this.beanFloat = beanFloat; 13 | } 14 | public String getBeanString() { 15 | return beanString; 16 | } 17 | public void setBeanString(String beanString) { 18 | this.beanString = beanString; 19 | } 20 | 21 | 22 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testMisc/ToBean3.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testMisc; 2 | 3 | public class ToBean3 { 4 | 5 | private Float beanFloat; 6 | private String beanString; 7 | 8 | public Float getBeanFloat() { 9 | return beanFloat; 10 | } 11 | public void setBeanFloat(Float beanFloat) { 12 | this.beanFloat = beanFloat; 13 | } 14 | public String getBeanString() { 15 | return beanString; 16 | } 17 | public void setBeanString(String beanString) { 18 | this.beanString = beanString; 19 | } 20 | 21 | 22 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testMisc/ToBean4.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testMisc; 2 | 3 | public class ToBean4 { 4 | 5 | private Float beanFloat; 6 | private String beanString; 7 | 8 | public Float getBeanFloat() { 9 | return beanFloat; 10 | } 11 | public void setBeanFloat(Float beanFloat) { 12 | this.beanFloat = beanFloat; 13 | } 14 | public String getBeanString() { 15 | return beanString; 16 | } 17 | public void setBeanString(String beanString) { 18 | this.beanString = beanString; 19 | } 20 | 21 | 22 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testMultiThread/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testMultiThread; 2 | 3 | public class FromBean { 4 | 5 | private String id; 6 | 7 | public String getId() { 8 | return id; 9 | } 10 | 11 | public void setId(String id) { 12 | this.id = id; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testMultiThread/StringToIntegerConverter.java: -------------------------------------------------------------------------------- 1 | 2 | package com.tuyang.test.testMultiThread; 3 | 4 | import com.tuyang.beanutils.BeanCopyConvertor; 5 | 6 | public class StringToIntegerConverter implements BeanCopyConvertor { 7 | 8 | @Override 9 | public Integer convertTo(String object) { 10 | return Integer.parseInt(object); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testMultiThread/TestMultiThread.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testMultiThread; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Iterator; 5 | import java.util.List; 6 | 7 | import org.junit.Test; 8 | 9 | import com.tuyang.beanutils.BeanCopyUtils; 10 | 11 | public class TestMultiThread { 12 | 13 | @Test 14 | public void testMultiThread() { 15 | List threads = new ArrayList<>(); 16 | for (int i=0;i<10;i++){ 17 | Thread thread = new Thread( new Runnable() { 18 | @Override 19 | public void run() { 20 | FromBean fromBean = new FromBean(); 21 | fromBean.setId("1"); 22 | ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class); 23 | System.out.println(toBean.getId()); 24 | } 25 | }); 26 | threads.add(thread); 27 | } 28 | Iterator iterator = threads.iterator(); 29 | while( iterator.hasNext() ) { 30 | iterator.next().start(); 31 | } 32 | iterator = threads.iterator(); 33 | while( iterator.hasNext() ) { 34 | try { 35 | iterator.next().join(); 36 | } catch (InterruptedException e) { 37 | e.printStackTrace(); 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testMultiThread/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testMultiThread; 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 | @CopyProperty(property="id", convertor=StringToIntegerConverter.class) 10 | private Integer id; 11 | 12 | public Integer getId() { 13 | return id; 14 | } 15 | 16 | public void setId(Integer id) { 17 | this.id = id; 18 | } 19 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testOption/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testOption; 2 | 3 | public class FromBean { 4 | 5 | private boolean beanBool; 6 | private int beanInt; 7 | private String beanString; 8 | 9 | 10 | public boolean isBeanBool() { 11 | return beanBool; 12 | } 13 | 14 | public void setBeanBool(boolean beanBool) { 15 | this.beanBool = beanBool; 16 | } 17 | 18 | 19 | public int getBeanInt() { 20 | return beanInt; 21 | } 22 | public void setBeanInt(int beanInt) { 23 | this.beanInt = beanInt; 24 | } 25 | 26 | public String getBeanString() { 27 | return beanString; 28 | } 29 | public void setBeanString(String beanString) { 30 | this.beanString = beanString; 31 | } 32 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testOption/Test07.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testOption; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | import com.tuyang.beanutils.BeanCopyUtils; 8 | 9 | public class Test07 { 10 | 11 | private FromBean getFromBean() { 12 | FromBean fromBean = new FromBean(); 13 | fromBean.setBeanBool(true); 14 | 15 | fromBean.setBeanInt(100); 16 | 17 | fromBean.setBeanString("Test test Test test."); 18 | return fromBean; 19 | } 20 | 21 | @Test 22 | public void testOption() { 23 | FromBean fromBean = getFromBean(); 24 | ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class, ToBeanOption.class); 25 | assertEquals(fromBean.isBeanBool(), toBean.isBeanBool() ); 26 | assertEquals( fromBean.getBeanInt(), toBean.getToBeanInt() ); 27 | assertEquals( fromBean.getBeanString(), toBean.getToBeanString() ); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testOption/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testOption; 2 | 3 | public class ToBean { 4 | 5 | private boolean beanBool; 6 | private int toBeanInt; 7 | private String toBeanString; 8 | 9 | public boolean isBeanBool() { 10 | return beanBool; 11 | } 12 | public void setBeanBool(boolean beanBool) { 13 | this.beanBool = beanBool; 14 | } 15 | public int getToBeanInt() { 16 | return toBeanInt; 17 | } 18 | public void setToBeanInt(int toBeanInt) { 19 | this.toBeanInt = toBeanInt; 20 | } 21 | public String getToBeanString() { 22 | return toBeanString; 23 | } 24 | public void setToBeanString(String toBeanString) { 25 | this.toBeanString = toBeanString; 26 | } 27 | 28 | 29 | 30 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testOption/ToBeanOption.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testOption; 2 | 3 | import com.tuyang.beanutils.annotation.CopyProperty; 4 | import com.tuyang.beanutils.annotation.BeanCopySource; 5 | 6 | @BeanCopySource(source=FromBean.class) 7 | public class ToBeanOption { 8 | 9 | @CopyProperty(property="beanInt") 10 | private int toBeanInt; 11 | @CopyProperty(property="beanString") 12 | private String toBeanString; 13 | 14 | 15 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testPrimitive/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testPrimitive; 2 | 3 | public class FromBean { 4 | 5 | private boolean beanBool; 6 | private byte beanByte; 7 | private char beanChar; 8 | private short beanShort; 9 | private int beanInt; 10 | private Long beanLong; 11 | private Float beanFloat; 12 | private Double beanDouble; 13 | private String beanString; 14 | 15 | public boolean isBeanBool() { 16 | return beanBool; 17 | } 18 | public void setBeanBool(boolean beanBool) { 19 | this.beanBool = beanBool; 20 | } 21 | public byte getBeanByte() { 22 | return beanByte; 23 | } 24 | public void setBeanByte(byte beanByte) { 25 | this.beanByte = beanByte; 26 | } 27 | public char getBeanChar() { 28 | return beanChar; 29 | } 30 | public void setBeanChar(char beanChar) { 31 | this.beanChar = beanChar; 32 | } 33 | public short getBeanShort() { 34 | return beanShort; 35 | } 36 | public void setBeanShort(short beanShort) { 37 | this.beanShort = beanShort; 38 | } 39 | public int getBeanInt() { 40 | return beanInt; 41 | } 42 | public void setBeanInt(int beanInt) { 43 | this.beanInt = beanInt; 44 | } 45 | public Long getBeanLong() { 46 | return beanLong; 47 | } 48 | public void setBeanLong(Long beanLong) { 49 | this.beanLong = beanLong; 50 | } 51 | public Float getBeanFloat() { 52 | return beanFloat; 53 | } 54 | public void setBeanFloat(Float beanFloat) { 55 | this.beanFloat = beanFloat; 56 | } 57 | public Double getBeanDouble() { 58 | return beanDouble; 59 | } 60 | public void setBeanDouble(Double beanDouble) { 61 | this.beanDouble = beanDouble; 62 | } 63 | public String getBeanString() { 64 | return beanString; 65 | } 66 | public void setBeanString(String beanString) { 67 | this.beanString = beanString; 68 | } 69 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testPrimitive/Test02.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testPrimitive; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | import com.tuyang.beanutils.BeanCopyUtils; 8 | 9 | public class Test02 { 10 | 11 | private FromBean getFromBean() { 12 | FromBean fromBean = new FromBean(); 13 | 14 | fromBean.setBeanBool(true); 15 | fromBean.setBeanByte((byte)5); 16 | fromBean.setBeanChar((char)40); 17 | fromBean.setBeanShort((short)50); 18 | fromBean.setBeanInt(100); 19 | fromBean.setBeanFloat(100.50f); 20 | fromBean.setBeanLong(234323243243243234L); 21 | fromBean.setBeanDouble(2342332423.23432432523523); 22 | fromBean.setBeanString("Test test Test test."); 23 | return fromBean; 24 | } 25 | 26 | @Test 27 | public void testPrimitiveType() { 28 | FromBean fromBean = getFromBean(); 29 | ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class); 30 | assertEquals(fromBean.isBeanBool(), toBean.getBeanBool().booleanValue()); 31 | assertEquals( fromBean.getBeanByte(), toBean.getBeanByte().byteValue() ); 32 | assertEquals( fromBean.getBeanChar(), toBean.getBeanChar().charValue() ); 33 | assertEquals( fromBean.getBeanShort(), toBean.getBeanShort().shortValue() ); 34 | assertEquals( fromBean.getBeanInt(), toBean.getBeanInt().intValue() ); 35 | assertEquals( fromBean.getBeanLong().longValue(), toBean.getBeanLong()); 36 | assertEquals( fromBean.getBeanFloat().floatValue(), toBean.getBeanFloat(), 0); 37 | assertEquals( fromBean.getBeanDouble().doubleValue(), toBean.getBeanDouble(), 0 ); 38 | assertEquals( fromBean.getBeanString(), toBean.getBeanString() ); 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testPrimitive/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testPrimitive; 2 | 3 | public class ToBean { 4 | 5 | private Boolean beanBool; 6 | private Byte beanByte; 7 | private Character beanChar; 8 | private Short beanShort; 9 | private Integer beanInt; 10 | private long beanLong; 11 | private float beanFloat; 12 | private double beanDouble; 13 | private String beanString; 14 | 15 | public Boolean getBeanBool() { 16 | return beanBool; 17 | } 18 | public void setBeanBool(Boolean beanBool) { 19 | this.beanBool = beanBool; 20 | } 21 | public Byte getBeanByte() { 22 | return beanByte; 23 | } 24 | public void setBeanByte(Byte beanByte) { 25 | this.beanByte = beanByte; 26 | } 27 | public Character getBeanChar() { 28 | return beanChar; 29 | } 30 | public void setBeanChar(Character beanChar) { 31 | this.beanChar = beanChar; 32 | } 33 | public Short getBeanShort() { 34 | return beanShort; 35 | } 36 | public void setBeanShort(Short beanShort) { 37 | this.beanShort = beanShort; 38 | } 39 | public Integer getBeanInt() { 40 | return beanInt; 41 | } 42 | public void setBeanInt(Integer beanInt) { 43 | this.beanInt = beanInt; 44 | } 45 | public long getBeanLong() { 46 | return beanLong; 47 | } 48 | public void setBeanLong(long beanLong) { 49 | this.beanLong = beanLong; 50 | } 51 | public float getBeanFloat() { 52 | return beanFloat; 53 | } 54 | public void setBeanFloat(float beanFloat) { 55 | this.beanFloat = beanFloat; 56 | } 57 | public double getBeanDouble() { 58 | return beanDouble; 59 | } 60 | public void setBeanDouble(double beanDouble) { 61 | this.beanDouble = beanDouble; 62 | } 63 | public String getBeanString() { 64 | return beanString; 65 | } 66 | public void setBeanString(String beanString) { 67 | this.beanString = beanString; 68 | } 69 | 70 | 71 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testRecursion/FromBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testRecursion; 2 | 3 | public class FromBean { 4 | 5 | private int beanInt; 6 | private long beanLong; 7 | 8 | private String beanString; 9 | 10 | FromBean2 bean2; 11 | 12 | public int getBeanInt() { 13 | return beanInt; 14 | } 15 | 16 | public void setBeanInt(int beanInt) { 17 | this.beanInt = beanInt; 18 | } 19 | 20 | public long getBeanLong() { 21 | return beanLong; 22 | } 23 | 24 | public void setBeanLong(long beanLong) { 25 | this.beanLong = beanLong; 26 | } 27 | public String getBeanString() { 28 | return beanString; 29 | } 30 | 31 | public void setBeanString(String beanString) { 32 | this.beanString = beanString; 33 | } 34 | 35 | public FromBean2 getBean2() { 36 | return bean2; 37 | } 38 | 39 | public void setBean2(FromBean2 bean2) { 40 | this.bean2 = bean2; 41 | } 42 | 43 | 44 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testRecursion/FromBean2.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testRecursion; 2 | 3 | public class FromBean2 { 4 | 5 | private int beanInt; 6 | private long beanLong; 7 | 8 | private String beanString; 9 | 10 | private FromBean3 bean3; 11 | 12 | public int getBeanInt() { 13 | return beanInt; 14 | } 15 | 16 | public void setBeanInt(int beanInt) { 17 | this.beanInt = beanInt; 18 | } 19 | 20 | public long getBeanLong() { 21 | return beanLong; 22 | } 23 | 24 | public void setBeanLong(long beanLong) { 25 | this.beanLong = beanLong; 26 | } 27 | 28 | public String getBeanString() { 29 | return beanString; 30 | } 31 | 32 | public void setBeanString(String beanString) { 33 | this.beanString = beanString; 34 | } 35 | 36 | public FromBean3 getBean3() { 37 | return bean3; 38 | } 39 | 40 | public void setBean3(FromBean3 bean3) { 41 | this.bean3 = bean3; 42 | } 43 | 44 | 45 | 46 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testRecursion/FromBean3.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testRecursion; 2 | 3 | public class FromBean3 { 4 | 5 | private FromBean4 bean4; 6 | 7 | public FromBean4 getBean4() { 8 | return bean4; 9 | } 10 | 11 | public void setBean4(FromBean4 bean4) { 12 | this.bean4 = bean4; 13 | } 14 | 15 | 16 | 17 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testRecursion/FromBean4.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testRecursion; 2 | 3 | public class FromBean4 { 4 | 5 | FromBean5 bean5; 6 | 7 | public FromBean5 getBean5() { 8 | return bean5; 9 | } 10 | 11 | public void setBean5(FromBean5 bean5) { 12 | this.bean5 = bean5; 13 | } 14 | 15 | 16 | 17 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testRecursion/FromBean5.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testRecursion; 2 | 3 | public class FromBean5 { 4 | 5 | FromBean6 bean6; 6 | 7 | public FromBean6 getBean6() { 8 | return bean6; 9 | } 10 | 11 | public void setBean6(FromBean6 bean6) { 12 | this.bean6 = bean6; 13 | } 14 | 15 | 16 | 17 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testRecursion/FromBean6.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testRecursion; 2 | 3 | public class FromBean6 { 4 | 5 | FromBean7 bean7; 6 | 7 | public FromBean7 getBean7() { 8 | return bean7; 9 | } 10 | 11 | public void setBean7(FromBean7 bean7) { 12 | this.bean7 = bean7; 13 | } 14 | 15 | 16 | 17 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testRecursion/FromBean7.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testRecursion; 2 | 3 | public class FromBean7 { 4 | 5 | FromBean8 bean8; 6 | 7 | public FromBean8 getBean8() { 8 | return bean8; 9 | } 10 | 11 | public void setBean8(FromBean8 bean8) { 12 | this.bean8 = bean8; 13 | } 14 | 15 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testRecursion/FromBean8.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testRecursion; 2 | 3 | public class FromBean8 { 4 | 5 | private Float beanFloat; 6 | private String beanString; 7 | 8 | public Float getBeanFloat() { 9 | return beanFloat; 10 | } 11 | public void setBeanFloat(Float beanFloat) { 12 | this.beanFloat = beanFloat; 13 | } 14 | public String getBeanString() { 15 | return beanString; 16 | } 17 | public void setBeanString(String beanString) { 18 | this.beanString = beanString; 19 | } 20 | 21 | 22 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testRecursion/Test06.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testRecursion; 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 Test06 { 10 | 11 | private FromBean getFromBean() { 12 | FromBean fromBean = new FromBean(); 13 | fromBean.setBeanInt(100); 14 | fromBean.setBeanLong(200); 15 | fromBean.setBeanString("Test test Test test."); 16 | 17 | FromBean8 bean8 = new FromBean8(); 18 | bean8.setBeanFloat(10.4f); 19 | bean8.setBeanString("bean8"); 20 | 21 | FromBean7 bean7 = new FromBean7(); 22 | bean7.setBean8(bean8); 23 | 24 | FromBean6 bean6 = new FromBean6(); 25 | bean6.setBean7(bean7); 26 | 27 | FromBean5 bean5 = new FromBean5(); 28 | bean5.setBean6(bean6); 29 | 30 | FromBean4 bean4 = new FromBean4(); 31 | bean4.setBean5(bean5); 32 | 33 | FromBean3 bean3 = new FromBean3(); 34 | bean3.setBean4(bean4); 35 | 36 | FromBean2 bean2 = new FromBean2(); 37 | bean2.setBean3(bean3); 38 | bean2.setBeanInt(100); 39 | bean2.setBeanLong(200L); 40 | bean2.setBeanString("Test bean2"); 41 | 42 | fromBean.setBean2(bean2); 43 | 44 | return fromBean; 45 | } 46 | 47 | @Test 48 | public void testRecursion() { 49 | FromBean fromBean = getFromBean(); 50 | ToBean toBean = BeanCopyUtils.copyBean(fromBean, ToBean.class); 51 | 52 | assertEquals(fromBean.getBean2().getBeanInt(), toBean.getBean2Int()); 53 | assertEquals(fromBean.getBean2().getBeanLong(), toBean.getBean2Long().longValue()); 54 | assertEquals(fromBean.getBean2().getBeanString(), toBean.getBean2Str()); 55 | 56 | assertEquals( fromBean.getBean2().getBean3().getBean4().getBean5().getBean6().getBean7().getBean8().getBeanFloat().floatValue(), 57 | toBean.getBean8Float(), 0 ); 58 | assertEquals( fromBean.getBean2().getBean3().getBean4().getBean5().getBean6().getBean7().getBean8().getBeanString(), 59 | toBean.getBean8String() ); 60 | assertEquals( fromBean.getBeanInt(), toBean.getBeanInt().intValue() ); 61 | assertEquals( fromBean.getBeanLong(), toBean.getBeanLong()); 62 | assertEquals( fromBean.getBeanString(), toBean.getBeanString() ); 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testRecursion/ToBean.java: -------------------------------------------------------------------------------- 1 | package com.tuyang.test.testRecursion; 2 | 3 | import com.tuyang.beanutils.annotation.CopyProperty; 4 | import com.tuyang.beanutils.annotation.BeanCopySource; 5 | 6 | @BeanCopySource(source=FromBean.class) 7 | public class ToBean { 8 | 9 | private Integer beanInt; 10 | private long beanLong; 11 | private String beanString; 12 | 13 | @CopyProperty(property="bean2.beanInt") 14 | private int bean2Int; 15 | @CopyProperty(property="bean2.beanLong") 16 | private Long bean2Long; 17 | @CopyProperty(property="bean2.beanString") 18 | private String bean2Str; 19 | 20 | @CopyProperty(property="bean2.bean3.bean4.bean5.bean6.bean7.bean8.beanFloat") 21 | private float bean8Float; 22 | 23 | @CopyProperty(property="bean2.bean3.bean4.bean5.bean6.bean7.bean8.beanString") 24 | private String bean8String; 25 | 26 | public Integer getBeanInt() { 27 | return beanInt; 28 | } 29 | 30 | public void setBeanInt(Integer beanInt) { 31 | this.beanInt = beanInt; 32 | } 33 | 34 | public long getBeanLong() { 35 | return beanLong; 36 | } 37 | 38 | public void setBeanLong(long beanLong) { 39 | this.beanLong = beanLong; 40 | } 41 | 42 | public String getBeanString() { 43 | return beanString; 44 | } 45 | 46 | public void setBeanString(String beanString) { 47 | this.beanString = beanString; 48 | } 49 | 50 | public int getBean2Int() { 51 | return bean2Int; 52 | } 53 | 54 | public void setBean2Int(int bean2Int) { 55 | this.bean2Int = bean2Int; 56 | } 57 | 58 | public Long getBean2Long() { 59 | return bean2Long; 60 | } 61 | 62 | public void setBean2Long(Long bean2Long) { 63 | this.bean2Long = bean2Long; 64 | } 65 | 66 | public String getBean2Str() { 67 | return bean2Str; 68 | } 69 | 70 | public void setBean2Str(String bean2Str) { 71 | this.bean2Str = bean2Str; 72 | } 73 | 74 | public float getBean8Float() { 75 | return bean8Float; 76 | } 77 | 78 | public void setBean8Float(float bean8Float) { 79 | this.bean8Float = bean8Float; 80 | } 81 | 82 | public String getBean8String() { 83 | return bean8String; 84 | } 85 | 86 | public void setBean8String(String bean8String) { 87 | this.bean8String = bean8String; 88 | } 89 | 90 | 91 | 92 | } -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testRecursion2/FromBean.java: -------------------------------------------------------------------------------- 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 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testRecursion2/TestRecursion.java: -------------------------------------------------------------------------------- 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 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/tuyang/test/testRecursion2/ToBean.java: -------------------------------------------------------------------------------- 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 | } 26 | --------------------------------------------------------------------------------