Collections.sort(merged, new Comparator() {
public int compare(Object o1, Object o2) {
int result;
if (o1 instanceof Styler && o2 instanceof Styler) {
Styler styler1 = (Styler) o1;
Styler styler2 = (Styler) o2;
result = styler1.getSource().compareTo(styler2.getSource());
if (result == 0) {
// source is equal, try comparing by priority
result = styler1.getPriority().compareTo(styler2.getPriority());
}
} else {
throw new IllegalArgumentException();
}
return result;
}
});
// Stuff the merged styler list back into the original mutable list.
Iterator mergedIterator = merged.iterator();
while (mergedIterator.hasNext()) {
Styler styler = (Styler) mergedIterator.next();
list.append(styler);
}
}