List<NavigatableMessageElement> (@NotNull String groupName, @NotNull ErrorTreeElementKind kind, @NotNull Navigatable navigatable) { synchronized (myLock) { List<NavigatableMessageElement> elements = myGroupNameToMessagesMap.get(groupName); if (elements == null) return Collections.emptyList(); int i = 0; List<NavigatableMessageElement> removed = new ArrayList<>(); while (i < elements.size()) { NavigatableMessageElement element = elements.get(i); if (element.getNavigatable() == navigatable && element.getKind() == kind) { removed.add(element); elements.remove(i); continue; } i++; } return removed; } }