private static boolean requiresReorder()

in src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrResourceProvider.java [565:589]


    private static boolean requiresReorder(@NotNull Node node, @NotNull String name, @Nullable String followingSiblingName) throws RepositoryException {
        NodeIterator nodeIterator = node.getNodes();
        long existingNodePosition = -1;
        long index = 0;
        while (nodeIterator.hasNext()) {
            Node childNode = nodeIterator.nextNode();
            if (childNode.getName().equals(name)) {
                existingNodePosition = index;
            }
            if (existingNodePosition >= 0) {
                // is existing resource already at the desired position?
                if (childNode.getName().equals(followingSiblingName)) {
                    if (existingNodePosition == index - 1) {
                        return false;
                    }
                }
                // is the existing node already the last one in the list?
                else if (followingSiblingName == null && existingNodePosition == nodeIterator.getSize() - 1) {
                    return false;
                }
            }
            index++;
        }
        return true;
    }