void (@NotNull Map<OrderEntry, OrderAware> orderEntryDataMap, @NotNull ModifiableRootModel modifiableRootModel) { final OrderEntry[] orderEntries = modifiableRootModel.getOrderEntries(); final int length = orderEntries.length; final OrderEntry[] newOrder = new OrderEntry[length]; final PriorityQueue<Pair<OrderEntry, OrderAware>> priorityQueue = new PriorityQueue<>( 11, (o1, o2) -> { int order1 = o1.second.getOrder(); int order2 = o2.second.getOrder(); if (order1 != order2) { return order1 < order2 ? -1 : 1; } return o1.second.toString().compareTo(o2.second.toString()); }); final List<OrderEntry> noOrderAwareItems = new ArrayList<>(); for (int i = 0; i < length; i++) { OrderEntry orderEntry = orderEntries[i]; final OrderAware orderAware = orderEntryDataMap.get(orderEntry); if (orderAware == null) { noOrderAwareItems.add(orderEntry); } else { priorityQueue.add(Pair.create(orderEntry, orderAware)); } } for (int i = 0; i < noOrderAwareItems.size(); i++) { newOrder[i] = noOrderAwareItems.get(i); } int index = noOrderAwareItems.size(); Pair<OrderEntry, OrderAware> pair; while ((pair = priorityQueue.poll()) != null) { newOrder[index] = pair.first; index++; } if (LOG.isDebugEnabled()) { boolean changed = !Arrays.equals(orderEntries, newOrder); LOG.debug(String.format("rearrange status (%s): %s", modifiableRootModel.getModule(), changed ? "modified" : "not modified")); } modifiableRootModel.rearrangeOrderEntries(newOrder); }