int (NodeDescriptor descriptor1, NodeDescriptor descriptor2) { descriptor1 = getUpdatedDescriptor(descriptor1); descriptor2 = getUpdatedDescriptor(descriptor2); if (descriptor1 instanceof ProjectViewNode<?> node1 && descriptor2 instanceof ProjectViewNode<?> node2) { NodeSortSettings settings = NodeSortSettings.of(isManualOrder(), getSortKey(), isFoldersAlwaysOnTop()); int sortResult = node1.getSortOrder(settings).compareTo(node2.getSortOrder(settings)); if (sortResult != 0) return sortResult; if (settings.isManualOrder()) { Comparable<?> key1 = node1.getManualOrderKey(); Comparable<?> key2 = node2.getManualOrderKey(); int result = compare(key1, key2); if (result != 0) return result; } if (settings.isFoldersAlwaysOnTop()) { int typeWeight1 = node1.getTypeSortWeight(settings.isSortByType()); int typeWeight2 = node2.getTypeSortWeight(settings.isSortByType()); if (typeWeight1 != 0 && typeWeight2 == 0) { return -1; } if (typeWeight1 == 0 && typeWeight2 != 0) { return 1; } if (typeWeight1 != 0 && typeWeight2 != typeWeight1) { return typeWeight1 - typeWeight2; } } switch (settings.getSortKey()) { case BY_NAME -> { final Comparable<?> sortKey1 = node1.getSortKey(); final Comparable<?> sortKey2 = node2.getSortKey(); if (sortKey1 != null && sortKey2 != null) { int result = compare(sortKey1, sortKey2); if (result != 0) return result; } } case BY_TYPE -> { final Comparable<?> typeSortKey1 = node1.getTypeSortKey(); final Comparable<?> typeSortKey2 = node2.getTypeSortKey(); int result = compare(typeSortKey1, typeSortKey2); if (result != 0) return result; } case BY_TIME_DESCENDING, BY_TIME_ASCENDING -> { final Comparable<?> timeSortKey1 = node1.getTimeSortKey(); final Comparable<?> timeSortKey2 = node2.getTimeSortKey(); int result = settings.getSortKey() == NodeSortKey.BY_TIME_ASCENDING ? compare(timeSortKey1, timeSortKey2, false) : compare(timeSortKey2, timeSortKey1, true); if (result != 0) return result; } } if (isAbbreviateQualifiedNames()) { String key1 = node1.getQualifiedNameSortKey(); String key2 = node2.getQualifiedNameSortKey(); if (key1 != null && key2 != null) { return naturalCompare(key1, key2); } } } if (descriptor1 == null) return -1; if (descriptor2 == null) return 1; return AlphaComparator.INSTANCE.compare(descriptor1, descriptor2); }