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.webtide.jetty.load.generator.jenkins.LoadGeneratorProjectAction.java
public String getAllResponseTimeInformations() throws IOException { ObjectMapper objectMapper = new ObjectMapper(); List<RunInformations> datas = new ArrayList<>(); for (Run run : this.builds) { LoadGeneratorBuildAction buildAction = run.getAction(LoadGeneratorBuildAction.class); if (buildAction != null) { if (buildAction.getGlobalResponseTimeInformations() != null) { RunInformations runInformations = new RunInformations(run.getId(), buildAction.getGlobalResponseTimeInformations()); datas.add(runInformations); }/*from w w w. j a v a2s .c o m*/ } } // order by buildId Collections.sort(datas, Comparator.comparing(RunInformations::getBuildId)); StringWriter stringWriter = new StringWriter(); objectMapper.writeValue(stringWriter, datas); return stringWriter.toString(); }
From source file:com.compomics.pepshell.view.statistics.RatioComparisonPane.java
private CategoryDataset createRatioDataset(PepshellProtein aPepshellProtein) { DefaultCategoryDataset returnset = new DefaultCategoryDataset(); PepshellProtein protein = referenceExperiment.getProteins() .get(referenceExperiment.getProteins().indexOf(aPepshellProtein)); List<PeptideGroup> sortedCopy = protein.getPeptideGroups().stream().sorted(Comparator.comparing(e -> { return 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, (Integer) 1, (Integer) aPeptide.getBeginningProteinMatch()); //returnset.addValue(((QuantedPeptide) aPeptide).getRatio(), String.valueOf(aPeptide.getBeginningProteinMatch()), String.valueOf(groupcounter)); }/* ww w.j ava2 s. c om*/ } protein = experimentToCompareTo.getProteins() .get(referenceExperiment.getProteins().indexOf(aPepshellProtein)); sortedCopy = protein.getPeptideGroups().stream() .sorted(Comparator .comparing(e -> ((PeptideGroup) 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, (Integer) aPeptide.getBeginningProteinMatch(), (Integer) 2); //returnset.addValue(((QuantedPeptide) aPeptide).getRatio(), String.valueOf(aPeptide.getBeginningProteinMatch()), String.valueOf(groupcounter)); } } return returnset; }
From source file:org.phoenicis.repository.types.ClasspathRepository.java
@Override public RepositoryDTO fetchInstallableApplications() { try {/*from w w w. jav a2 s. co m*/ final List<TypeDTO> typeDTOS = new ArrayList<>(); Resource[] resources = resourceResolver.getResources(packagePath + "/*"); for (Resource resource : resources) { final TypeDTO type = buildType(resource.getFilename()); if (!type.getCategories().isEmpty()) { typeDTOS.add(type); } } typeDTOS.sort(Comparator.comparing(TypeDTO::getName)); final RepositoryDTO.Builder repositoryDTOBuilder = new RepositoryDTO.Builder() .withName("classpath repository").withTypes(typeDTOS); return repositoryDTOBuilder.build(); } catch (IOException e) { LOGGER.warn("Error while reading resource directory", e); return new RepositoryDTO.Builder().build(); } }
From source file:io.adeptj.runtime.osgi.BundleInstaller.java
Stream<Bundle> installBundles(Stream<JarEntry> jarEntryStream, BundleContext systemBundleContext) { return jarEntryStream.map(jarEntry -> this.getClass().getClassLoader().getResource(jarEntry.getName())) .map(url -> this.installBundle(url, systemBundleContext)).filter(Objects::nonNull) .sorted(Comparator.comparing(Bundle::getBundleId)); }
From source file:com.epam.dlab.backendapi.service.impl.LibraryServiceImpl.java
@Override @SuppressWarnings("unchecked") public List<LibInfoRecord> getLibInfo(String user, String exploratoryName) { Document document = libraryDAO.findAllLibraries(user, exploratoryName); Map<LibKey, List<LibraryStatus>> model = new TreeMap<>(Comparator.comparing(LibKey::getName) .thenComparing(LibKey::getVersion).thenComparing(LibKey::getGroup)); if (document.get(ExploratoryLibDAO.EXPLORATORY_LIBS) != null) { List<Document> exploratoryLibs = (List<Document>) document.get(ExploratoryLibDAO.EXPLORATORY_LIBS); exploratoryLibs.forEach(e -> populateModel(exploratoryName, e, model, "notebook")); }/* w ww . j av a2 s .co m*/ if (document.get(ExploratoryLibDAO.COMPUTATIONAL_LIBS) != null) { Document computationalLibs = getLibsOfActiveComputationalResources(document); populateComputational(computationalLibs, model, "cluster"); } List<LibInfoRecord> libInfoRecords = new ArrayList<>(); for (Map.Entry<LibKey, List<LibraryStatus>> entry : model.entrySet()) { libInfoRecords.add(new LibInfoRecord(entry.getKey(), entry.getValue())); } return libInfoRecords; }
From source file:nc.noumea.mairie.appock.services.impl.ServiceServiceImpl.java
@Override public List<Service> findAllWithActifInactifOrderByLibelle(boolean avecNull) { List<Service> result = serviceRepository.findAllByOrderByLibelle(); List<Service> listeServiceActif = new ArrayList<>(); List<Service> listeServiceInactif = new ArrayList<>(); for (Service service : result) { chargeLazy(service);/* w ww.j a v a2 s .c om*/ if (service.isActif()) { listeServiceActif.add(service); } else { listeServiceInactif.add(service); } } result.clear(); Comparator serviceComparator = Comparator .comparing((Service service) -> service.getDirection().getPole().getLibelle()) .thenComparing(service -> service.getDirection().getLibelleCourt()) .thenComparing(service -> service.getLibelleCourt()); Collections.sort(listeServiceActif, serviceComparator); Collections.sort(listeServiceInactif, serviceComparator); result.addAll(listeServiceActif); result.addAll(listeServiceInactif); if (avecNull) { result.add(0, null); } return result; }
From source file:alfio.util.EventUtil.java
private static Optional<SaleableTicketCategory> findFirstCategory(List<SaleableTicketCategory> categories) { return sortCategories(categories, Comparator.comparing(SaleableTicketCategory::getUtcExpiration)) .findFirst();/*from w w w .j a v a 2 s. c om*/ }
From source file:org.fao.geonet.MergeUsersByUsernameDatabaseMigration.java
private void mergeUsers(ApplicationContext applicationContext, String duplicatedUsername) throws Exception { UserRepository userRepository = applicationContext.getBean(UserRepository.class); List<User> duplicatedUserList = userRepository.findByUsernameIgnoreCase(duplicatedUsername); duplicatedUserList.sort(Comparator.comparing(User::getProfile)); User greatestProfileUser = duplicatedUserList.get(0); User userToKeep = userRepository.findOne(greatestProfileUser.getId()); Set<String> emails = new HashSet<>(); Set<Address> addresses = new HashSet<>(); mergeGroups(applicationContext, duplicatedUserList, userToKeep); transferMetadata(applicationContext, duplicatedUserList, userToKeep); transferSavedSelections(applicationContext, duplicatedUserList, userToKeep); User tempUser = new User(); for (int i = duplicatedUserList.size() - 1; i >= 0; i--) { // i = 1 is intended User duplicatedUser = duplicatedUserList.get(i); addresses.addAll(duplicatedUser.getAddresses()); mergeUser(tempUser, duplicatedUser); emails.addAll(duplicatedUser.getEmailAddresses()); }//from w w w .ja v a 2 s. c o m mergeUser(userToKeep, tempUser); duplicatedUserList.remove(greatestProfileUser); userRepository.delete(duplicatedUserList); userToKeep.setUsername(userToKeep.getUsername().toLowerCase()); userRepository.save(userToKeep); }
From source file:org.apache.lens.cube.parse.TestCubeSegmentationRewriter.java
private static void compareUnionQuery(CubeQueryContext cubeql, String begin, String end, List<String> queries) throws LensException { final String actualLower = cubeql.toHQL().toLowerCase(); queries.sort(Comparator.comparing(s -> actualLower.indexOf(extractTableName(s)))); String expected = queries.stream().collect(Collectors.joining(" UNION ALL ", begin, end)); compareQueries(actualLower, expected); }
From source file:org.wildfly.swarm.proc.FailFastComparator.java
@Override public void compare(List<CSVRecord> previous, List<CSVRecord> current) throws ThresholdExceeded { List<ComparisonResult> comparisonResults = new ArrayList<>(); int maxChars = 0; for (CSVRecord prevRecord : previous) { String fileName = prevRecord.get(CSVCollector.SHORT_FILE_NAME_COLUMN); if (fileName.length() > maxChars) maxChars = fileName.length(); CSVRecord matching = findMatching(fileName, current); if (matching != null) { for (Measure measure : criteria) { double prevVal = Double.valueOf(prevRecord.get(measure.column75Percentile())); double currVal = Double.valueOf(matching.get(measure.column75Percentile())); if (currVal > prevVal) { double increasePercentage = currVal * 100 / prevVal; boolean failed = increasePercentage - threshold > 100; String message = StringUtils.rightPad(measure.getShortName(), 10) + " +" + Math.floor(increasePercentage - 100) + "% (" + prevVal + " -> " + currVal + ")"; comparisonResults.add(new ComparisonResult(measure, fileName, failed, message)); } else { double decreasePercentage = prevVal * 100 / currVal; String message = StringUtils.rightPad(measure.getShortName(), 10) + " -" + Math.floor(decreasePercentage - 100) + "% (" + prevVal + " -> " + currVal + ")"; comparisonResults.add(new ComparisonResult(measure, fileName, message)); }//from w ww .j a va2s . co m } } else { System.err.println("No matching record for test " + fileName + ". Skipping ..."); } } // dump results final int pad = maxChars + 2; Collections.sort(comparisonResults, Comparator.comparing(ComparisonResult::getMeasure)); comparisonResults .forEach(r -> System.out.println(StringUtils.rightPad(r.getFile(), pad) + ": " + r.getMessage())); // decide if ThresholdExceeded List<ComparisonResult> failedTests = comparisonResults.stream().filter(r -> !r.isFailure()) .collect(Collectors.toList()); if (failedTests.size() > 0) { System.err.println("There have been test errors. See previous logs for details ..."); throw new ThresholdExceeded( failedTests.size() + " test(s) did exceed the " + this.threshold + "% tolerance."); } }