void (@NotNull String text, @NotNull String contributorID) { historyList.stream() .filter(item -> text.equals(item.searchText()) && contributorID.equals(item.contributorID())) .findFirst() .ifPresent(historyList::remove); historyList.add(new HistoryItem(text, contributorID)); List<String> list = filteredHistory(item -> item.contributorID().equals(contributorID)); if (list.size() > HISTORY_LIMIT) { historyList.stream() .filter(item -> item.contributorID().equals(contributorID)) .findFirst() .ifPresent(historyList::remove); } }