private static <E extends ArrangementEntry> void sortByName(@NotNull List<E> entries) {
    if (entries.size() < 2) {
      return;
    }
    final Object2IntMap<E> weights = new Object2IntOpenHashMap<>();
    int i = 0;
    for (E e : entries) {
      weights.put(e, ++i);
    }
    ContainerUtil.sort(entries, (e1, e2) -> {
      String name1 = e1 instanceof NameAwareArrangementEntry ? ((NameAwareArrangementEntry)e1).getName() : null;
      String name2 = e2 instanceof NameAwareArrangementEntry ? ((NameAwareArrangementEntry)e2).getName() : null;
      if (name1 != null && name2 != null) {
        return name1.compareTo(name2);
      }
      else if (name1 == null && name2 == null) {
        return weights.getInt(e1) - weights.getInt(e2);
      }
      else if (name2 == null) {
        return -1;
      }
      else {
        return 1;
      }
    });
  }
private static <E extends ArrangementEntry> void sortByName(@NotNull List<E> entries)