List<DiffTool> (@NotNull DiffTool tool, @NotNull List<DiffTool> oldOrder, @NotNull DiffContext diffContext, @NotNull DiffRequest diffRequest) { List<FrameDiffTool> fittedTools = filterFittedTools(oldOrder, diffContext, diffRequest); FrameDiffTool toolToReplace = ContainerUtil.getFirstItem(fittedTools); if (toolToReplace == tool) return oldOrder; List<DiffTool> newOrder = new ArrayList<>(oldOrder); newOrder.remove(tool); int index = ContainerUtil.indexOf(newOrder, it -> it == toolToReplace); if (index == -1) index = newOrder.size(); newOrder.add(index, tool); return newOrder; }