package com.edgardleal.benchmark.example;

import com.edgardleal.benchmark.Benchmark;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by edgardleal on 24/07/16.
 */
public class BeanUtilsExample {

  public BeanUtilsExample() {

  }

  public void timeBeanutils() {
    List<Cliente> list = new ArrayList<Cliente>();
    for (int i = 0; i < Benchmark.ITERATIONS; i++) {
      Cliente cliente = new Cliente("Teste", 5, 7.7, "Test street");
      Cliente second = new Cliente();
      try {
        second = (Cliente) BeanUtils.cloneBean(cliente);
        list.add(second);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  }

  public void timeReflection() {
    List<Cliente> list = new ArrayList<Cliente>();
    for (int i = 0; i < Benchmark.ITERATIONS; i++) {
      Cliente cliente = new Cliente("Teste", 5, 7.7, "Test street");
      Cliente second = new Cliente();
      try {
        Field fields[] = Cliente.class.getDeclaredFields();
        for (Field field : fields) {
          String capitalizedName = StringUtils.capitalize(field.getName());
          Cliente.class.getDeclaredMethod("set" + capitalizedName,
              field.getType()).invoke(second,
              Cliente.class.getDeclaredMethod("get" + capitalizedName).invoke(cliente, new Class<?>[0])
          );
          list.add(second);
        }
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  }
}

@@ -368,24 +368,479 @@
 e() %7B%0A%0A  %7D%0A%0A
+  public void timeGetAndSet() %7B%0A    List%3CCliente%3E list = new ArrayList%3CCliente%3E();%0A    for (int i = 0; i %3C Benchmark.ITERATIONS; i++) %7B%0A      Cliente cliente = new Cliente(%22Teste%22, 5, 7.7, %22Test street%22);%0A      Cliente second = new Cliente();%0A      second.setNome(cliente.getNome());%0A      second.setIdade(cliente.getIdade());%0A      second.setSaldo(cliente.getSaldo());%0A      second.setEndereco(cliente.getEndereco());%0A%0A      list.add(second);%0A    %7D%0A  %7D%0A%0A
   public voi

Include get and set example to BeanUtilExample