@Test public void shouldNeedAtLeastOneComparator() { Comparator<String> c = new CompoundComparator<>(); thrown.expect(IllegalStateException.class); c.compare("foo", "bar"); }
/** * 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)); } }
/** * <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; }
@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; }