/** * Construct a CompoundComparator from the Comparators in the provided array. * <p>All Comparators will default to ascending sort order, * unless they are InvertibleComparators. * @param comparators the comparators to build into a compound comparator * @see InvertibleComparator */ @SuppressWarnings("unchecked") public CompoundComparator(Comparator... comparators) { Assert.notNull(comparators, "Comparators must not be null"); this.comparators = new ArrayList<>(comparators.length); for (Comparator comparator : comparators) { addComparator(comparator); } }
@Test public void shouldNeedAtLeastOneComparator() { Comparator<String> c = new CompoundComparator<>(); thrown.expect(IllegalStateException.class); c.compare("foo", "bar"); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public Comparator<?> aerospikePropertyComparator(Query<?> query ) { if (query == null || query.getSort() == null) { return null; } CompoundComparator compoundComperator = new CompoundComparator(); for (Order order : query.getSort()) { if (Direction.DESC.equals(order.getDirection())) { compoundComperator.addComparator(new PropertyComparator(order.getProperty(), true, false)); }else { compoundComperator.addComparator(new PropertyComparator(order.getProperty(), true, true)); } } return compoundComperator; }
/** * Change the sort order at the given index to descending sort. * @param index the index of the comparator to change */ public void setDescendingOrder(int index) { getInvertibleComparator(index).setAscending(false); }
/** * <p> * Sort on a sequence of fields, possibly none. * </P> * * @param query If not null, will contain one of more {@link Sort.Order} objects. * @return A sequence of comparators or {@code null} */ public Comparator<Entry<?, ?>> resolve(KeyValueQuery<?> query) { if (query == null || query.getSort() == Sort.unsorted()) { return null; } CompoundComparator<Entry<?, ?>> compoundComparator = new CompoundComparator<>(); for (Order order : query.getSort()) { if (order.getProperty().indexOf('.') > -1) { throw new UnsupportedOperationException("Embedded fields not implemented: " + order); } if (order.isIgnoreCase()) { throw new UnsupportedOperationException("Ignore case not implemented: " + order); } if (NullHandling.NATIVE != order.getNullHandling()) { throw new UnsupportedOperationException("Null handling not implemented: " + order); } HazelcastPropertyComparator hazelcastPropertyComparator = new HazelcastPropertyComparator(order.getProperty(), order.isAscending()); compoundComparator.addComparator(hazelcastPropertyComparator); } return compoundComparator; }
/** * Invert the sort order of the sort definition at the specified index. * @param index the index of the comparator to invert */ public void invertOrder(int index) { getInvertibleComparator(index).invertOrder(); }
/** * Construct a CompoundComparator from the Comparators in the provided array. * <p>All Comparators will default to ascending sort order, * unless they are InvertibleComparators. * @param comparators the comparators to build into a compound comparator * @see InvertibleComparator */ @SuppressWarnings("unchecked") public CompoundComparator(Comparator... comparators) { Assert.notNull(comparators, "Comparators must not be null"); this.comparators = new ArrayList<>(comparators.length); for (Comparator comparator : comparators) { addComparator(comparator); } }
/** * Sorts the given list of {@code MediaType} objects by specificity as the * primary criteria and quality value the secondary. * @see MediaType#sortBySpecificity(List) * @see MediaType#sortByQualityValue(List) */ public static void sortBySpecificityAndQuality(List<MediaType> mediaTypes) { Assert.notNull(mediaTypes, "'mediaTypes' must not be null"); if (mediaTypes.size() > 1) { Collections.sort(mediaTypes, new CompoundComparator<MediaType>( MediaType.SPECIFICITY_COMPARATOR, MediaType.QUALITY_VALUE_COMPARATOR)); } }
/** * Change the sort order at the given index to ascending. * @param index the index of the comparator to change */ public void setAscendingOrder(int index) { getInvertibleComparator(index).setAscending(true); }
/** * Construct a CompoundComparator from the Comparators in the provided array. * <p>All Comparators will default to ascending sort order, * unless they are InvertibleComparators. * @param comparators the comparators to build into a compound comparator * @see InvertibleComparator */ public CompoundComparator(Comparator[] comparators) { this.comparators = new ArrayList<InvertibleComparator<T>>(comparators.length); for (Comparator<T> comparator : comparators) { addComparator(comparator); } }
/** * Construct a CompoundComparator from the Comparators in the provided array. * <p>All Comparators will default to ascending sort order, * unless they are InvertibleComparators. * @param comparators the comparators to build into a compound comparator * @see InvertibleComparator */ public CompoundComparator(Comparator[] comparators) { this.comparators = new ArrayList(comparators.length); for (int i = 0; i < comparators.length; i++) { addComparator(comparators[i]); } }
/** * Construct a CompoundComparator from the Comparators in the provided array. * <p>All Comparators will default to ascending sort order, * unless they are InvertibleComparators. * @param comparators the comparators to build into a compound comparator * @see InvertibleComparator */ @SuppressWarnings("unchecked") public CompoundComparator(Comparator... comparators) { Assert.notNull(comparators, "Comparators must not be null"); this.comparators = new ArrayList<>(comparators.length); for (Comparator comparator : comparators) { addComparator(comparator); } }
/** * Construct a CompoundComparator from the Comparators in the provided array. * <p>All Comparators will default to ascending sort order, * unless they are InvertibleComparators. * @param comparators the comparators to build into a compound comparator * @see InvertibleComparator */ @SuppressWarnings("unchecked") public CompoundComparator(Comparator... comparators) { Assert.notNull(comparators, "Comparators must not be null"); this.comparators = new ArrayList<>(comparators.length); for (Comparator comparator : comparators) { addComparator(comparator); } }