List of usage examples for java.util List sort
@SuppressWarnings({ "unchecked", "rawtypes" }) default void sort(Comparator<? super E> c)
From source file:cc.kave.commons.pointsto.evaluation.runners.ProjectStoreRunner.java
private static void methodPropabilities(Collection<ICoReTypeName> types, ProjectUsageStore store) throws IOException { ICoReTypeName stringType = Iterables.find(types, t -> t.getClassName().equals("String")); Map<ICoReMethodName, Integer> methods = new HashMap<>(); for (Usage usage : store.load(stringType)) { for (CallSite cs : usage.getReceiverCallsites()) { Integer currentCount = methods.getOrDefault(cs.getMethod(), 0); methods.put(cs.getMethod(), currentCount + 1); }//w w w. j av a 2 s .c o m } double total = methods.values().stream().mapToInt(i -> i).sum(); List<Map.Entry<ICoReMethodName, Integer>> methodEntries = new ArrayList<>(methods.entrySet()); methodEntries .sort(Comparator.<Map.Entry<ICoReMethodName, Integer>>comparingInt(e -> e.getValue()).reversed()); double mrr = 0; double rank = 1.0; for (Map.Entry<ICoReMethodName, Integer> method : methodEntries) { double probability = method.getValue() / total; mrr += probability * (1.0 / rank); ++rank; System.out.printf(Locale.US, "%s\t%.3f\n", method.getKey().getName(), probability); } System.out.println(mrr); }
From source file:aiai.ai.launchpad.experiment.ExperimentUtils.java
public static void sortExperimentSnippets(List<ExperimentSnippet> experimentSnippets) { experimentSnippets.sort((o1, o2) -> { if (o1.getType().equals(o2.getType())) return 0; return "fit".equals(o1.getType().toLowerCase()) ? 1 : -1; });//from w ww .j av a 2 s .c om }
From source file:clientapi.util.ClientAPIUtils.java
/** * Gets the categories that are represented by a manager containing modules. * * @param sort Whether or not to sort alphabetically * @return The categories/*w ww .j a va 2 s .co m*/ */ public static Collection<Class<?>> getCategories(Manager<Module> moduleManager, boolean sort) { LinkedHashSet<Class<?>> categories = new LinkedHashSet<>(); moduleManager.stream().map(Module::getType).forEach(categories::add); if (sort) { List<Class<?>> sorted = new ArrayList<>(categories); sorted.sort((c1, c2) -> String.CASE_INSENSITIVE_ORDER.compare(c1.getAnnotation(Category.class).name(), c2.getAnnotation(Category.class).name())); return sorted; } return categories; }
From source file:org.talend.dataprep.api.dataset.row.RowMetadataUtils.java
/** * In case of a date column, return the most used pattern. * * @param column the column to inspect.// w ww . ja v a2 s. c o m * @return the most used pattern or null if there's none. */ public static String getMostUsedDatePattern(ColumnMetadata column) { // only filter out non date columns if (Type.get(column.getType()) != Type.DATE) { return null; } final List<PatternFrequency> patternFrequencies = column.getStatistics().getPatternFrequencies(); if (!patternFrequencies.isEmpty()) { patternFrequencies.sort((p1, p2) -> Long.compare(p2.getOccurrences(), p1.getOccurrences())); return patternFrequencies.get(0).getPattern(); } return null; }
From source file:org.jasig.portlet.notice.util.sort.Sorting.java
public static List<NotificationEntry> sort(HttpServletRequest req, List<NotificationEntry> entries) { final Comparator<NotificationEntry> comparator = chooseConfiguredComparator(req); if (comparator == null) { // No sorting; we're done... return entries; }//from w w w. j ava 2 s . c o m final List<NotificationEntry> rslt = new ArrayList<>(entries); // defensive copy rslt.sort(comparator); return rslt; }
From source file:com.act.biointerpretation.sarinference.ProductScorer.java
/** * Reads in scored SARs, checks them against a prediction corpus and positive inchi list to get a product ranking. * This method is static because it does not rely on any properties of the enclosing class to construct the job. * TODO: It would probably make more sense to make this its own class, i.e. <ProductScorer implements JavaRunnable> * TODO: improve the data structure used to store scored products- using an L2PredictionCorpus is pretty ugly * * @param predictionCorpus The prediction corpus to score. * @param scoredSars The scored SARs to use. * @param lcmsFile The set of positive LCMS inchis, to use in scoring. * @return A JavaRunnable to run the product scoring. *//* ww w .j av a 2s.c o m*/ public static JavaRunnable getProductScorer(File predictionCorpus, File scoredSars, File lcmsFile, File outputFile) { return new JavaRunnable() { @Override public void run() throws IOException { // Verify files FileChecker.verifyInputFile(predictionCorpus); FileChecker.verifyInputFile(scoredSars); FileChecker.verifyInputFile(lcmsFile); FileChecker.verifyAndCreateOutputFile(outputFile); // Build SAR node list and best sar finder SarTreeNodeList nodeList = new SarTreeNodeList(); nodeList.loadFromFile(scoredSars); BestSarFinder sarFinder = new BestSarFinder(nodeList); // Build prediction corpus L2PredictionCorpus predictions = L2PredictionCorpus.readPredictionsFromJsonFile(predictionCorpus); // Build LCMS results IonAnalysisInterchangeModel lcmsResults = new IonAnalysisInterchangeModel(); lcmsResults.loadResultsFromFile(lcmsFile); /** * Build map from predictions to their scores based on SAR * For each prediction, we add on auxiliary info about its SARs and score to its projector name. * TODO: build data structure to store a scored prediction, instead of hijacking the projector name. */ Map<L2Prediction, Double> predictionToScoreMap = new HashMap<>(); LOGGER.info("Scoring predictions."); for (L2Prediction prediction : predictions.getCorpus()) { String nameAppendage = lcmsResults.getLcmsDataForPrediction(prediction).toString(); // Always tack LCMS result onto name Optional<SarTreeNode> maybeBestSar = sarFinder.apply(prediction); if (maybeBestSar.isPresent()) { // If a SAR was matched, add info about it to the projector name, and put its score into the map SarTreeNode bestSar = maybeBestSar.get(); nameAppendage += ":" + bestSar.getHierarchyId() + ":" + bestSar.getRankingScore(); prediction.setProjectorName(prediction.getProjectorName() + nameAppendage); predictionToScoreMap.put(prediction, bestSar.getRankingScore()); } else { // If no SAR is found, append "NO_SAR" to the prediction, and give it a ranking score of 0 nameAppendage += "NO_SAR"; prediction.setProjectorName(prediction.getProjectorName() + nameAppendage); predictionToScoreMap.put(prediction, 0D); } } LOGGER.info("Sorting predictions in decreasing order of best associated SAR rank."); List<L2Prediction> predictionList = new ArrayList<>(predictionToScoreMap.keySet()); predictionList .sort((a, b) -> -Double.compare(predictionToScoreMap.get(a), predictionToScoreMap.get(b))); // Wrap results in a corpus and write to file. L2PredictionCorpus finalCorpus = new L2PredictionCorpus(predictionList); finalCorpus.writePredictionsToJsonFile(outputFile); LOGGER.info("Complete!."); } @Override public String toString() { return "ProductScorer:" + scoredSars.getName(); } }; }
From source file:org.jasig.portlet.notice.util.sort.Sorting.java
/** * @deprecated Part of the legacy, Portlet-based API. *///from www . j a v a 2 s . c o m @Deprecated public static List<NotificationEntry> sort(PortletRequest req, List<NotificationEntry> entries) { final Comparator<NotificationEntry> comparator = chooseConfiguredComparator(req); if (comparator == null) { // No sorting; we're done... return entries; } final List<NotificationEntry> rslt = new ArrayList<>(entries); // defensive copy rslt.sort(comparator); return rslt; }
From source file:com.wrmsr.wava.yen.translation.UnitTranslation.java
public static Function translateFunction(YFunction function, Map<Name, Signature> functionSignatures) { requireNonNull(function);/*from w w w . j a va 2 s . c om*/ checkArgument(function.getName().isPresent()); checkArgument(function.getResult() != Type.UNREACHABLE); checkArgument(function.getBody().isPresent()); checkArgument(function.getLocalNames().size() == function.getNumLocals()); checkArgument(function.getLocalIndices().size() == function.getNumLocals()); List<Pair<Name, Index>> localList = function.getLocalIndices().entrySet().stream() .map(e -> ImmutablePair.of(e.getKey(), e.getValue())).collect(Collectors.toList()); localList.sort((l, r) -> l.getValue().compareTo(r.getValue())); checkArgument( enumerate(localList.stream().map(Pair::getRight)).allMatch(e -> e.getItem().get() == e.getIndex())); Locals locals = Locals .of(localList.stream().map(l -> ImmutablePair.of(l.getLeft(), function.getLocalType(l.getRight()))) .collect(toImmutableList())); Node body = NodeTranslation.translateNode(function.getBody().get(), functionSignatures); return new Function(function.getName().get(), function.getResult(), function.getNumParams(), locals, body); }
From source file:org.jasig.portlet.notice.util.sort.Sorting.java
private static NotificationResponse sortNotificationResponse(Comparator<NotificationEntry> comparator, NotificationResponse data) {//from w w w .ja v a 2 s. co m // Sort each category... final List<NotificationCategory> copies = new ArrayList<>(); for (NotificationCategory category : data.getCategories()) { final List<NotificationEntry> entries = new ArrayList<>(category.getEntries()); // defensive copy entries.sort(comparator); copies.add(new NotificationCategory(category.getTitle(), entries)); } return new NotificationResponse(copies, data.getErrors()); }
From source file:uk.gov.gchq.gaffer.schemabuilder.service.SchemaBuilderService.java
private static List<Class> getSubClasses(final Class<?> clazz) { final Set<URL> urls = new HashSet<>(); for (final String packagePrefix : System .getProperty(SystemProperty.PACKAGE_PREFIXES, SystemProperty.PACKAGE_PREFIXES_DEFAULT).split(",")) { urls.addAll(ClasspathHelper.forPackage(packagePrefix)); }//from www . ja v a 2 s. co m final List<Class> classes = new ArrayList<Class>(new Reflections(urls).getSubTypesOf(clazz)); keepPublicConcreteClasses(classes); classes.sort(Comparator.comparing(Class::getName)); return classes; }