private void moveSimilarExceptions(EntityManager em, Report candidatesReport, Exceptions master, Report newReport) {
// protect the first exception report
candidatesReport.preloadSubmitCollection(em);
List<Exceptions> candidates = new ArrayList(candidatesReport.getSubmitCollection());
assert(!candidates.isEmpty());
Exceptions minimal = candidates.iterator().next();
for (Exceptions exceptions : candidates) {
if (exceptions.getId() < minimal.getId()){
minimal = exceptions;
}
}
candidates.remove(master);
candidates.remove(minimal);
//move exactly the same stacktraces
Integer mashterHash = master.getHashcodes().getCode();
Iterator<Exceptions> it = candidates.iterator();
while (it.hasNext()) {
Exceptions next = it.next();
if (next.getHashcodes().getCode().equals(mashterHash)) {
it.remove();
next.setReportId(newReport);
em.merge(next);
}
}
//move other very similar stacktraces