public int compare(Feature f1, Feature f2) { int result = compareAscending(f1, f2); if (ascending) { return result; } else { return result * -1; } }
/** * Builds a single comparator based on the sortBy specification. * * <ul> * <li>{@link SortBy#NATURAL_ORDER}: sort by feature id (acceding) * <li>{@link SortBy#REVERSE_ORDER}: sort by feature id (descending) * <li>sort by supplied property name, and sort order * </ul> * * @param sortBy indication of sort order * @return Comparator used to determine sort order */ public static Comparator<Feature> buildComparator(SortBy sortBy) { if (sortBy == null) { throw new NullPointerException( "The sortBy argument must be not null (consider SortBy.UNSORTED)"); } if (sortBy == SortBy.NATURAL_ORDER) { return new FidComparator(true); } else if (sortBy == SortBy.REVERSE_ORDER) { return new FidComparator(false); } else { return new PropertyComparator<Feature>( sortBy.getPropertyName(), sortBy.getSortOrder() == SortOrder.ASCENDING); } } }