/**
 * @author Thomas Bellembois
 * @version
 * 
 * Creation date : 17 juil. 2006
 * Last modification :
 */
package org.esupportail.webdavserver.store.uPortal;

import java.util.Comparator;

import org.apache.commons.lang.StringUtils;

public class GroupsComparator_natural implements Comparator {

	public int compare(Object o1, Object o2) {
		
		String groupA = (String)o1;
		String groupB = (String)o2;
		
		groupA = StringUtils.removeStart(StringUtils.removeEnd(groupA, "/"), "/");
		groupB = StringUtils.removeStart(StringUtils.removeEnd(groupB, "/"), "/");
		
		if (StringUtils.countMatches(groupA, "/") == StringUtils.countMatches(groupB, "/"))	{
			return groupA.compareTo(groupB);
		}
		if (StringUtils.indexOf(groupB, groupA) == 0) return -1;
		else return groupA.compareTo(groupB);
		
	}

}
