本文整理汇总了Java中net.sf.cglib.beans.BeanCopier类的典型用法代码示例。如果您正苦于以下问题:Java BeanCopier类的具体用法?Java BeanCopier怎么用?Java BeanCopier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BeanCopier类属于net.sf.cglib.beans包,在下文中一共展示了BeanCopier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyProperties
import net.sf.cglib.beans.BeanCopier; //导入依赖的package包/类
public static void copyProperties(Object from, Object to) {
BeanCopier bc = getCopier(from.getClass(), to.getClass());
bc.copy(from, to, new Converter() {
@Override
public Object convert(Object value, @SuppressWarnings("rawtypes") Class target, Object context) {
if (null != value && target.getName().equals("java.lang.String")) {
return value.toString();
} else if (null != value && target.isAssignableFrom(value.getClass())) {
return value;
}
return null;
}
});
}
示例2: ZkWatcher
import net.sf.cglib.beans.BeanCopier; //导入依赖的package包/类
public ZkWatcher(String hosts, int timeout, String path, T wob) throws IOException, KeeperException, InterruptedException, Exception {
this.hosts = hosts;
this.timeout = timeout;
this.path = path;
this.wob = wob;
copier = BeanCopier.create(wob.getClass(), wob.getClass(), false);
zkclient = CuratorFrameworkFactory.builder()
.connectString(hosts)
.sessionTimeoutMs(5000)
.retryPolicy(retryPolicy)
// .namespace(path)
.build();
zkclient.start();
treeCache = new TreeCache(zkclient, path);
treeCache.getListenable().addListener(this);
treeCache.start();
log.debug("treeCache=" + treeCache);
init();
}
示例3: beanCopy
import net.sf.cglib.beans.BeanCopier; //导入依赖的package包/类
private static final <T> T beanCopy(Object source, T target, Converter converter) {
if (source == null || target == null)
return target;
// always true
boolean useConvert = converter != null;
String beanKey = _generateKey(source.getClass(), target.getClass(), useConvert);
BeanCopier copier = null;
if (!beanCopiers.containsKey(beanKey)) {
copier = BeanCopier.create(source.getClass(), target.getClass(), useConvert);
beanCopiers.put(beanKey, copier);
} else {
copier = beanCopiers.get(beanKey);
}
copier.copy(source, target, converter);
return target;
}
示例4: getCopier
import net.sf.cglib.beans.BeanCopier; //导入依赖的package包/类
private static BeanCopier getCopier(Class<?> clz1, Class<?> clz2) {
if (beanCopiers.containsKey(clz1.getName() + clz2.getName()))
return beanCopiers.get(clz1.getName() + clz2.getName());
beanCopiers.putIfAbsent(clz1.getName() + clz2.getName(), BeanCopier.create(clz1, clz2, true));
return beanCopiers.get(clz1.getName() + clz2.getName());
}
示例5: copyProperties
import net.sf.cglib.beans.BeanCopier; //导入依赖的package包/类
/**
* Copy the property values of the given source bean into the target bean.
*
* @param source the source bean
* @param target the target bean
*
* @see BeanCopier
*/
@Override
public void copyProperties(Object source, Object target) {
Objects.requireNonNull(source, "source must not be null");
Objects.requireNonNull(target, "target must not be null");
BeanCopier beanCopier = getBeanCopier(source.getClass(), target.getClass());
beanCopier.copy(source, target, converter);
}
示例6: copy
import net.sf.cglib.beans.BeanCopier; //导入依赖的package包/类
public static <S,T> void copy(S source, T target){
Objects.requireNonNull(source);
Objects.requireNonNull(target);
String key = buildBeanCopierKey(source.getClass() ,target.getClass());
BeanCopier beanCopier = beanCopierMap.get(key);
if(beanCopier == null){
beanCopier = BeanCopier.create(source.getClass() ,target.getClass(), false);//not use Converter
beanCopierMap.put(key, beanCopier);
}
beanCopier.copy(source, target, null);
}
示例7: getCopier
import net.sf.cglib.beans.BeanCopier; //导入依赖的package包/类
private BeanCopier getCopier(Class<?> src, Class<?> dest) {
Map<Class<?>, BeanCopier> dest2copier = src2dest2copier.get(src);
if (dest2copier == null) {
dest2copier = new HashMap<>();
src2dest2copier.put(src, dest2copier);
}
BeanCopier copier = dest2copier.get(dest);
if (copier == null) {
copier = BeanCopier.create(src, dest, false);
dest2copier.put(dest, copier);
}
return copier;
}
示例8: copyProperties
import net.sf.cglib.beans.BeanCopier; //导入依赖的package包/类
public static void copyProperties(Object source, Object target) {
String beanKey = generateKey(source.getClass(), target.getClass());
BeanCopier copier = null;
copier = BeanCopier.create(source.getClass(), target.getClass(), false);
beanCopierMap.putIfAbsent(beanKey, copier);
copier = beanCopierMap.get(beanKey);
copier.copy(source, target, null);
}
示例9: testGetSet
import net.sf.cglib.beans.BeanCopier; //导入依赖的package包/类
public Profiler testGetSet(int invokeNum, String frameworkName) {
BeanCopier b = BeanCopier.create(Person7.class, PersonDto.class, false);
long start = System.currentTimeMillis();
for (int i = 0; i < invokeNum; i++) {
Person7 p = getPerson();
PersonDto dto = new PersonDto();
dto.setFirstName(p.getFirstName());
dto.setLastName(p.getLastName());
dto.setJobTitles(p.getJobTitles());
dto.setSalary(p.getSalary());
//System.out.println(dto);
}
return Profiler.apply(System.currentTimeMillis(), start)
.setFrameworkName(frameworkName);
}
示例10: testBeanCopier
import net.sf.cglib.beans.BeanCopier; //导入依赖的package包/类
public Profiler testBeanCopier(int invokeNum, String frameworkName) {
BeanCopier b = BeanCopier.create(Person7.class, PersonDto.class, false);
long start = System.currentTimeMillis();
for (int i = 0; i < invokeNum; i++) {
Person7 p = getPerson();
PersonDto dto = new PersonDto();
b.copy(p, dto, null);
//System.out.println(dto);
}
return Profiler.apply(System.currentTimeMillis(), start)
.setFrameworkName(frameworkName);
}
示例11: copyProperties
import net.sf.cglib.beans.BeanCopier; //导入依赖的package包/类
public static void copyProperties(Object source, Object target) {
String beanKey = generateKey(source.getClass(), target.getClass());
BeanCopier copier = null;
if (!beanCopierMap.containsKey(beanKey)) {
copier = BeanCopier.create(source.getClass(), target.getClass(), false);
beanCopierMap.put(beanKey, copier);
} else {
copier = beanCopierMap.get(beanKey);
}
copier.copy(source, target, null);
}
示例12: beanCopy
import net.sf.cglib.beans.BeanCopier; //导入依赖的package包/类
/**
* 高性能的Bean copy
* @param fromBean
* @param toBean
* @author huangxin
*/
public static void beanCopy(Object fromBean ,Object toBean){
if (fromBean == null || toBean==null) {
return;
}
BeanCopier b = BeanCopier.create(fromBean.getClass(), toBean.getClass(), false);
b.copy(fromBean, toBean, null);
}
示例13: copy
import net.sf.cglib.beans.BeanCopier; //导入依赖的package包/类
/**
* 将from实体bean的属性值拷贝至to实体类的同名属性值, 可使用自定义转换器,
* 如果使用了转换器,则由转换器完成所有的属性拷贝
*
* @param from 源对象
* @param to 目标对象
* @param converter
*/
public static void copy(Object from, Object to, Converter converter) {
if (from == null || to == null) {
return;
}
boolean useConverter = (converter != null ? true : false);
BeanCopier copier = BeanCopier.create(from.getClass(), to.getClass(),
useConverter);
copier.copy(from, to, converter);
}
示例14: getBeanCopier
import net.sf.cglib.beans.BeanCopier; //导入依赖的package包/类
private static BeanCopier getBeanCopier(Class<?> sourceClass, Class<?> targetClass) {
ClassPair classPair = new ClassPair(sourceClass, targetClass);
BeanCopier beanCopier = beanCopiers.get(classPair);
if (beanCopier == null) {
BeanCopier copier = BeanCopier.create(sourceClass, targetClass, false);
logger.info("Created BeanCopier(" + sourceClass + ',' + targetClass + ").");
beanCopiers.putIfAbsent(classPair, copier);
return beanCopiers.get(classPair);
} else {
return beanCopier;
}
}
示例15: main
import net.sf.cglib.beans.BeanCopier; //导入依赖的package包/类
public static void main(String[] args) throws IllegalAccessException, InstantiationException {
BeanCopier beanCopier = getBeanCopier(Person.class, Person.class);
Person from = null; // new Person(); // new Person(123, 124, 125, Person.A.Y);
Person to = Person.class.newInstance();
beanCopier.copy(from, to, null);
System.out.println(to);
}