Sort a bean

Sort a bean

java.util.Comparator
java.util.TreeSet
org.apache.cocoon.i18n.XMLResourceBundle
org.apache.cocoon.i18n.XMLResourceBundleFactory
 
ListTravelerType = hs.createQuery("FROM Utypes WHERE isdefault = 1 ORDER BY type ASC").list();
 
try {
	XMLResourceBundle translationBundle = null;
	XMLResourceBundleFactory bf = (XMLResourceBundleFactory)manager.lookup(XMLResourceBundleFactory.ROLE);
	translationBundle = (XMLResourceBundle)bf.select("/opt/tomcat/webapps/project/translations", "travelertypes", );
 
	for(Iterator i = ListTravelerType.iterator(); i.hasNext();) {
		Utypes elt = (Utypes)i.next();
		hs.evict(elt);
		elt.setType(translationBundle.getString(elt.getType()));
	}
} catch (Exception cme) {
	logger.error("Could not look up the PersistenceManager", cme);
}
 
Set sortedTravelerType = new TreeSet(new Comparator() {
	public int compare(Object o1, Object o2) {
		if(o1 instanceof Utypes && o2 instanceof Utypes) {
			Utypes utype1 = (Utypes)o1;
			Utypes utype2 = (Utypes)o2;
			return utype1.getType().compareTo(utype2.getType());
		}
		return 1;
	}
});
 
sortedTravelerType.addAll(ListTravelerType);