List of usage examples for java.util List sort
@SuppressWarnings({ "unchecked", "rawtypes" }) default void sort(Comparator<? super E> c)
From source file:ninja.eivind.hotsreplayuploader.concurrent.tasks.HeroListTask.java
@Override protected List<HotSLogsHero> call() throws Exception { final String result = httpClient.simpleRequest(API_ROUTE); final HotSLogsHero[] heroes = new ObjectMapper().readValue(result, HotSLogsHero[].class); final List<HotSLogsHero> heroList = Arrays.asList(heroes); heroList.sort((o1, o2) -> o1.getPrimaryName().compareTo(o2.getPrimaryName())); return heroList; }
From source file:com.vgorcinschi.concordiafootballmanager.data.DefaultPlayerService.java
@Override @Transactional/*www . jav a2 s.c o m*/ public List<Player> getAllPlayers() { List<Player> list = this.playerRepository.getAll(); list.sort((p1, p2) -> p1.getSalary().compareTo(p2.getSalary())); return list; }
From source file:org.neo4j.nlp.impl.util.VectorUtil.java
public static List<LinkedHashMap<String, Object>> getPhrasesForClass(GraphDatabaseService db, String className) {// w w w . ja va2 s. co m // This method trains a model on a supplied label and text content VsmCacheModel vsmCacheModel = new VsmCacheModel(db).invoke(); List<Integer> longs = vsmCacheModel.getDocuments().get(className).stream() .map(a -> ((Integer) a.get("feature"))).collect(Collectors.toList()); Map<Long, LinkedHashMap<Long, Integer>> pageRankGraph = new HashMap<>(); // PageRank Map<Long, Double> pageRank = getPageRankOnFeatures(db, longs, pageRankGraph); // Translate map to phrases List<LinkedHashMap<String, Object>> results = longs.stream().map(a -> { LinkedHashMap<String, Object> linkHashMap = new LinkedHashMap<>(); linkHashMap.put("feature", NodeManager.getNodeFromGlobalCache(a.longValue()).get("phrase")); linkHashMap.put("affinity", (pageRank.get(a.longValue()) + getFeatureMatchDistribution(db, a.longValue())) / 2.0); return linkHashMap; }).collect(Collectors.toList()); results.sort((a, b) -> { Double diff = (((Double) a.get("affinity")) * 100) - (((Double) b.get("affinity")) * 100); return diff > 0.0 ? -1 : diff.equals(0.0) ? 0 : 1; }); return results; }
From source file:com.fortify.processrunner.processor.CompositeOrderedProcessor.java
/** * This method retrieves the currently configured {@link IProcessor} instances * from our superclass, and returns them in a sorted order. *///from w w w.ja v a2 s . c o m @Override protected List<IProcessor> getProcessors() { List<IProcessor> result = new ArrayList<IProcessor>(super.getProcessors()); result.sort(new OrderComparator()); return result; }
From source file:io.siddhi.doc.gen.core.utils.DocumentationUtils.java
/** * This add a new page to the list of pages in the mkdocs configuration * * @param mkdocsConfigFile The mkdocs configuration file * @param documentationBaseDirectory The base directory of the documentation * @throws FileNotFoundException If mkdocs configuration file is not found *//*ww w. ja v a 2s .c om*/ public static void updateAPIPagesInMkdocsConfig(File mkdocsConfigFile, String documentationBaseDirectory) throws FileNotFoundException { // Retrieving the documentation file names File documentationDirectory = new File( documentationBaseDirectory + File.separator + Constants.API_SUB_DIRECTORY); String[] documentationFiles = documentationDirectory .list((directory, fileName) -> fileName.endsWith(Constants.MARKDOWN_FILE_EXTENSION)); List<String> apiDirectoryContent; if (documentationFiles == null) { apiDirectoryContent = new ArrayList<>(); } else { apiDirectoryContent = Arrays.asList(documentationFiles); apiDirectoryContent.sort(new Comparator<String>() { @Override public int compare(String s1, String s2) { String[] s1s = s1.split("\\D+"); String[] s2s = s2.split("\\D+"); int i = 0; while (s1s.length > i || s2s.length > i) { String s1a = "0"; String s2a = "0"; if (s1s.length > i) { s1a = s1s[i]; } if (s2s.length > i) { s2a = s2s[i]; } int s1aInt = Integer.parseInt(s1a); int s2aInt = Integer.parseInt(s2a); if (s2aInt > s1aInt) { return 1; } else if (s2aInt < s1aInt) { return -1; } i++; } return 0; } }); } String latestVersionFile = null; if (apiDirectoryContent.size() > 1) { String first = apiDirectoryContent.get(0); String second = apiDirectoryContent.get(1); if (first.equals(Constants.LATEST_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION)) { latestVersionFile = second; } } // Creating yaml parser DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); Yaml yaml = new Yaml(dumperOptions); // Reading the mkdocs configuration Map<String, Object> yamlConfig = (Map<String, Object>) yaml .load(new InputStreamReader(new FileInputStream(mkdocsConfigFile), Constants.DEFAULT_CHARSET)); // Getting the pages list List<Map<String, Object>> yamlConfigPagesList = (List<Map<String, Object>>) yamlConfig .get(Constants.MKDOCS_CONFIG_PAGES_KEY); // Creating the new api pages list List<Map<String, Object>> apiPagesList = new ArrayList<>(); for (String apiFile : apiDirectoryContent) { String pageName = apiFile.substring(0, apiFile.length() - Constants.MARKDOWN_FILE_EXTENSION.length()); Map<String, Object> newPage = new HashMap<>(); if (latestVersionFile != null && pageName.equals(Constants.LATEST_FILE_NAME)) { pageName = "Latest (" + latestVersionFile.substring(0, latestVersionFile.length() - Constants.MARKDOWN_FILE_EXTENSION.length()) + ")"; } newPage.put(pageName, Constants.API_SUB_DIRECTORY + Constants.MKDOCS_FILE_SEPARATOR + apiFile); apiPagesList.add(newPage); } // Setting the new api pages Map<String, Object> yamlConfigAPIPage = null; for (Map<String, Object> yamlConfigPage : yamlConfigPagesList) { if (yamlConfigPage.get(Constants.MKDOCS_CONFIG_PAGES_API_KEY) != null) { yamlConfigAPIPage = yamlConfigPage; break; } } if (yamlConfigAPIPage == null) { yamlConfigAPIPage = new HashMap<>(); yamlConfigPagesList.add(yamlConfigAPIPage); } yamlConfigAPIPage.put(Constants.MKDOCS_CONFIG_PAGES_API_KEY, apiPagesList); // Saving the updated configuration yaml.dump(yamlConfig, new OutputStreamWriter(new FileOutputStream(mkdocsConfigFile), Constants.DEFAULT_CHARSET)); }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.RunningServiceDetails.java
public Integer getLatestEnabledVersion() { List<Integer> versions = new ArrayList<>(instances.keySet()); if (!versions.isEmpty()) { versions.sort(Integer::compareTo); versions.sort(Comparator.reverseOrder()); }/*from w ww . j a v a 2 s . c om*/ return versions.stream().map(i -> new ImmutablePair<>(i, instances.get(i))) .filter(is -> is.getRight().stream().allMatch(i -> i.isHealthy() && i.isRunning())).findFirst() .orElse(new ImmutablePair<>(null, null)).getLeft(); }
From source file:de.hs.mannheim.modUro.controller.diagram.BoxAndWhiskerPlotController.java
/** * Creates dataset for BoxWhiskerPlot.//from w w w . j a v a 2 s.c o m * * @return */ private BoxAndWhiskerCategoryDataset createDataset() { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); List<String> sortedModels = new ArrayList<>(models); sortedModels.sort(String::compareTo); for (String model : sortedModels) { StatisticValues stat = stats.get(model); BoxAndWhiskerItem item = new BoxAndWhiskerItem(stat.getMean(), stat.getSecondPercentile(), stat.getFirstPercentile(), stat.getLastPercentile(), stat.getMin(), stat.getMax(), stat.getMin(), stat.getMax(), new ArrayList<>()); // Second parameter is the row key (?), using always the same works: dataset.add(item, "", model); } return dataset; }
From source file:ninja.eivind.hotsreplayuploader.versions.ReleaseManager.java
public Optional<GitHubRelease> getNewerVersionIfAny() { final ReleaseComparator releaseComparator = new ReleaseComparator(); try {//from w w w . ja v a 2 s .com final List<GitHubRelease> latest = getLatest(); latest.sort(releaseComparator); final GitHubRelease latestRelease = latest.get(0); final int compare = releaseComparator.compare(currentRelease, latestRelease); if (!latest.isEmpty() && compare > 0) { LOG.info("Newer release is: " + latestRelease); return Optional.of(latestRelease); } else { LOG.info(currentRelease + " is the newest version."); } } catch (IOException e) { LOG.error("Unable to get latest versions", e); } return Optional.empty(); }
From source file:net.dv8tion.jda.core.utils.cache.impl.SortedSnowflakeCacheView.java
@Override public List<T> asList() { List<T> list = new ArrayList<>(elements.size()); elements.forEachValue(list::add);//w w w . j a v a2s .c om list.sort(comparator); return Collections.unmodifiableList(list); }
From source file:com.skelril.nitro.droptable.DropTableImpl.java
public DropTableImpl(DiceRoller roller, List<DropTableEntry> possible) { this.roller = roller; // First sort possible, then apply possible.sort((a, b) -> a.getChance() - b.getChance()); Validate.isTrue(!possible.isEmpty() && possible.get(0).getChance() > 0); this.possible = ImmutableList.copyOf(possible); }