Example usage for java.util Comparator comparing

List of usage examples for java.util Comparator comparing

Introduction

In this page you can find the example usage for java.util Comparator comparing.

Prototype

public static <T, U extends Comparable<? super U>> Comparator<T> comparing(
        Function<? super T, ? extends U> keyExtractor) 

Source Link

Document

Accepts a function that extracts a java.lang.Comparable Comparable sort key from a type T , and returns a Comparator that compares by that sort key.

Usage

From source file:jease.cms.service.Informations.java

public Map<Class<?>, Integer> getDatabaseClassCount() {
    Map<Class<?>, Integer> resultMap = new TreeMap<>(Comparator.comparing(Class::getName));
    //      for (Persistent obj : Database.query(Persistent.class)) {
    //         Class<?> clazz = obj.getClass();
    //         if (!resultMap.containsKey(clazz)) {
    //            resultMap.put(clazz, 0);
    //         }//from   w w  w . j a va  2 s. c o  m
    //         resultMap.put(clazz, resultMap.get(clazz) + 1);
    //      }
    return resultMap;
}

From source file:org.kie.workbench.common.migration.cli.MigrationApp.java

public MigrationApp(String args[]) {

    actualConfig = parseToolConfigOrExit(args);

    ServiceLoader<MigrationTool> migrationLoader = ServiceLoader.load(MigrationTool.class);

    migrationLoader.forEach(migrationTool -> migrationTools.add(migrationTool));

    Collections.sort(migrationTools, Comparator.comparing(MigrationTool::getPriority));
}

From source file:com.wrmsr.kleist.Segment.java

@JsonCreator
public Segment(@JsonProperty("generation") long generation,
        @JsonProperty("created_datetime") Instant createdDatetime,
        @JsonProperty("splits") Map<String, Split> splits) {
    checkArgument(generation >= 0);/*from w w w . j  a  va 2 s .  c o  m*/
    this.generation = generation;
    this.createdDatetime = requireNonNull(createdDatetime);
    this.splits = splits.entrySet().stream().sorted(Comparator.comparing(e -> e.getValue().getMinSequence()))
            .collect(toLinkedHashMap());
    checkArgument(zip(this.splits.values().stream(), this.splits.values().stream().skip(1))
            .allMatch(pair -> pair.getLeft().getMaxSequence() < pair.getRight().getMinSequence()));
}

From source file:pt.ist.fenix.ui.spring.BookmarksController.java

@RequestMapping
public String bookmarks(Model model) {
    model.addAttribute("bookmarks",
            Authenticate.getUser().getBookmarksSet().stream()
                    .sorted(Comparator.comparing(cat -> cat.getSite().getName().getContent()))
                    .collect(Collectors.toList()));
    final Student student = AccessControl.getPerson().getStudent();
    if (student != null) {
        model.addAttribute("courses",
                student.getActiveRegistrationsIn(ExecutionSemester.readActualExecutionSemester()).stream()
                        .flatMap(registration -> registration
                                .getAttendingExecutionCoursesForCurrentExecutionPeriod().stream())
                        .collect(Collectors.toList()));
    }/*  ww  w. j  ava 2 s.com*/
    return "fenix-learning/bookmarks";
}

From source file:org.apache.nifi.toolkit.cli.impl.result.VersionedFlowSnapshotMetadataResult.java

public VersionedFlowSnapshotMetadataResult(final ResultType resultType,
        final List<VersionedFlowSnapshotMetadata> versions) {
    super(resultType);
    this.versions = versions;
    Validate.notNull(this.versions);
    this.versions.sort(Comparator.comparing(VersionedFlowSnapshotMetadata::getVersion));
}

From source file:net.kemitix.checkstyle.ruleset.builder.DefaultReadmeIndexBuilder.java

@Override
public final String build() {
    return rulesProperties.getRules().stream().sorted(Comparator.comparing(lowerCaseRuleName()))
            .map(this::formatRuleRow).collect(Collectors.joining(NEWLINE));
}

From source file:io.github.resilience4j.ratelimiter.monitoring.endpoint.RateLimiterEventsEndpoint.java

@ReadOperation
public RateLimiterEventsEndpointResponse getAllRateLimiterEvents() {
    List<RateLimiterEventDTO> eventsList = eventsConsumerRegistry.getAllEventConsumer()
            .flatMap(CircularEventConsumer::getBufferedEvents)
            .sorted(Comparator.comparing(RateLimiterEvent::getCreationTime))
            .map(RateLimiterEventDTO::createRateLimiterEventDTO).toJavaList();
    return new RateLimiterEventsEndpointResponse(eventsList);
}

From source file:org.obiba.mica.study.rest.DraftHarmonizationStudiesResource.java

@GET
@Path("/harmonization-studies")
@Timed//from   w  ww  .j a  va  2  s. com
public List<Mica.StudyDto> list() {
    return harmonizationStudyService.findAllDraftStudies().stream()
            .filter(s -> subjectAclService.isPermitted("/draft/harmonization-study", "VIEW", s.getId()))
            .sorted(Comparator.comparing(AbstractGitPersistable::getId)).map(s -> dtos.asDto(s, true))
            .collect(Collectors.toList());
}

From source file:org.apache.nifi.toolkit.cli.impl.result.ProcessGroupsResult.java

public ProcessGroupsResult(final ResultType resultType, final List<ProcessGroupDTO> processGroups) {
    super(resultType);
    this.processGroups = processGroups;
    Validate.notNull(this.processGroups);
    this.processGroups.sort(Comparator.comparing(ProcessGroupDTO::getName));
}

From source file:am.ik.categolj3.api.category.InMemoryCategoryService.java

@Override
public List<List<String>> findAllOrderByNameAsc() {
    return this.categories.values().stream().distinct()
            .sorted(Comparator.comparing(categories -> String.join(",", categories)))
            .collect(Collectors.toList());
}