private static IProblemLocation[] getHandledProblems( IProblemLocation[] locations, ContributedProcessorDescriptor processor) { // implementation tries to avoid creating a new array boolean allHandled = true; List<IProblemLocation> res = null; for (int i = 0; i < locations.length; i++) { IProblemLocation curr = locations[i]; if (processor.canHandleMarkerType(curr.getMarkerType())) { if (!allHandled) { // first handled problem if (res == null) { res = Lists.newArrayListWithCapacity(locations.length - i); } res.add(curr); } } else if (allHandled) { if (i > 0) { // first non handled problem res = Lists.newArrayListWithCapacity(locations.length - i); for (int k = 0; k < i; k++) { res.add(locations[k]); } } allHandled = false; } } if (allHandled) { return locations; } if (res == null) { return null; } return res.toArray(new IProblemLocation[res.size()]); }