if(mds != null) {
Map orgs = new HashMap();
for (int i = 0; i < mds.length; i++) {
ModuleDescriptor descriptor = mds[i];
String organisationName = descriptor.getOrganisation();
Organisation organisation = (Organisation) orgs.get(organisationName);
if(organisation == null) {
organisation = new Organisation(organisationName);
orgs.put(organisationName, organisation);
}
organisation.addModuleRevision(descriptor.getModule(), descriptor.getRevision());
}
List values = new ArrayList(orgs.values());
Collections.sort(values, new Comparator() {
public int compare(Object o1, Object o2) {
if (o1 instanceof Organisation && o2 instanceof Organisation ) {
Organisation m1 = (Organisation) o1;
Organisation m2 = (Organisation) o2;
return m1.getName().compareTo(m2.getName());
}
return 0;
}
});
return (Organisation[]) values.toArray(new Organisation[orgs.size()]);