List of usage examples for java.util Comparator comparingLong
public static <T> Comparator<T> comparingLong(ToLongFunction<? super T> keyExtractor)
From source file:org.cloudsimplus.sla.responsetime.CloudletResponseTimeWorkLoadExperimet.java
/** * Selects a VM to run a Cloudlet that will minimize the Cloudlet response * time./*from w w w .ja v a 2 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.codice.ddf.test.common.KarafContainerFailureLogger.java
private Optional<Path> getLatestExamFolder() { try (Stream<Path> files = Files.list(EXAM_DIR)) { return files.filter(Files::isDirectory).max(Comparator.comparingLong(p -> p.toFile().lastModified())); } catch (IOException e) { LOGGER.error("No exam directory under {}", EXAM_DIR.toAbsolutePath()); return Optional.empty(); }/* w w w. j a v a 2s . co m*/ }
From source file:org.hyperledger.fabric.sdk.ServiceDiscovery.java
private static List<SDEndorser> topNbyHeight(int required, List<SDEndorser> endorsers) { ArrayList<SDEndorser> ret = new ArrayList<>(endorsers); ret.sort(Comparator.comparingLong(SDEndorser::getLedgerHeight)); return ret.subList(Math.max(ret.size() - required, 0), ret.size()); }
From source file:org.sakaiproject.poll.logic.impl.PollOrderOptionBackFillJob.java
/** * This is the method that is fired when the job is 'triggered'. * * @param jobExecutionContext - the context of the job execution * @throws JobExecutionException// w w w . jav a 2s. c o m */ @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { log.info("Attempting to back-fill all existing Poll option orders..."); int modifiedCount = 0; // Iterate over sites in the system, ordered by creation date... List<Site> sites = siteService.getSites(SelectionType.ANY, null, null, null, SortType.CREATED_ON_DESC, null); if (!CollectionUtils.isEmpty(sites)) { for (Site site : sites) { String siteID = site.getId(); List<Poll> pollsForSite = pollService.findAllPolls(siteID); if (!CollectionUtils.isEmpty(pollsForSite)) { // Iterate over the polls for the site... for (Poll poll : pollsForSite) { try { // Iterate over Options in the poll... securityService.pushAdvisor(YES_MAN); List<Option> pollOptions = pollService.getOptionsForPoll(poll); if (!CollectionUtils.isEmpty(pollOptions)) { // Check if any options have a null order boolean hasNullOptionOrder = false; for (Option option : pollOptions) { if (option.getOptionOrder() == null) { hasNullOptionOrder = true; break; } } // If any of the option's order is null, we need to back-fill them if (hasNullOptionOrder) { log.info("Poll ID {} has options with null order, processing...", poll.getId()); // Order the list by ID pollOptions.sort(Comparator.comparingLong(Option::getOptionId)); // Iterate over the list for (int i = 0; i < pollOptions.size(); i++) { // Add order based on ID Option option = pollOptions.get(i); option.setOptionOrder(i); pollService.saveOption(option); modifiedCount++; log.info("Option {} ---> new order == {}", option.getId(), i); } } } } catch (Exception ex) { log.error("Unexcepted exception", ex); } finally { securityService.popAdvisor(YES_MAN); } } } } } log.info("Processing finished, modified {} poll options", modifiedCount); }