List of usage examples for java.util List sort
@SuppressWarnings({ "unchecked", "rawtypes" }) default void sort(Comparator<? super E> c)
From source file:no.asgari.civilization.server.action.PlayerAction.java
/** * Returns the remaining techs the player can choose from * * @param playerId - The player//w ww. j ava 2 s . c o m * @param pbfId - The PBF * @return */ public List<Tech> getRemaingTechsForPlayer(String playerId, String pbfId) { PBF pbf = pbfCollection.findOneById(pbfId); Optional<Playerhand> playerhandOptional = pbf.getPlayers().stream() .filter(p -> p.getPlayerId().equals(playerId)).findFirst(); Set<Tech> techsChosen = playerhandOptional.orElseThrow(PlayerAction::cannotFindPlayer).getTechsChosen(); Playerhand playerhand = playerhandOptional.get(); if (playerhand.getCivilization() != null && playerhand.getCivilization().getStartingTech() != null) { techsChosen.add(playerhandOptional.get().getCivilization().getStartingTech()); } List<Tech> techs = pbf.getTechs(); techs.removeAll(techsChosen); techs.sort(((o1, o2) -> Integer.valueOf(o1.getLevel()).compareTo(o2.getLevel()))); return techs; }
From source file:com.evolveum.midpoint.wf.impl.processors.primary.policy.ApprovalSchemaBuilder.java
private List<ApprovalStageDefinitionType> cloneAndMergeStages(List<Fragment> fragments) throws SchemaException { if (fragments.size() == 1) { return CloneUtil.cloneCollectionMembers(getStages(fragments.get(0).schema)); }// ww w .j a v a 2s . co m PrismContext prismContext = primaryChangeAspect.getChangeProcessor().getPrismContext(); ApprovalStageDefinitionType resultingStageDef = new ApprovalStageDefinitionType(prismContext); fragments.sort((f1, f2) -> Comparator.nullsLast(Comparator.<Integer>naturalOrder()) .compare(f1.compositionStrategy.getMergePriority(), f2.compositionStrategy.getMergePriority())); for (Fragment fragment : fragments) { mergeStageDefFromFragment(resultingStageDef, fragment); } return Collections.singletonList(resultingStageDef); }
From source file:org.cloudsimplus.migration.VmMigrationWhenCpuMetricIsViolatedExampleWithSelectedVm.java
/** * Selects a VM to run a Cloudlet that will minimize the Cloudlet response * time.// ww 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.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:io.github.swagger2markup.internal.component.PathOperationComponent.java
private void buildTagsSection(MarkupDocBuilder markupDocBuilder, PathOperation operation) { if (config.getPathsGroupedBy() == GroupBy.AS_IS) { List<String> tags = operation.getOperation().getTags(); if (CollectionUtils.isNotEmpty(tags)) { buildSectionTitle(markupDocBuilder, labels.getLabel(TAGS)); if (config.getTagOrdering() != null) { tags.sort(config.getTagOrdering()); }/*from w w w .j a v a2s. co m*/ markupDocBuilder.unorderedList(tags); } } }
From source file:org.openlmis.fulfillment.web.BaseController.java
private List<Change> getChanges(Map<UUID, Class> pairs, String author, String changedPropertyName, Pageable page) {// w w w. j a v a 2 s. c o m List<Change> changes = Lists.newArrayList(); for (Entry<UUID, Class> pair : pairs.entrySet()) { QueryBuilder queryBuilder = QueryBuilder.byInstanceId(pair.getKey(), pair.getValue()) .withNewObjectChanges(); if (StringUtils.isNotBlank(author)) { queryBuilder = queryBuilder.byAuthor(author); } if (StringUtils.isNotBlank(changedPropertyName)) { queryBuilder = queryBuilder.andProperty(changedPropertyName); } changes.addAll(javers.findChanges(queryBuilder.build())); } changes.sort(comparing((Change change) -> change.getCommitMetadata().get().getCommitDate()).reversed()); return Pagination.getPage(changes, page).getContent(); }
From source file:com.ggvaidya.scinames.ui.DatasetDiffController.java
private Function<DatasetRow, String> getByUniqueMap() { DatasetColumn colByEqual = byUniqueComboBox.getValue(); if (colByEqual.equals(DATASET_COLUMN_ALL)) { return row -> row.toString(); } else if (colByEqual.equals(DATASET_COLUMN_NAME_ONLY)) { // Note that this will combine rows that have identical names, which is not // what we want. return row -> row.getDataset().getNamesInRow(row).toString(); } else if (colByEqual.equals(DATASET_COLUMN_BINOMIAL_NAME_CLUSTER)) { return row -> { Project project = datasetDiffView.getProjectView().getProject(); NameClusterManager ncm = project.getNameClusterManager(); List<Name> binomialNames = row.getDataset().getNamesInRow(row).stream().flatMap(n -> n.asBinomial()) .collect(Collectors.toList()); List<NameCluster> nameClusters = ncm.getClusters(binomialNames); nameClusters.sort(null); return nameClusters.toString(); };//from www. j av a 2 s .c om } else if (colByEqual.equals(DATASET_COLUMN_NAME_SPECIFIC_EPITHET)) { return row -> row.getDataset().getNamesInRow(row).stream().map(n -> n.getSpecificEpithet()) .collect(Collectors.toSet()).toString(); } else { return row -> row.get(colByEqual); } }
From source file:com.navercorp.pinpoint.common.server.bo.thrift.SpanFactory.java
private List<SpanEventBo> buildSpanEventBoList(List<TSpanEvent> spanEventList) { if (CollectionUtils.isEmpty(spanEventList)) { return new ArrayList<>(); }/*from ww w .j ava2s . c o m*/ List<SpanEventBo> spanEventBoList = new ArrayList<>(spanEventList.size()); for (TSpanEvent tSpanEvent : spanEventList) { final SpanEventBo spanEventBo = buildSpanEventBo(tSpanEvent); if (!spanEventFilter.filter(spanEventBo)) { continue; } spanEventBoList.add(spanEventBo); } spanEventBoList.sort(SpanEventComparator.INSTANCE); return spanEventBoList; }
From source file:com.netflix.spinnaker.halyard.cli.command.v1.NestableCommand.java
protected void showHelp() { AnsiStoryBuilder story = new AnsiStoryBuilder(); int indentWidth = 2; AnsiParagraphBuilder paragraph = story.addParagraph(); paragraph.addSnippet(getCommandName().toUpperCase()).addStyle(AnsiStyle.BOLD); story.addNewline();// www. j a va 2s. c o m paragraph = story.addParagraph().setIndentWidth(indentWidth); String longDescription = getLongDescription() != null ? getLongDescription() : getDescription(); paragraph.addSnippet(longDescription); story.addNewline(); String usage = fullCommandName; if (!commander.getParameters().isEmpty()) { usage += " [parameters]"; } if (!subcommands.isEmpty()) { usage += " [subcommands]"; } paragraph = story.addParagraph(); paragraph.addSnippet("USAGE").addStyle(AnsiStyle.BOLD); story.addNewline(); paragraph = story.addParagraph().setIndentWidth(indentWidth); paragraph.addSnippet(usage); story.addNewline(); List<ParameterDescription> parameters = commander.getParameters(); parameters.sort(Comparator.comparing(ParameterDescription::getNames)); int parameterCount = 0; if (!parameters.isEmpty()) { paragraph = story.addParagraph(); paragraph.addSnippet("GLOBAL PARAMETERS").addStyle(AnsiStyle.BOLD); story.addNewline(); for (ParameterDescription parameter : parameters) { if (GlobalOptions.isGlobalOption(parameter.getLongestName())) { formatParameter(story, parameter, indentWidth); parameterCount++; } } } if (parameters.size() > parameterCount) { paragraph = story.addParagraph(); paragraph.addSnippet("PARAMETERS").addStyle(AnsiStyle.BOLD); story.addNewline(); ParameterDescription mainParameter = commander.getMainParameter(); if (mainParameter != null) { paragraph = story.addParagraph().setIndentWidth(indentWidth); paragraph.addSnippet(getMainParameter().toUpperCase()).addStyle(AnsiStyle.UNDERLINE); paragraph = story.addParagraph().setIndentWidth(indentWidth * 2); paragraph.addSnippet(mainParameter.getDescription()); story.addNewline(); } for (ParameterDescription parameter : parameters) { if (!GlobalOptions.isGlobalOption(parameter.getLongestName())) { formatParameter(story, parameter, indentWidth); } } } if (!subcommands.isEmpty()) { int maxLen = -1; for (String key : subcommands.keySet()) { if (key.length() > maxLen) { maxLen = key.length(); } } paragraph = story.addParagraph(); paragraph.addSnippet("SUBCOMMANDS").addStyle(AnsiStyle.BOLD); story.addNewline(); List<String> keys = new ArrayList<>(subcommands.keySet()); keys.sort(String::compareTo); for (String key : keys) { paragraph = story.addParagraph().setIndentWidth(indentWidth); paragraph.addSnippet(key).addStyle(AnsiStyle.BOLD); NestableCommand subcommand = subcommands.get(key); if (subcommand instanceof DeprecatedCommand) { paragraph.addSnippet(" "); paragraph.addSnippet("(Deprecated)").addStyle(AnsiStyle.UNDERLINE); } paragraph = story.addParagraph().setIndentWidth(indentWidth * 2); String shortDescription = subcommand.getShortDescription() != null ? subcommand.getShortDescription() : subcommand.getDescription(); paragraph.addSnippet(shortDescription); story.addNewline(); } } AnsiPrinter.out.println(story.toString()); }
From source file:com.rcv.ResultsWriter.java
private List<String> sortCandidatesByTally(Map<String, BigDecimal> tally) { // entries will contain all the input tally entries in sorted order List<Map.Entry<String, BigDecimal>> entries = new ArrayList<>(tally.entrySet()); // anonymous custom comparator will sort undeclared write in candidates to last place entries.sort((firstObject, secondObject) -> { // result of the comparison int ret;/*ww w.j ava2 s. c o m*/ if (firstObject.getKey().equals(config.getUndeclaredWriteInLabel())) { ret = 1; } else if (secondObject.getKey().equals(config.getUndeclaredWriteInLabel())) { ret = -1; } else { ret = (secondObject.getValue()).compareTo(firstObject.getValue()); } return ret; }); // container list for the final results List<String> sortedCandidates = new LinkedList<>(); // index over all entries for (Map.Entry<String, BigDecimal> entry : entries) { sortedCandidates.add(entry.getKey()); } return sortedCandidates; }
From source file:org.cloudsimplus.sla.responsetime.CloudletResponseTimeWorkLoadExperimet.java
/** * Selects a VM to run a Cloudlet that will minimize the Cloudlet response * time./*from www . j a va 2 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; }