@SuppressWarnings("unchecked") protected boolean matches(TopLevelItem item) { if (item instanceof Job) { Job job = (Job) item; // iterate over runs and check conditions Run run = job.getLastBuild(); boolean oneMatched = false; int count = 0; while (run != null) { // check the different types of durations to see if we've checked back far enough if (amount > 0 && amountType != AmountType.Builds) { // get the amount of time since it last built long now = System.currentTimeMillis(); long then = run.getTimeInMillis(); float diff = now - then; diff = amountType.convertMillisToAmount(diff); if (diff > amount) { break; } } // now evaluate the build status boolean runMatches = matchesRun(run); if (runMatches) { if (buildCountType == BuildCountType.AtLeastOne || buildCountType == BuildCountType.Latest) { return true; } } else { if (buildCountType == BuildCountType.All) { return false; } } // if we got this far, and the type is for "latest" then it's not going to match if (buildCountType == BuildCountType.Latest) { return false; } oneMatched = true; if (amount > 0 && amountType == AmountType.Builds) { if (++count >= amount) { break; } } run = run.getPreviousBuild(); } // if we're talking about "all builds" and there was at least one build, then // it means no builds didn't match the filter if (buildCountType == BuildCountType.All && oneMatched) { return true; } // means we ran out of builds to check and did not find a match return false; } else { // wasn't of type "job" return false; } }