0
I would like to write this method in a cleaner and more performing way. Someone has an idea?
private List<Projeto> filtraResultado(List<Projeto> projetosAssinados, String[] filtros){
List<Projeto> result = new ArrayList<Projeto>();
for(Projeto p: projetosAssinados) {
if(existeFiltroBuscadoNosCamposDePesquisa(p.getDsProjeto(), filtros) ||
existeFiltroBuscadoNosCamposDePesquisa(p.getNomeProjeto(), filtros) ||
existeFiltroBuscadoNosCamposDePesquisa(p.getSetor(),filtros) ||
existeFiltroBuscadoNosCamposDePesquisa(p.getUn(), filtros) ||
existeFiltroBuscadoNosCamposDePesquisa(p.getProcessosModelados(),filtros)||
existeFiltroBuscadoNosCamposDePesquisa(p.getServicosPrestados(),filtros) ||
existeFiltroBuscadoNosCamposDePesquisa(p.getTecnologias(),filtros)||
existeFiltroBuscadoNosCamposDePesquisa(p.getDetalhamento(),filtros)) {
result.add(p);
}
}
return result;
}
public boolean existeFiltroBuscadoNosCamposDePesquisa(String campoPesquisado,String[] filtros ){
if(campoPesquisado == null) {
return false;
}
for(String f: filtros) {
if(StringUtils.containsIgnoreCase(campoPesquisado, f.trim())) {
return true;
}
}
return false;
}
I believe it is possible to implement this with far fewer lines of code and more reusable code, and possibly using parallelism to increase performance. However, doing it in fewer lines the way I’m thinking might disrupt performance. What you consider most important in this case, simpler, reusable performance or code?
– Douglas
You are using Java 8?
– nullptr
yes I’m using java 8, I even thought about using stream, but it turns out it’s one inside another
– oitathi
I rewrote using fewer lines and less rewritten code, but I believe q is still possible to improve.
– oitathi