void (@NotNull TextFieldWithHistory textFieldWithHistory, @NotNull List<String> history, boolean mergeWithPrevHistory) { Set<String> newHistorySet = new HashSet<>(history); List<String> prevHistory = textFieldWithHistory.getHistory(); List<String> mergedHistory = new ArrayList<>(history.size()); if (mergeWithPrevHistory) { for (String item : prevHistory) { if (!newHistorySet.contains(item)) { mergedHistory.add(item); } } } mergedHistory.addAll(history); String oldText = StringUtil.notNullize(textFieldWithHistory.getText()); String oldSelectedItem = ObjectUtils.tryCast(textFieldWithHistory.getSelectedItem(), String.class); if (!mergedHistory.contains(oldSelectedItem)) { oldSelectedItem = null; } textFieldWithHistory.setHistory(mergedHistory); setLongestAsPrototype(textFieldWithHistory, mergedHistory); if (oldSelectedItem != null) { textFieldWithHistory.setSelectedItem(oldSelectedItem); } if (!oldText.equals(oldSelectedItem)) { textFieldWithHistory.setText(oldText); } }