public int compare(Info i1, Info i2) { int result = compareAscending(i1, i2); if (ascending) { return result; } else { return result * -1; } }
/** Builds a single comparator based on the sortBy specification */ public static Comparator<Info> buildComparator(SortBy sortBy) { if (sortBy == null) { throw new NullPointerException("The sortBy argument must be not null"); } if (sortBy == SortBy.NATURAL_ORDER) { return new InfoComparator(true); } else if (sortBy == SortBy.REVERSE_ORDER) { return new InfoComparator(false); } else { return new PropertyComparator<Info>( sortBy.getPropertyName(), sortBy.getSortOrder() == SortOrder.ASCENDING); } } }