@Test public void testCopy() { BeanCopier copy = BeanCopier.create(Bean.class, Bean2.class, false); Bean source = new Bean(); source.setIpaddr("12.16.17.18"); source.setPin(1568); Bean2 target = null; long t = System.currentTimeMillis(); for (int i = 0; i < 10000000; i++) { target = new Bean2(); copy.copy(source, target, null); } System.out.println(System.currentTimeMillis() - t); System.out.println(target.getIpArr()); // System.out.println(target.getIpArr().size()); System.out.println(target.getIpaddr()); }
class Bean { private String ipaddr; private Integer pin;
public String getIpaddr() { return ipaddr; }
public void setIpaddr(String ipaddr) { this.ipaddr = ipaddr; }
public Integer getPin() { return pin; }
public void setPin(Integer pin) { this.pin = pin; }
}
class Bean2 { private List<String> ipArr = new ArrayList<String>(); // IP列表 private Integer pin; private String ipaddr;
public String getIpaddr() { return ipaddr; }
public void setIpaddr(String ipaddr) { if (ipaddr == null) return; // Matcher m = ps.matcher(ipaddr); // while(m.find()) // ipArr.add(m.group()); // String[] iplist = ipaddr.split(".", -1); // for (String ip : iplist) { // ipArr.add(m.group()); // ipArr.add("34"); // ipArr.add("35"); // }
this.ipaddr = ipaddr; }
public List<String> getIpArr() { return ipArr; }
public void setIpArr(List<String> ipArr) { this.ipArr = ipArr; }
public Integer getPin() { return pin; }
public void setPin(Integer pin) { this.pin = pin; }
|