本文整理了Java中java.util.Comparator.thenComparing()
方法的一些代码示例,展示了Comparator.thenComparing()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Comparator.thenComparing()
方法的具体详情如下:
包路径:java.util.Comparator
类名称:Comparator
方法名:thenComparing
暂无
代码示例来源:origin: spring-projects/spring-framework
/**
* 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) {
mediaTypes.sort(MediaType.SPECIFICITY_COMPARATOR.thenComparing(MediaType.QUALITY_VALUE_COMPARATOR));
}
}
代码示例来源:origin: kiegroup/optaplanner
@Override
public int compareTo(TotalRankSolverRankingWeight other) {
return Comparator
.comparingInt(TotalRankSolverRankingWeight::getBetterCount)
.thenComparingInt(TotalRankSolverRankingWeight::getEqualCount)
.thenComparingInt(TotalRankSolverRankingWeight::getLowerCount)
.thenComparing(TotalRankSolverRankingWeight::getSolverBenchmarkResult, totalScoreSolverRankingComparator) // Tie-breaker
.compare(this, other);
}
代码示例来源:origin: org.springframework/spring-web
/**
* 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) {
mediaTypes.sort(MediaType.SPECIFICITY_COMPARATOR.thenComparing(MediaType.QUALITY_VALUE_COMPARATOR));
}
}
代码示例来源:origin: SonarSource/sonarqube
private ListDefinitionsWsResponse doHandle(Request request) {
ListDefinitionsRequest wsRequest = toWsRequest(request);
Optional<ComponentDto> component = loadComponent(wsRequest);
Optional<String> qualifier = getQualifier(component);
ListDefinitionsWsResponse.Builder wsResponse = ListDefinitionsWsResponse.newBuilder();
propertyDefinitions.getAll().stream()
.filter(definition -> qualifier.map(s -> definition.qualifiers().contains(s)).orElseGet(definition::global))
.filter(definition -> wsRequest.getBranch() == null || SETTING_ON_BRANCHES.contains(definition.key()))
.filter(definition -> settingsWsSupport.isVisible(definition.key(), definition, component))
.sorted(comparing(PropertyDefinition::category, String::compareToIgnoreCase)
.thenComparingInt(PropertyDefinition::index)
.thenComparing(PropertyDefinition::name, String::compareToIgnoreCase))
.forEach(definition -> addDefinition(definition, wsResponse));
return wsResponse.build();
}
代码示例来源:origin: robolectric/robolectric
@Nonnull
private <T> List<Class<? extends T>> prioritize(Iterable<Class<? extends T>> iterable) {
List<Class<? extends T>> serviceClasses = new ArrayList<>();
for (Class<? extends T> serviceClass : iterable) {
serviceClasses.add(serviceClass);
}
Comparator<Class<? extends T>> c = reverseOrder(comparing(PluginFinder::priority));
c = c.thenComparing(Class::getName);
serviceClasses.sort(c);
return serviceClasses;
}
代码示例来源:origin: dropwizard/dropwizard
@Override
public int compare(EndpointLogLine endpointA, EndpointLogLine endpointB) {
return Comparator.<EndpointLogLine, String>comparing(endpoint -> endpoint.basePath)
.thenComparing(endpoint -> endpoint.httpMethod, Comparator.nullsLast(Comparator.naturalOrder()))
.compare(endpointA, endpointB);
}
}
代码示例来源:origin: kiegroup/optaplanner
@Override
public int compare(SolverBenchmarkResult a, SolverBenchmarkResult b) {
return Comparator
.comparing(SolverBenchmarkResult::getFailureCount, Comparator.reverseOrder())
.thenComparing(SolverBenchmarkResult::getTotalScore, resilientScoreComparator)
.thenComparing(worstScoreSolverRankingComparator)
.compare(a, b);
}
代码示例来源:origin: speedment/speedment
@Override
public <U> Comparator<ENTITY> thenComparing(
Function<? super ENTITY, ? extends U> keyExtractor,
Comparator<? super U> keyComparator) {
return asCombined().thenComparing(keyExtractor, keyComparator);
}
代码示例来源:origin: speedment/speedment
@Override
public <U extends Comparable<? super U>> Comparator<ENTITY>
thenComparing(Function<? super ENTITY, ? extends U> keyExtractor) {
return asCombined().thenComparing(keyExtractor);
}
代码示例来源:origin: speedment/speedment
@Override
public Comparator<ENTITY> thenComparing(Comparator<? super ENTITY> other) {
return asCombined().thenComparing(other);
}
代码示例来源:origin: kiegroup/optaplanner
@Override
public int compare(SubSingleBenchmarkResult a, SubSingleBenchmarkResult b) {
return Comparator
// Reverse, less is better (redundant: failed benchmarks don't get ranked at all)
.comparing(SubSingleBenchmarkResult::hasAnyFailure, Comparator.reverseOrder())
.thenComparing(SubSingleBenchmarkResult::getRanking, Comparator.naturalOrder())
.compare(a, b);
}
代码示例来源:origin: kiegroup/optaplanner
@Override
public int compare(SubSingleBenchmarkResult a, SubSingleBenchmarkResult b) {
return Comparator
// Reverse, less is better (redundant: failed benchmarks don't get ranked at all)
.comparing(SubSingleBenchmarkResult::hasAnyFailure, Comparator.reverseOrder())
.thenComparing(SubSingleBenchmarkResult::getScore, resilientScoreComparator)
.compare(a, b);
}
代码示例来源:origin: kiegroup/optaplanner
@Override
public int compare(SingleBenchmarkResult a, SingleBenchmarkResult b) {
return Comparator
// Reverse, less is better (redundant: failed benchmarks don't get ranked at all)
.comparing(SingleBenchmarkResult::hasAnyFailure, Comparator.reverseOrder())
.thenComparing(SingleBenchmarkResult::getTotalScore, resilientScoreComparator)
.compare(a, b);
}
代码示例来源:origin: apache/incubator-druid
@VisibleForTesting
static String[] getFrequentLocations(final Stream<String> locations)
{
final Map<String, Long> locationCountMap = locations.collect(
Collectors.groupingBy(location -> location, Collectors.counting())
);
final Comparator<Map.Entry<String, Long>> valueComparator =
Map.Entry.comparingByValue(Comparator.reverseOrder());
final Comparator<Map.Entry<String, Long>> keyComparator =
Map.Entry.comparingByKey();
return locationCountMap
.entrySet().stream()
.sorted(valueComparator.thenComparing(keyComparator))
.limit(3)
.map(Map.Entry::getKey)
.toArray(String[]::new);
}
代码示例来源:origin: allure-framework/allure2
private List<Parameter> getParameters(final TestResult result) {
final TreeSet<Parameter> parametersSet = new TreeSet<>(
comparing(Parameter::getName, nullsFirst(naturalOrder()))
.thenComparing(Parameter::getValue, nullsFirst(naturalOrder()))
);
parametersSet.addAll(convert(result.getParameters(), this::convert));
return new ArrayList<>(parametersSet);
}
代码示例来源:origin: allure-framework/allure2
private List<Parameter> getParameters(final TestCaseResult source) {
final TreeSet<Parameter> parametersSet = new TreeSet<>(
comparing(Parameter::getName, nullsFirst(naturalOrder()))
.thenComparing(Parameter::getValue, nullsFirst(naturalOrder()))
);
parametersSet.addAll(convert(source.getParameters(), this::hasArgumentType, this::convert));
return new ArrayList<>(parametersSet);
}
代码示例来源:origin: graphhopper/graphhopper
private void parseSolutionsAndAddToResponse(List<List<Label.Transition>> solutions, PointList waypoints) {
for (List<Label.Transition> solution : solutions) {
final List<Trip.Leg> legs = tripFromLabel.getTrip(translation, graphExplorer, accessEgressWeighting, solution);
final PathWrapper pathWrapper = tripFromLabel.createPathWrapper(translation, waypoints, legs);
pathWrapper.setImpossible(solution.stream().anyMatch(t -> t.label.impossible));
pathWrapper.setTime((solution.get(solution.size()-1).label.currentTime - solution.get(0).label.currentTime));
response.add(pathWrapper);
}
Comparator<PathWrapper> c = Comparator.comparingInt(p -> (p.isImpossible() ? 1 : 0));
Comparator<PathWrapper> d = Comparator.comparingDouble(PathWrapper::getTime);
response.getAll().sort(c.thenComparing(d));
}
代码示例来源:origin: facebook/litho
/** Compares two {@link MethodParamModel}s based on name and annotations only. */
public static Comparator<MethodParamModel> shallowParamComparator() {
return Comparator.nullsLast(
Comparator.comparing(MethodParamModel::getName)
.thenComparing(
(a, b) ->
(a.getTypeName() == null && a.getTypeName() == b.getTypeName())
|| a.getTypeName().equals(b.getTypeName())
? 0
: -1)
.thenComparing((a, b) -> a.getAnnotations().equals(b.getAnnotations()) ? 0 : -1));
}
}
代码示例来源:origin: google/error-prone
private static ImmutableList<MethodTree> sortedByArity(Iterable<MethodTree> methodTrees) {
return sortedCopyOf(comparingArity().thenComparing(comparingPositions()), methodTrees);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testChainedComparators() {
Comparator<Dog> c = new PropertyComparator<>("lastName", false, true);
Dog dog1 = new Dog();
dog1.setFirstName("macy");
dog1.setLastName("grayspots");
Dog dog2 = new Dog();
dog2.setFirstName("biscuit");
dog2.setLastName("grayspots");
assertTrue(c.compare(dog1, dog2) == 0);
c = c.thenComparing(new PropertyComparator<>("firstName", false, true));
assertTrue(c.compare(dog1, dog2) > 0);
dog2.setLastName("konikk dog");
assertTrue(c.compare(dog2, dog1) > 0);
}
内容来源于网络,如有侵权,请联系作者删除!