I have a problem, I'm trying to compare two arraylist so that I can fullfile another with the information as one, the problem is described above:
I have this query:
public ArrayList consultaEntidadPresencial (GlpiEntities gentities){
ArrayList consulta = new ArrayList();
try {
cnn=Conectar.getInstace();
ps=cnn.prepareStatement("SELECT\n" + "glpi_entities.name,\n" + "Sum(glpi_tickettasks.actiontime)/3600 AS Tiempo\n" + "FROM\n" + "glpi_tickettasks\n" + "INNER JOIN glpi_tickets ON glpi_tickets.id = glpi_tickettasks.tickets_id\n" + "INNER JOIN glpi_entities ON glpi_tickets.entities_id = glpi_entities.id\n" + "WHERE\n" + "glpi_tickettasks.date BETWEEN ? AND ? AND\n" + "glpi_tickettasks.taskcategories_id = 4\n" +"GROUP BY\n" + "glpi_entities.name");
ps.setDate(1,gentities.getfInicial());
ps.setDate(2, gentities.getfFinal());
rs=ps.executeQuery();
while(rs.next()){
GlpiEntities gtickets=new GlpiEntities();
gtickets.setName(rs.getString(1));
gtickets.setTiempoPresencial(rs.getDouble(2));
consulta.add(gtickets);
}
} catch (NamingException ex) {
Logger.getLogger(TasksDao.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(TasksDao.class.getName()).log(Level.SEVERE, null, ex);
}
return consulta;
}
And I have another Query which just changes glpi_tickettasks.taskcategories_id = 3 (just the number), this is because at our company we specify services as remote or presencial (I've tried getting the information from the query but I wasn't able to get what I wanted)
afther executing both querys I get two Arraylist with the objects on it, one has the following Data: Name: (entitie name) RemoteTime: 1.5
and the other: Name (entitie name) PresentialTime:5.5
and as I want to show that information on the web page then I've made a controller which has the following code:
if(request.getParameter("entidad")!=null && request.getParameter("entidad").equals("Enviar")){
String fInicial=request.getParameter("inicial");
String fFinal= request.getParameter("final");
if(fInicial.length()<19 || fFinal.length()<19){
response.sendRedirect("reportes/Reportegeneral.jsp?msg=Las fechas deben ser ingresadas con el formato Año-Mes-Día horas-minutos-segundos.");
}else{
GlpiEntities entities=new GlpiEntities();
try {
Date inicial=formatter.parse(fInicial);
Date fechaF=formatter.parse(fFinal);
fi=new java.sql.Date(inicial.getTime());
ff=new java.sql.Date(fechaF.getTime());
int arraySize=0;
entities.setfInicial(fi);
entities.setfFinal(ff);
ArrayList<GlpiEntities> presencial=tdao.consultaEntidadPresencial(entities);
ArrayList<GlpiEntities> remoto=tdao.consultaEntidadRemoto(entities);
List<GlpiEntities> resultado= new ArrayList<GlpiEntities>();
if(presencial.size()>remoto.size()){
arraySize=presencial.size();
}else if (remoto.size()>presencial.size()) {
arraySize=remoto.size();
}
for (GlpiEntities presential: presencial){
for(GlpiEntities remote: remoto){
if(!presential.getName().equals(remote.getName())){
//out.print(" <br/> el valor de primer if es: "+presential.getName());
resultado.add(presential);
}else if(presential.getName().equals(remote.getName())){
presential.setTiempoRemoto(remote.getTiempoRemoto());
//out.print(" <br/> el valor de primer if es: "+presential.getName()+" Valor de remoto"+remote.getName());
resultado.add(presential);
}
}
for(GlpiEntities listado: resultado){
out.print(" <br/> Nombre entidad: "+listado.getName());
out.print(" <br/> Tiempo Presencial: "+listado.getTiempoPresencial());
out.print(" <br/> Tiempo Remoto: "+listado.getTiempoRemoto());
}
}
sesion.setAttribute("entidaddetalle", resultado);
response.sendRedirect("reportes/Reportegeneral.jsp?resul=ok");
} catch (ParseException ex) {
Logger.getLogger(ReporteCtrol.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
As you can see I have an If which evaluates which of the arrays has the higest value I mean which one is the bigger one, this was beacuse I thought the best way was using a normal for to read the arrays but then afther a google search I've found THIS LINK and then I've tried to use a for:each to solve the problem but when I was performing some proofs I've realized that the object was into the new array Hundreds of times so what I want to achieve with this is I want to compare the two arrays and if the entities which is on remote doesn't exist on precenial array then it should be added to a new arraylist, but if the entitie on remote object does exists then I want to add remote time to that objet and then add it to the new arraylist, but it doesn't work so suggestions are very welcome.
PD: oh almost forgot it, the Br you see are for debugging just to know what is being processed.