Map<String, Build> builds = new HashMap<String, Build>();
for (Job job : jobs) {
for (int i = 0; i < Math.min(1, job.getBuilds().size()); i++) {
BuildReference buildReference = job.getBuilds().get(i);
Build build = getBuild(project, buildReference, job);
builds.put(job.getName(), build);
}
}
List<Alert> ret = new ArrayList<Alert>();
for (Job curJob : jobs) {
Build curBuild = builds.get(curJob.getName());
if (curBuild == null)
continue;
if (Result.UNSTABLE.equals(curBuild.getResult())) {
Alert alert = new Alert(alertsCache.get(curJob.getName()),
DotColor.YELLOW, project, "Build "
+ curBuild.getNumber() + " is unstable");
alert.setOverlayVisible((System.currentTimeMillis() - curBuild
.getTimestamp().getTime()) < 90 * 1000);
alertsCache.put(curJob.getName(), alert);
ret.add(alert);
} else if (Result.FAILURE.equals(curBuild.getResult())) {
Alert alert = new Alert(alertsCache.get(curJob.getName()),
DotColor.RED, project, "Build " + curBuild.getNumber()
+ " failed");
alert.setOverlayVisible((System.currentTimeMillis() - curBuild
.getTimestamp().getTime()) < 90 * 1000);
alertsCache.put(curJob.getName(), alert);
ret.add(alert);
} else
alertsCache.remove(curJob.getName());