if (events == null || events.size() == 0) {
List<Topic> topics = new ArrayList<Topic>(eventsGrouped.size());
for (Map.Entry topicEntry : (Set<Map.Entry>) eventsGrouped.entrySet()) {
Topic topic = new Topic();
topic.setName((String) topicEntry.getKey());
topic.setNumEvents(((Long) topicEntry.getValue()).intValue());
topics.add(topic);
}
// Sort the array on numEvents
for (int i = 1; i < topics.size(); i++) {
int numEvents = topics.get(i).getNumEvents();
int j = i - 1;
boolean done = false;
do {
if (topics.get(j).getNumEvents() < numEvents) {
Topic swapped = topics.remove(j + 1);
topics.add(j, swapped);
j--;
if (j < 0) {
done = true;
}