Source:
public static Pair<ClassificationCounter, List<AttributeValueWithClassificationCounter>> getSortedListOfAttributeValuesWithClassificationCounters( final Iterable<? extends Instance<AttributesMap>> instances, final String attribute, String splitAttribute, Serializable splitAttributeValue, final Serializable minorityClassification) { Pair<ClassificationCounter, Map<Serializable, ClassificationCounter>> totalsClassificationCounterPairedWithMapofClassificationCounters = countAllByAttributeValues(instances,attribute,splitAttribute,splitAttributeValue); final Map<Serializable, ClassificationCounter> result = totalsClassificationCounterPairedWithMapofClassificationCounters.getValue1(); final ClassificationCounter totals = totalsClassificationCounterPairedWithMapofClassificationCounters.getValue0(); List<AttributeValueWithClassificationCounter> attributesWithClassificationCounters = Lists.newArrayList(); for(Serializable key : result.keySet()) { attributesWithClassificationCounters.add(new AttributeValueWithClassificationCounter(key, result.get(key))); } Collections.sort(attributesWithClassificationCounters, new Comparator<AttributeValueWithClassificationCounter>() { @Override public int compare(AttributeValueWithClassificationCounter cc1, AttributeValueWithClassificationCounter cc2) { double probOfMinority1 = cc1.classificationCounter.getCount(minorityClassification) / cc1.classificationCounter.getTotal(); double probOfMinority2 = cc2.classificationCounter.getCount(minorityClassification) / cc2.classificationCounter.getTotal(); return -Double.compare(probOfMinority1, probOfMinority2); } }); return Pair.with(totals, attributesWithClassificationCounters); }

Target:
public static Pair<ClassificationCounter, List<AttributeValueWithClassificationCounter>> getSortedListOfAttributeValuesWithClassificationCounters( final Iterable<? extends Instance<AttributesMap>> instances, final String attribute, String splitAttribute, Serializable splitAttributeValue, final Serializable minorityClassification) { Pair<ClassificationCounter, Map<Serializable, ClassificationCounter>> totalsClassificationCounterPairedWithMapofClassificationCounters = countAllByAttributeValues(instances,attribute,splitAttribute,splitAttributeValue); final Map<Serializable, ClassificationCounter> result = totalsClassificationCounterPairedWithMapofClassificationCounters.getValue1(); final ClassificationCounter totals = totalsClassificationCounterPairedWithMapofClassificationCounters.getValue0(); List<AttributeValueWithClassificationCounter> attributesWithClassificationCounters = Lists.newArrayList(); for(Serializable key : result.keySet()) { attributesWithClassificationCounters.add(new AttributeValueWithClassificationCounter(key, result.get(key))); } Collections.sort(attributesWithClassificationCounters, new Comparator<AttributeValueWithClassificationCounter>() { @Override public int compare(AttributeValueWithClassificationCounter cc1, AttributeValueWithClassificationCounter cc2) { double probOfMinority1 = cc1.classificationCounter.getCount(minorityClassification) / cc1.classificationCounter.getTotal(); double probOfMinority2 = cc2.classificationCounter.getCount(minorityClassification) / cc2.classificationCounter.getTotal(); return Ordering.natural().reverse().compare(probOfMinority1, probOfMinority2); } }); return Pair.with(totals, attributesWithClassificationCounters); }