Example usage for java.util Comparator thenComparing

List of usage examples for java.util Comparator thenComparing

Introduction

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

Prototype

default <U extends Comparable<? super U>> Comparator<T> thenComparing(
        Function<? super T, ? extends U> keyExtractor) 

Source Link

Document

Returns a lexicographic-order comparator with a function that extracts a Comparable sort key.

Usage

From source file:de.ks.idnadrev.information.chart.ChartDataEditor.java

protected void sortGridPane() {
    ArrayList<Node> childrensToSort = new ArrayList<>(dataContainer.getChildren());

    Comparator<Node> rowCompare = Comparator.comparing(GridPane::getRowIndex);
    Comparator<Node> columnCompare = Comparator.comparing(GridPane::getColumnIndex);

    Collections.sort(childrensToSort, rowCompare.thenComparing(columnCompare));

    dataContainer.getChildren().clear();
    dataContainer.getChildren().addAll(childrensToSort);
}

From source file:com.thinkbiganalytics.metadata.cache.FeedHealthSummaryCache.java

public FeedStatus getUserFeeds(Long time, String feedName) {
    RoleSetExposingSecurityExpressionRoot userContext = feedAclCache.userContext();
    //streamline the summaries as they could have multiple
    Map<String, FeedSummary> latestFeeds = new HashMap<>();

    Comparator<FeedSummary> byRunningStatus = Comparator.comparing(FeedSummary::getRunStatus,
            Comparator.nullsLast(Comparator.naturalOrder()));

    Comparator<FeedSummary> byStartTime = Comparator.comparing(FeedSummary::getStartTime,
            Comparator.nullsLast(Comparator.naturalOrder()));

    getFeedSummaryList(time).stream().filter(
            summary -> (StringUtils.isBlank(feedName) || feedName.equalsIgnoreCase(summary.getFeedName()))
                    && feedAclCache.hasAccess(userContext, summary.getFeedId().toString()))
            .sorted(byRunningStatus.thenComparing(byStartTime)).forEach(f -> {
                String feedId = f.getFeedId().toString();
                if (!latestFeeds.containsKey(feedId)) {
                    latestFeeds.put(feedId, f);
                }/*w w w .j  ava2 s .c o  m*/
            });

    //NOTE it could also populate the last job execution time since the above query gets a union of the running jobs along with the latest finished jobs by feed
    List<FeedHealth> feedSummaryHealth = latestFeeds.values().stream()
            .map(f -> FeedModelTransform.feedHealth(f)).collect(Collectors.toList());
    return FeedModelTransform.feedStatus(feedSummaryHealth);
}

From source file:gedi.riboseq.inference.orf.OrfFinder.java

private void annotate(ImmutableReferenceGenomicRegion<Orf> r) {
    ArrayList<ImmutableReferenceGenomicRegion<Transcript>> tr = intronless.ei(r).map(i -> i.getData())
            .toCollection(new ArrayList<>());
    Comparator<ImmutableReferenceGenomicRegion<Transcript>> comp = (a, b) -> Integer
            .compare(a.getRegion().getTotalLength(), b.getRegion().getTotalLength());
    comp = comp.thenComparing((a, b) -> a.getData().getTranscriptId().compareTo(b.getData().getTranscriptId())); // just to make it stable for two different orfs
    Collections.sort(tr, comp);//from  w w  w . j  a v  a 2 s . c  o  m

    for (OrfType type : OrfType.values()) {
        for (ImmutableReferenceGenomicRegion<Transcript> t : tr) {
            if (type.is(r, t)) {
                r.getData().reference = t;
                r.getData().orfType = type;
                return;
            }
        }
    }
    r.getData().orfType = OrfType.oORF;
}

From source file:net.thirdy.blackmarket.controls.ModSelectionPane.java

@Override
public void accept(List<ItemType> itemTypes) {
    masterData.clear();/*from w w w .j a v  a  2s  .  co m*/
    List<ModMapping> modMappings = ModsMapping.getInstance().getModMappings();
    if (!itemTypes.isEmpty()) {
        List<String> itemTypesRaw = itemTypes.stream().map(itemType -> itemType.itemType())
                .collect(Collectors.toList());
        modMappings = modMappings.stream()
                .filter(mm -> mm.getModType() == ModType.PSEUDO || itemTypesRaw.contains(mm.getItemType()))
                .collect(Collectors.toList());
    }

    Comparator<ModMapping> byModType = (m1, m2) -> Integer.valueOf(m1.getModType().ordinal())
            .compareTo(Integer.valueOf(m2.getModType().ordinal()));

    Comparator<ModMapping> byModTypeThenKey = byModType
            .thenComparing((m1, m2) -> m1.getKey().compareTo(m2.getKey()));
    modMappings.sort(byModTypeThenKey);
    masterData.addAll(modMappings);
}

From source file:org.cloudsimplus.migration.VmMigrationWhenCpuMetricIsViolatedExampleWithSelectedVm.java

/**
 * Selects a VM to run a Cloudlet that will minimize the Cloudlet response
 * time.//from w  w w .  ja  v a2  s  .c om
 *
 * @param cloudlet the Cloudlet to select a VM to
 * @return the selected Vm
 */
