
com.day.jcr.vault.util.NodeNameComparator Maven / Gradle / Ivy
/*************************************************************************
*
* ADOBE CONFIDENTIAL
* __________________
*
* Copyright 2011 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
*
**************************************************************************/
package com.day.jcr.vault.util;
import java.util.Comparator;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
/**
* ItemNameComparator
...
*/
public class NodeNameComparator implements Comparator {
public static final NodeNameComparator INSTANCE = new NodeNameComparator();
public int compare(Node o1, Node o2) {
try {
// sort namespaced first
String n1 = o1.getName().toLowerCase();
String n2 = o2.getName().toLowerCase();
int i1 = n1.indexOf(':');
int i2 = n2.indexOf(':');
if (i1 >=0 && i2 < 0) {
return -1;
} else if (i1 < 0 && i2 >=0) {
return 1;
} else if (n1.equals(n2)) {
// compare indexes for SNS
return o1.getIndex() - o2.getIndex();
} else {
return n1.compareTo(n2);
}
} catch (RepositoryException e) {
throw new IllegalStateException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy