List of usage examples for java.util List sort
@SuppressWarnings({ "unchecked", "rawtypes" }) default void sort(Comparator<? super E> c)
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:com.epam.ngb.cli.manager.command.handler.http.ReferenceListHandler.java
@Override public int runCommand() { HttpRequestBase request = getRequest(getRequestUrl()); setDefaultHeader(request);//from w ww .jav a 2s. c om if (isSecure()) { addAuthorizationToRequest(request); } String result = RequestManager.executeRequest(request); ResponseResult<List<BiologicalDataItem>> responseResult; try { responseResult = getMapper().readValue(result, getMapper().getTypeFactory().constructParametrizedType(ResponseResult.class, ResponseResult.class, getMapper().getTypeFactory().constructParametrizedType(List.class, List.class, BiologicalDataItem.class))); } catch (IOException e) { throw new ApplicationException(e.getMessage(), e); } if (ERROR_STATUS.equals(responseResult.getStatus())) { throw new ApplicationException(responseResult.getMessage()); } if (responseResult.getPayload() == null || responseResult.getPayload().isEmpty()) { LOGGER.info("No references registered on the server."); } else { List<BiologicalDataItem> items = responseResult.getPayload(); items.sort(Comparator.comparing(BiologicalDataItem::getBioDataItemId)); AbstractResultPrinter printer = AbstractResultPrinter.getPrinter(printTable, items.get(0).getFormatString(items)); printer.printHeader(items.get(0)); items.forEach(printer::printItem); } return 0; }
From source file:org.neo4j.nlp.impl.util.VectorUtil.java
public static List<LinkedHashMap<String, Object>> getPhrases(GraphDatabaseService db, String text, GraphManager graphManager, DecisionTree<Long> decisionTree) { // This method trains a model on a supplied label and text content Map<Long, Integer> patternMatchers = decisionTree.traverseByPattern(text); Map<Long, LinkedHashMap<Long, Integer>> pageRankGraph = new HashMap<>(); // PageRank/* www .j av a 2 s . c om*/ Map<Long, Double> pageRank = getPageRankOnFeatures(db, patternMatchers.keySet().stream().map(l -> l.intValue()).collect(Collectors.toList()), pageRankGraph); // Translate map to phrases List<LinkedHashMap<String, Object>> results = patternMatchers.keySet().stream().map(a -> { LinkedHashMap<String, Object> linkHashMap = new LinkedHashMap<>(); linkHashMap.put("feature", NodeManager.getNodeFromGlobalCache(a).get("phrase")); linkHashMap.put("frequency", patternMatchers.get(a)); linkHashMap.put("variance", getFeatureMatchDistribution(db, a)); linkHashMap.put("affinity", pageRank.get(a)); return linkHashMap; }).collect(Collectors.toList()); results.sort((a, b) -> { Integer diff = ((Integer) a.get("frequency")) - ((Integer) b.get("frequency")); return diff > 0 ? -1 : diff.equals(0) ? 0 : 1; }); return results; }
From source file:com.aestheticsw.jobkeywords.service.termextractor.domain.TermFrequencyResults.java
public List<TermFrequency> getSortedTermFrequencyList(Comparator<? super TermFrequency> comparator) { List<TermFrequency> list = new ArrayList<>(termFrequencyMap.values()); list.sort(comparator); return list;// www . ja va 2 s. co m }
From source file:eu.amidst.core.datastream.Attributes.java
/** * Creates a new Attributes from a given List of attribute objects. * @param attributes a non-empty list of Attribute objects. *///from w w w. j av a2 s . co m public Attributes(List<Attribute> attributes) { attributes.sort((a, b) -> a.getIndex() - b.getIndex()); this.attributes = attributes;//Collections.unmodifiableList(attributes); this.time_id = null; this.seq_id = null; for (Attribute att : getFullListOfAttributes()) { String name = att.getName(); if (name.equals(Attributes.TIME_ID_ATT_NAME)) { this.time_id = att; this.time_id.setSpecialAttribute(true); this.time_id.setTimeId(true); //this.time_id.setNumberFormat(new DecimalFormat("#")); } else if (name.equals(Attributes.SEQUENCE_ID_ATT_NAME)) { this.seq_id = att; this.seq_id.setSpecialAttribute(true); this.seq_id.setSeqId(true); //this.seq_id.setNumberFormat(new DecimalFormat("#")); } } }
From source file:edu.usu.sdl.openstorefront.report.ComponentOrganizationReport.java
@Override protected void writeReport() { CSVGenerator cvsGenerator = (CSVGenerator) generator; //write header cvsGenerator.addLine("Component Organization Report", sdf.format(TimeUtil.currentDate())); cvsGenerator.addLine("Organization", "Component Name", //"Security Classification", "Last Update Date", "Approve Status"); List<ODocument> documents = service.getPersistenceService().query( "Select DISTINCT(organization) as organization, name, name.toLowerCase() as sortname, securityMarkingType, lastActivityDts, approvalState from " + Component.class.getSimpleName() + " where approvalState='" + ApprovalStatus.APPROVED + "' and " + " activeStatus= '" + Component.ACTIVE_STATUS + "' order by sortname", new HashMap<>()); //group by org Map<String, List<ODocument>> orgMap = new HashMap<>(); documents.forEach(document -> {/*from w w w . ja va2 s. c om*/ String org = document.field("organization"); if (StringUtils.isBlank(org)) { org = "No Organization Specified"; } if (orgMap.containsKey(org)) { orgMap.get(org).add(document); } else { List<ODocument> records = new ArrayList<>(); records.add(document); orgMap.put(org, records); } }); long totalComponents = 0; List<String> sortedOrganizations = new ArrayList<>(orgMap.keySet()); sortedOrganizations.sort(null); for (String organization : sortedOrganizations) { cvsGenerator.addLine(organization); for (ODocument document : orgMap.get(organization)) { //String securityMarking = document.field("securityMarkingType"); cvsGenerator.addLine("", document.field("name"), //securityMarking == null ? "" : "(" + securityMarking + ") - " + TranslateUtil.translate(SecurityMarkingType.class, securityMarking), document.field("lastActivityDts"), document.field("approvalState")); totalComponents++; } cvsGenerator.addLine("Total", orgMap.get(organization).size()); cvsGenerator.addLine(""); } cvsGenerator.addLine(""); cvsGenerator.addLine("Report Totals"); cvsGenerator.addLine("Total Organizations: " + orgMap.keySet().size()); cvsGenerator.addLine("Total Component: " + totalComponents); }
From source file:org.cgiar.ccafs.marlo.action.json.global.CrpByUserEmailAction.java
@Override public String execute() throws Exception { crps = new ArrayList<Map<String, Object>>(); Map<String, Object> crpMap; List<GlobalUnit> crps = crpManager.crpUsers(userEmail); crps.sort(Comparator.comparing(GlobalUnit::getAcronym)); for (GlobalUnit crp : crps) { try {/*from w w w .j a v a2s.c o m*/ crpMap = new HashMap<String, Object>(); crpMap.put("id", crp.getId()); crpMap.put("name", crp.getName()); crpMap.put("acronym", crp.getAcronym()); crpMap.put("type", crp.getGlobalUnitType().getName()); crpMap.put("idType", crp.getGlobalUnitType().getId()); this.crps.add(crpMap); } catch (Exception e) { logger.error("unable to add flagship to crps list", e); /** * Original code swallows the exception and didn't even log it. Now we at least log it, * but we need to revisit to see if we should continue processing or re-throw the exception. */ } user = new HashMap<>(); User usrDB = userManager.getUserByEmail(userEmail); if (usrDB != null) { user.put("name", usrDB.getComposedCompleteName()); user.put("agree", usrDB.getAgreeTerms()); } else { usrDB = userManager.getUserByUsername(userEmail); if (usrDB != null) { user.put("name", usrDB.getComposedCompleteName()); user.put("agree", usrDB.getAgreeTerms()); } } } return SUCCESS; }
From source file:com.epam.ngb.cli.manager.command.handler.http.DatasetListHandler.java
/** * Performs a dataset list request to NGB server and its result to * StdOut. The performed request varies according to the presence of 'parent' option. * @return 0 if request completed successfully *//*w ww .ja v a 2 s . com*/ @Override public int runCommand() { HttpRequestBase request = parentId == null ? createListingRequest() : createTreeRequest(parentId); String result = RequestManager.executeRequest(request); ResponseResult<List<Project>> responseResult; try { responseResult = getMapper().readValue(result, getMapper().getTypeFactory().constructParametrizedType( ResponseResult.class, ResponseResult.class, getMapper().getTypeFactory().constructParametrizedType(List.class, List.class, Project.class))); } catch (IOException e) { throw new ApplicationException(e.getMessage(), e); } if (ERROR_STATUS.equals(responseResult.getStatus())) { throw new ApplicationException(responseResult.getMessage()); } if (responseResult.getPayload() == null || responseResult.getPayload().isEmpty()) { LOGGER.info("No datasets registered on the server."); } else { List<Project> items = responseResult.getPayload(); items.sort(Comparator.comparing(Project::getId)); AbstractResultPrinter printer = AbstractResultPrinter.getPrinter(printTable, items.get(0).getFormatString(items)); printer.printHeader(items.get(0)); items.forEach(printer::printItem); } return 0; }
From source file:de.hs.mannheim.modUro.reader.BoxAndWhiskersPlotDiagram.java
/** * Creates dataset for BoxWhiskerPlot./* w w w. j ava 2 s. c o m*/ * * @return */ private BoxAndWhiskerCategoryDataset createDataset() { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); List<String> sortedModels = bwpModel.getModelTypeName(); sortedModels.sort(String::compareTo); for (String model : sortedModels) { StatisticValues stat = bwpModel.getStatisticValues().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: int n = stat.size(); dataset.add(item, "", model + " (n=" + n + ")"); } return dataset; }
From source file:de.hs.mannheim.modUro.reader.BoxAndWhiskersPlotDiagram.java
@Override public String exportToWSV() { Map<String, StatisticValues> stats = bwpModel.getStatisticValues(); List<String> sortedModels = new ArrayList<>(stats.keySet()); sortedModels.sort((s1, s2) -> s2.compareTo(s1)); String s = "\n# Model Data (Mean fitness) ..."; for (String m : sortedModels) { double[] data = stats.get(m).getData(); s += "\n" + m; for (double v : data) { s += " " + v; }/* w w w. java2 s .c o m*/ } s += "\n"; return s; }