public Collection getYAxis(String orderBy, String direction) { Comparator comp; if (orderBy != null && orderBy.equals(TOTAL_ORDER)) { // Compare by total comp = new Comparator() { public int compare(Object o1, Object o2) { Long o1Long = new Long(getYAxisUniqueTotal(o1)); Long o2Long = new Long(getYAxisUniqueTotal(o2)); return o1Long.compareTo(o2Long); } }; // Only reverse total Comaparator, not field Comparator if (direction != null && direction.equals(DESC)) { comp = new ReverseComparator(comp); } // If totals are equal, delagate back to field comparator comp = new DelegatingComparator(comp, ComparatorSelector.getComparator(yAxisMapper)); } else { comp = yAxisMapper.getComparator(); if (direction != null && direction.equals(DESC)) { comp = new ReverseComparator(comp); } } return getYAxis(comp); }