List of usage examples for java.util Comparator comparing
public static <T, U extends Comparable<? super U>> Comparator<T> comparing( Function<? super T, ? extends U> keyExtractor)
From source file:com.thoughtworks.go.server.service.lookups.CommandSnippets.java
private List<CommandSnippet> sortByName(List<CommandSnippet> snippets) { List<CommandSnippet> snippetsSortedByName = new ArrayList<>(snippets); snippetsSortedByName.sort(Comparator.comparing(CommandSnippet::getName)); return snippetsSortedByName; }
From source file:org.apache.asterix.common.config.ConfigUsageTest.java
protected Set<Section> getSections(ConfigManager configManager) { TreeSet<Section> sections = new TreeSet<>(Comparator.comparing(Section::sectionName)); sections.addAll(configManager.getSections()); sections.remove(Section.LOCALNC);/*from ww w . ja v a 2s . c om*/ return sections; }
From source file:com.uber.hoodie.common.table.timeline.HoodieActiveTimeline.java
protected HoodieActiveTimeline(FileSystem fs, String metaPath, String[] includedExtensions) { // Filter all the filter in the metapath and include only the extensions passed and // convert them into HoodieInstant try {/*w ww . j av a 2s . c o m*/ this.instants = Arrays.stream(HoodieTableMetaClient.scanFiles(fs, new Path(metaPath), path -> { // Include only the meta files with extensions that needs to be included String extension = FSUtils.getFileExtension(path.getName()); return Arrays.stream(includedExtensions).anyMatch(Predicate.isEqual(extension)); })).sorted(Comparator.comparing( // Sort the meta-data by the instant time (first part of the file name) fileStatus -> FSUtils.getInstantTime(fileStatus.getPath().getName()))) // create HoodieInstantMarkers from FileStatus, which extracts properties .map(HoodieInstant::new).collect(Collectors.toList()); log.info("Loaded instants " + instants); } catch (IOException e) { throw new HoodieIOException("Failed to scan metadata", e); } this.fs = fs; this.metaPath = metaPath; // multiple casts will make this lambda serializable - http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.16 this.details = (Function<HoodieInstant, Optional<byte[]>> & Serializable) this::getInstantDetails; }
From source file:com.compomics.pepshell.view.statistics.RatioStatisticsPane.java
private CategoryDataset createRatioDataset(PepshellProtein aPepshellProtein) { DefaultCategoryDataset returnset = new DefaultCategoryDataset(); //PepshellProtein protein = experimentGroup.get(0).getProteins().get(experimentGroup.get(0).getProteins().indexOf(aPepshellProtein)); if (aPepshellProtein != null) { for (Experiment anExperiment : experimentGroup) { if (anExperiment.getProteins().indexOf(aPepshellProtein) != -1) { PepshellProtein protein = anExperiment.getProteins() .get(anExperiment.getProteins().indexOf(aPepshellProtein)); List<PeptideGroup> sortedCopy = protein.getPeptideGroups().stream() .sorted(Comparator .comparing(e -> e.getRepresentativePeptide().getBeginningProteinMatch())) .collect(Collectors.toList()); for (PeptideGroup aPeptideGroup : sortedCopy) { PeptideInterface aPeptide = aPeptideGroup.getRepresentativePeptide(); if (aPeptide instanceof QuantedPeptide && ((QuantedPeptide) aPeptide).getRatio() != null) { Double value = Math.log(((QuantedPeptide) aPeptide).getRatio()) / Math.log(2); returnset.addValue(value, anExperiment.getExperimentName(), String.valueOf(aPeptide.getBeginningProteinMatch())); //this part can be put in it's own method for (Experiment checkList : experimentGroup) { if (!checkList.equals(anExperiment) && returnset.getRowKeys().contains(checkList.getExperimentName())) { if (returnset.getValue(checkList.getExperimentName(), String.valueOf(aPeptide.getBeginningProteinMatch())) == null) { returnset.addValue(null, checkList.getExperimentName(), String.valueOf(aPeptide.getBeginningProteinMatch())); }/* w w w. ja v a2s . c om*/ } } } } } } } return returnset; }
From source file:org.niord.web.DictionaryRestService.java
/** Exports the dictionary as a text file */ @GET/*from w ww . java2s . c o m*/ @Path("/dictionary/{name}_{lang}.properties") @Produces("text/plain;charset=UTF-8") @GZIP @NoCache public String getDictionaryEntries(@PathParam("name") String name, @PathParam("lang") String lang) { DictionaryVo dict = dictionaryService.getCachedDictionary(name); if (dict == null) { throw new WebApplicationException(404); } StringBuilder result = new StringBuilder(); dict.getEntries().values().stream().filter(e -> e.getDesc(lang) != null && e.getDesc(lang).descDefined()) .sorted(Comparator.comparing(e2 -> e2.getKey().toLowerCase())) .forEach(entry -> result.append(entry.getKey()).append(" = ") .append(encodeValue(entry.getDesc(lang).getValue())).append("\n")); return result.toString(); }
From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.view.provider.KubernetesV2ManifestProvider.java
@Override public KubernetesV2Manifest getManifest(String account, String location, String name) { Pair<KubernetesKind, String> parsedName; try {/*from w ww . j a v a 2 s .co m*/ parsedName = KubernetesManifest.fromFullResourceName(name); } catch (Exception e) { return null; } KubernetesKind kind = parsedName.getLeft(); String key = Keys.infrastructure(kind, account, location, parsedName.getRight()); Optional<CacheData> dataOptional = cacheUtils.getSingleEntry(kind.toString(), key); if (!dataOptional.isPresent()) { return null; } CacheData data = dataOptional.get(); KubernetesResourceProperties properties = registry.get(account, kind); if (properties == null) { return null; } Function<KubernetesManifest, String> lastEventTimestamp = ( m) -> (String) m.getOrDefault("lastTimestamp", m.getOrDefault("firstTimestamp", "n/a")); List<KubernetesManifest> events = cacheUtils .getTransitiveRelationship(kind.toString(), Collections.singletonList(key), KubernetesKind.EVENT.toString()) .stream().map(KubernetesCacheDataConverter::getManifest) .sorted(Comparator.comparing(lastEventTimestamp)).collect(Collectors.toList()); KubernetesHandler handler = properties.getHandler(); KubernetesManifest manifest = KubernetesCacheDataConverter.getManifest(data); Moniker moniker = KubernetesCacheDataConverter.getMoniker(data); return new KubernetesV2Manifest().builder().account(account).location(location).manifest(manifest) .moniker(moniker).status(handler.status(manifest)).artifacts(handler.listArtifacts(manifest)) .events(events).build(); }
From source file:org.matsim.contrib.drt.routing.ClosestAccessEgressStopFinder.java
private TransitStopFacility findClosestStop(Facility<?> facility) { Coord coord = StopBasedDrtRoutingModule.getFacilityCoord(facility, network); TransitStopFacility closest = stops.values().stream()// .max(Comparator.comparing(s -> DistanceUtils.calculateSquaredDistance(coord, s.getCoord())))// .orElse(null);// w ww .j a v a 2 s . c o m if (closest != null && walkBeelineFactor * DistanceUtils.calculateDistance(coord, closest.getCoord()) <= maxWalkDistance) { return closest; } else { return null; } }
From source file:org.springframework.cloud.stream.app.object.detection.processor.ObjectDetectionTensorflowOutputConverter.java
/** * Loads object labels in the string_int_label_map.proto * @param labelsResource/*w w w. j a v a2 s . c om*/ * @return * @throws Exception */ private static String[] loadLabels(Resource labelsResource) throws Exception { try (InputStream is = labelsResource.getInputStream()) { String text = StreamUtils.copyToString(is, Charset.forName("UTF-8")); StringIntLabelMapOuterClass.StringIntLabelMap.Builder builder = StringIntLabelMapOuterClass.StringIntLabelMap .newBuilder(); TextFormat.merge(text, builder); StringIntLabelMapOuterClass.StringIntLabelMap proto = builder.build(); int maxLabelId = proto.getItemList().stream() .map(StringIntLabelMapOuterClass.StringIntLabelMapItem::getId).max(Comparator.comparing(i -> i)) .orElse(-1); String[] labelIdToNameMap = new String[maxLabelId + 1]; for (StringIntLabelMapOuterClass.StringIntLabelMapItem item : proto.getItemList()) { if (!StringUtils.isEmpty(item.getDisplayName())) { labelIdToNameMap[item.getId()] = item.getDisplayName(); } else { // Common practice is to set the name to a MID or Synsets Id. Synset is a set of synonyms that // share a common meaning: https://en.wikipedia.org/wiki/WordNet labelIdToNameMap[item.getId()] = item.getName(); } } return labelIdToNameMap; } }
From source file:com.epam.dlab.billing.azure.AzureBillableResourcesService.java
/** * Collects billable resources//from www . j av a 2s .c o m * * @return set of all billable resources that were created in scope by DLab from its installation to current time */ public Set<AzureDlabBillableResource> getBillableResources() { Set<AzureDlabBillableResource> billableResources = new HashSet<>(); billableResources.addAll(getSsn()); billableResources.addAll(getDataLake()); billableResources.addAll(getEdgeAndStorageAccount()); billableResources.addAll(getNotebooksAndClusters()); List<AzureDlabBillableResource> list = new ArrayList<>(billableResources); list.sort(Comparator.comparing(AzureDlabBillableResource::getId)); try { log.debug("Billable resources is \n {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(list)); } catch (JsonProcessingException e) { log.debug("Error during pretty printing. Show simple list", e); log.debug("Billable resources is {}", list); } return billableResources; }
From source file:org.opennms.smoketest.topo.GraphMLTopologyIT.java
@Test public void canUseTopology() throws IOException { topologyUIPage.selectTopologyProvider(() -> LABEL); topologyUIPage.defaultFocus();//from w w w . j av a 2 s . com List<TopologyIT.FocusedVertex> focusedVertices = topologyUIPage.getFocusedVertices(); assertEquals(4, focusedVertices.size()); assertEquals(4, topologyUIPage.getVisibleVertices().size()); assertEquals(1, topologyUIPage.getSzl()); focusedVertices.sort(Comparator.comparing(TopologyIT.FocusedVertex::getNamespace) .thenComparing(TopologyIT.FocusedVertex::getLabel)); assertEquals(Lists.newArrayList(focusVertex(topologyUIPage, "Acme:regions:", "East Region"), focusVertex(topologyUIPage, "Acme:regions:", "North Region"), focusVertex(topologyUIPage, "Acme:regions:", "South Region"), focusVertex(topologyUIPage, "Acme:regions:", "West Region")), focusedVertices); // Search for and select a region final String regionName = "South"; TopologyIT.TopologyUISearchResults searchResult = topologyUIPage.search(regionName); assertEquals(5, searchResult.countItemsThatContain(regionName)); searchResult.selectItemThatContains("South Region"); // Focus should not have changed assertEquals(4, focusedVertices.size()); assertEquals(4, topologyUIPage.getVisibleVertices().size()); // Verify that the layout is the D3 Layout as this layer does not provide a preferredLayout assertEquals(Layout.D3, topologyUIPage.getSelectedLayout()); // Switch Layer topologyUIPage.selectLayer("Markets"); assertEquals(0, topologyUIPage.getSzl()); assertEquals(1, topologyUIPage.getFocusedVertices().size()); assertEquals("North 4", topologyUIPage.getFocusedVertices().get(0).getLabel()); }