private Vm selectVmForCloudlet(Cloudlet cloudlet) {
    List<Vm> createdVms = cloudlet.getBroker().getVmsCreatedList();
    Log.printLine("\t\tCreated VMs: " + createdVms);
    Comparator<Vm> sortByNumberOfFreePes = Comparator.comparingLong(vm -> getExpectedNumberOfFreeVmPes(vm));
    Comparator<Vm> sortByExpectedCloudletResponseTime = Comparator
            .comparingDouble(vm -> getExpectedCloudletResponseTime(cloudlet, vm));
    createdVms.sort(sortByNumberOfFreePes.thenComparing(sortByExpectedCloudletResponseTime).reversed());
    Vm mostFreePesVm = createdVms.stream().findFirst().orElse(Vm.NULL);

    Vm selectedVm = createdVms.stream()
            .filter(vm -> getExpectedNumberOfFreeVmPes(vm) >= cloudlet.getNumberOfPes())
            .filter(vm -> getExpectedCloudletResponseTime(cloudlet, vm) <= responseTimeSlaContract).findFirst()
            .orElse(mostFreePesVm);

    return selectedVm;
}

From source file:org.cloudsimplus.sla.responsetime.CloudletResponseTimeMinimizationExperiment.java

@Override
public final void printResults() {
    DatacenterBroker broker0 = getFirstBroker();
    List<Cloudlet> finishedCloudlets = broker0.getCloudletsFinishedList();
    Comparator<Cloudlet> sortByVmId = comparingDouble(c -> c.getVm().getId());
    Comparator<Cloudlet> sortByStartTime = comparingDouble(c -> c.getExecStartTime());
    finishedCloudlets.sort(sortByVmId.thenComparing(sortByStartTime));

    new CloudletsTableBuilder(finishedCloudlets).build();
}

From source file:org.cloudsimplus.sla.responsetime.CloudletResponseTimeMinimizationExperiment.java

/**
* Selects a VM to run a Cloudlet that will minimize the Cloudlet response
* time.//from w  w  w .ja  v a2 s.c o m
*
* @param cloudlet the Cloudlet to select a VM to
* @return the selected Vm
*/
private Vm selectVmForCloudlet(Cloudlet cloudlet) {
    List<Vm> createdVms = cloudlet.getBroker().getVmsCreatedList();
    Log.printLine("\t\tCreated VMs: " + createdVms);
    Comparator<Vm> sortByNumberOfFreePes = Comparator.comparingInt(vm -> getExpectedNumberOfFreeVmPes(vm));
    Comparator<Vm> sortByExpectedCloudletResponseTime = Comparator
            .comparingDouble(vm -> getExpectedCloudletResponseTime(cloudlet, vm));
    createdVms.sort(sortByNumberOfFreePes.thenComparing(sortByExpectedCloudletResponseTime).reversed());
    Vm mostFreePesVm = createdVms.stream().findFirst().orElse(Vm.NULL);

    Vm selectedVm = createdVms.stream()
            .filter(vm -> getExpectedNumberOfFreeVmPes(vm) >= cloudlet.getNumberOfPes())
            .filter(vm -> getExpectedCloudletResponseTime(cloudlet, vm) <= responseTimeSlaContract).findFirst()
            .orElse(mostFreePesVm);

    return selectedVm;
}

From source file:org.cloudsimplus.sla.responsetime.CloudletResponseTimeWorkLoadExperimet.java

/**
 * Selects a VM to run a Cloudlet that will minimize the Cloudlet response
 * time./*from ww  w  .  j  a v  a2 s .  c  o  m*/
 *
 * @param cloudlet the Cloudlet to select a VM to
 * @return the selected Vm
 */
private Vm selectVmForCloudlet(Cloudlet cloudlet) {
    List<Vm> createdVms = cloudlet.getBroker().getVmsCreatedList();
    //    Log.printLine("\t\tCreated VMs: " + createdVms);
    Comparator<Vm> sortByNumberOfFreePes = Comparator.comparingLong(vm -> getExpectedNumberOfFreeVmPes(vm));
    Comparator<Vm> sortByExpectedCloudletResponseTime = Comparator
            .comparingDouble(vm -> getExpectedCloudletResponseTime(cloudlet, vm));
    createdVms.sort(sortByNumberOfFreePes.thenComparing(sortByExpectedCloudletResponseTime).reversed());
    Vm mostFreePesVm = createdVms.stream().findFirst().orElse(Vm.NULL);

    Vm selectedVm = createdVms.stream()
            .filter(vm -> getExpectedNumberOfFreeVmPes(vm) >= cloudlet.getNumberOfPes())
            .filter(vm -> getExpectedCloudletResponseTime(cloudlet, vm) <= responseTimeSlaContract).findFirst()
            .orElse(mostFreePesVm);

    return selectedVm;
}

From source file:org.fenixedu.ulisboa.specifications.domain.evaluation.markSheet.CompetenceCourseMarkSheet.java

public SortedSet<EnrolmentEvaluation> getSortedEnrolmentEvaluations() {

    final Comparator<EnrolmentEvaluation> byStudentName = (x,
            y) -> CompetenceCourseMarkSheet.COMPARATOR_FOR_STUDENT_NAME.compare(
                    x.getRegistration().getStudent().getName(), y.getRegistration().getStudent().getName());

    final SortedSet<EnrolmentEvaluation> result = Sets
            .newTreeSet(byStudentName.thenComparing(DomainObjectUtil.COMPARATOR_BY_ID));

    result.addAll(getEnrolmentEvaluationSet());

    return result;

}