NodeNameComparator.java 1.14 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  javax.jcr.Node
 *  javax.jcr.RepositoryException
 */
package com.day.jcr.vault.util;

import java.util.Comparator;
import javax.jcr.Node;
import javax.jcr.RepositoryException;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
public class NodeNameComparator
implements Comparator<Node> {
    public static final NodeNameComparator INSTANCE = new NodeNameComparator();

    @Override
    public int compare(Node o1, Node o2) {
        try {
            String n1 = o1.getName().toLowerCase();
            String n2 = o2.getName().toLowerCase();
            int i1 = n1.indexOf(58);
            int i2 = n2.indexOf(58);
            if (i1 >= 0 && i2 < 0) {
                return -1;
            }
            if (i1 < 0 && i2 >= 0) {
                return 1;
            }
            if (n1.equals(n2)) {
                return o1.getIndex() - o2.getIndex();
            }
            return n1.compareTo(n2);
        }
        catch (RepositoryException e) {
            throw new IllegalStateException((Throwable)e);
        }
    }
}