FileGroup (List<? extends FileGroup> groups, String id) { for (FileGroup fileGroup : groups) { if (id.equals(fileGroup.getId())) return fileGroup; FileGroup foundInChildren = findByIdIn(fileGroup.getChildren(), id); if (foundInChildren != null) return foundInChildren; } return null; }