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:org.cgiar.ccafs.marlo.action.powb.CRPStaffingAction.java
public List<LiaisonInstitution> getFlagships() { List<LiaisonInstitution> flagshipsList = loggedCrp.getLiaisonInstitutions().stream() .filter(c -> c.getCrpProgram() != null && c.getCrpProgram().getProgramType() == ProgramType.FLAGSHIP_PROGRAM_TYPE.getValue() && c.isActive()) .collect(Collectors.toList()); if (flagshipsList != null) { flagshipsList.sort(Comparator.comparing(LiaisonInstitution::getAcronym)); return flagshipsList; } else {/*from w w w . j ava 2s . c o m*/ return new ArrayList<>(); } }
From source file:nc.noumea.mairie.appock.services.impl.CommandeServiceImpl.java
@Override public CommandeTreeNode getCommandeTreeRoot(Commande commande, boolean vueAgrege) { CommandeTreeNode result = new CommandeTreeNode(null, "", null, null, null, 0, null); Map<Service, List<Demande>> map = construitMapServiceListeDemande(commande); List<Service> listeService = new ArrayList(map.keySet()); Comparator serviceComparator = Comparator .comparing((Service service) -> service.getDirection().getPole().getLibelle()) .thenComparing(service -> service.getDirection().getLibelleCourt()) .thenComparing(Service::getLibelleCourt); Collections.sort(listeService, serviceComparator); for (Service service : listeService) { CommandeTreeNode rootService = construitPremierNiveauService(result, map, service, vueAgrege); if (!vueAgrege) { for (Demande demande : map.get(service)) { rootService.appendChild(construitSecondNiveauDemande(result, demande)); }/*from www.j a v a2 s . c o m*/ } result.appendChild(rootService); } return result; }
From source file:View.Visualize.java
public void getAreaChartData(Integer nameColumn, Integer valueColumn, Table table, StackedAreaChart areaChart, Boolean newSeries, Boolean rowCounter) { data.clear();/*w ww . j a v a 2s . c om*/ ObservableList<XYChart.Data> areaChartData = FXCollections.observableArrayList(); XYChart.Series series1 = new XYChart.Series(); if (!newSeries) { series1.getData().clear(); areaChart.getData().clear(); areaChartSeries.clear(); } areaChart.setAnimated(false);//bug fix addDataFromTable(table, nameColumn, valueColumn, rowCounter); data.entrySet().stream().map(entry -> new XYChart.Data(entry.getKey(), entry.getValue())) .forEach(areaChartData::add); series1.getData().addAll(areaChartData); areaChart.getData().addAll(series1); areaChartSeries.add(series1); series1.getData().sort(Comparator.comparing(BarChart.Data<String, Double>::getYValue).reversed()); series1.getNode().setUserData(areaChartSeries.size() - 1); setupHover(series1); addColorChangeOnSeries(series1); }
From source file:org.tightblog.rendering.requests.WeblogSearchRequest.java
/** * Create weblog entries for each result found. *//*ww w . jav a 2 s. c o m*/ Map<LocalDate, TreeSet<WeblogEntry>> convertHitsToEntries(ScoreDoc[] hits, SearchTask searchTask) { Map<LocalDate, TreeSet<WeblogEntry>> results = new HashMap<>(); // determine offset and limit this.offset = getPageNum() * RESULTS_PER_PAGE; if (this.offset >= hits.length) { this.offset = 0; } this.limit = RESULTS_PER_PAGE; if (this.offset + this.limit > hits.length) { this.limit = hits.length - this.offset; } WeblogEntry entry; Document doc; for (int i = offset; i < offset + limit; i++) { try { doc = searchTask.getSearcher().doc(hits[i].doc); } catch (IOException e) { log.warn("IOException processing {}", hits[i].doc, e); continue; } entry = searchModel.getWeblogEntryRepository() .findByIdOrNull(doc.getField(FieldConstants.ID).stringValue()); if (entry != null && WeblogEntry.PubStatus.PUBLISHED.equals(entry.getStatus())) { LocalDate pubDate = entry.getPubTime().atZone(ZoneId.systemDefault()).toLocalDate(); // ensure we do not get duplicates from Lucene by using a set collection. results.putIfAbsent(pubDate, new TreeSet<>(Comparator.comparing(WeblogEntry::getPubTime).reversed() .thenComparing(WeblogEntry::getTitle))); results.get(pubDate).add(entry); } } return results; }
From source file:org.opennms.smoketest.topo.GraphMLTopologyIT.java
@Test public void verifyNavigateToAndBreadcrumbs() { topologyUIPage.selectTopologyProvider(() -> LABEL); topologyUIPage.findVertex("East Region").contextMenu().click("Navigate To", "Markets (East Region)"); final ArrayList<TopologyIT.FocusedVertex> marketsVertcies = Lists.newArrayList( focusVertex(topologyUIPage, "Acme:markets:", "East 1"), focusVertex(topologyUIPage, "Acme:markets:", "East 2"), focusVertex(topologyUIPage, "Acme:markets:", "East 3"), focusVertex(topologyUIPage, "Acme:markets:", "East 4")); assertEquals(marketsVertcies, topologyUIPage.getFocusedVertices()); assertEquals("Markets", topologyUIPage.getSelectedLayer()); assertEquals(Lists.newArrayList("regions", "East Region"), topologyUIPage.getBreadcrumbs().getLabels()); // Click on last element should add all vertices to focus topologyUIPage.getFocusedVertices().get(0).removeFromFocus(); // remove an element from focus topologyUIPage.getBreadcrumbs().click("East Region"); assertEquals(marketsVertcies, topologyUIPage.getFocusedVertices()); // Click on 1st element, should switch layer and add "child" to focus topologyUIPage.getBreadcrumbs().click("regions"); assertEquals(Lists.newArrayList("regions"), topologyUIPage.getBreadcrumbs().getLabels()); assertEquals(Lists.newArrayList(focusVertex(topologyUIPage, "Acme:regions:", "East Region")), topologyUIPage.getFocusedVertices()); // Click on last element should add all elements to focus topologyUIPage.getBreadcrumbs().click("regions"); List<TopologyIT.FocusedVertex> focusedVertices = topologyUIPage.getFocusedVertices(); 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); // all elements should be focused }
From source file:org.sleuthkit.autopsy.timeline.ui.listvew.ListTimeline.java
/** * Constructor/* w w w. j ava 2 s . c o m*/ * * @param controller The controller for this timeline */ ListTimeline(TimeLineController controller) { this.controller = controller; sleuthkitCase = controller.getAutopsyCase().getSleuthkitCase(); tagsManager = controller.getAutopsyCase().getServices().getTagsManager(); FXMLConstructor.construct(this, ListTimeline.class, "ListTimeline.fxml"); //NON-NLS this.visibleEvents = new ConcurrentSkipListSet<>(Comparator.comparing(table.getItems()::indexOf)); }
From source file:grakn.core.daemon.executor.Storage.java
public void clean() { System.out.print("Cleaning " + DISPLAY_NAME + "..."); System.out.flush();/*w w w . j a v a 2 s.c o m*/ try (Stream<Path> files = Files.walk(STORAGE_DATA)) { files.map(Path::toFile).sorted(Comparator.comparing(File::isDirectory)).forEach(File::delete); Files.createDirectories(graknHome.resolve(STORAGE_DATA).resolve("data")); Files.createDirectories(graknHome.resolve(STORAGE_DATA).resolve("commitlog")); Files.createDirectories(graknHome.resolve(STORAGE_DATA).resolve("saved_caches")); System.out.println("SUCCESS"); } catch (IOException e) { System.out.println("FAILED!"); System.out.println("Unable to clean " + DISPLAY_NAME); } }
From source file:src.agent.DepuradoraAgent.java
public void llenarTanques(MasaDeAgua aguaSucia) { OntModel model = ontoManager.getModel(); String namingContext = ontoManager.getNamingContext(); OntProperty aguaTanqueProperty = model.getOntProperty(namingContext + Constants.MASA_DE_AGUA_TANQUE); OntProperty volumenTanqueProperty = model.getOntProperty(namingContext + Constants.VOLUMEN_TANQUE); List<Pair<Float, RDFNode>> listaTanques = listaTanquesVacios(); Collections.sort(listaTanques, Comparator.comparing(coste -> -coste.getLeft())); int i = 0;// w ww.j a v a2 s . c om while (aguaSucia.Volumen > 0) { MasaDeAgua aguaSuciaClone = aguaSucia.copy(); RDFNode tanqueNode = listaTanques.get(i++).getRight(); Individual tanque = tanqueNode.as(Individual.class); float volumenTanque = min(tanque.getPropertyValue(volumenTanqueProperty).asLiteral().getFloat(), aguaSuciaClone.Volumen); aguaSuciaClone.Volumen = volumenTanque; aguaSucia.Volumen -= volumenTanque; model.add(tanqueNode.asResource(), aguaTanqueProperty, ontoManager.createIndividual(aguaSuciaClone)); // imprimir resultado System.out.println("Se ha aadido al tanque " + tanque.getLocalName() + " " + aguaSuciaClone.Volumen + " litros de agua sucia"); aguaSuciaClone.showData(); } }
From source file:org.symphonyoss.vb.model.VoteProposalFormatter.java
/** * Get Comments by individual ID or list * * @param id Individual ID or -1 for list * @return MessageML (Body only) list of comments *//* ww w . j a v a 2 s . co m*/ public static String getCommentsMessage(VoteProposal voteProposal, int id) { StringBuilder comment = new StringBuilder(); List<VoteComment> sortedComments = voteProposal.getComments().stream() .sorted(Comparator.comparing(e -> (e.getTimestamp()))).collect(Collectors.toList()); for (VoteComment voteComment : sortedComments) { if (voteComment.getId() == id || id == -1) { comment.append(BREAK).append(SEPARATOR_ML); comment.append(TimeDateFormatting.formatDate(voteComment.getTimestamp())); if (voteComment.getSymUser().getId() < 0) { comment.append(": ").append(voteComment.getSymUser().getDisplayName()).append(" | "); } else { comment.append(": <mention uid=\"").append(voteComment.getSymUser().getId()).append("\"/> | "); //comment.append(": ").append(voteComment.getSymUser().getDisplayName()).append(" | "); } comment.append(voteComment.getComment()); } } return comment.toString(); }
From source file:org.phoenicis.repository.types.LocalRepository.java
private List<CategoryDTO> fetchCategories(String typeId, File typeDirectory) { final File[] categoryDirectories = typeDirectory.listFiles(); if (categoryDirectories == null) { return Collections.emptyList(); }// www . j a v a2 s. c o m final List<CategoryDTO> results = new ArrayList<>(); for (File categoryDirectory : categoryDirectories) { if (categoryDirectory.isDirectory() && !categoryDirectory.getName().startsWith(".")) { final File categoryJson = new File(categoryDirectory, "category.json"); if (categoryJson.exists()) { final CategoryDTO jsonCategoryDTO = unSerializeCategory(categoryJson); final CategoryDTO.Builder categoryDTOBuilder = new CategoryDTO.Builder(jsonCategoryDTO); categoryDTOBuilder.withTypeId(typeId); if (StringUtils.isBlank(jsonCategoryDTO.getId())) { if (!StringUtils.isBlank(jsonCategoryDTO.getName())) { categoryDTOBuilder.withId(jsonCategoryDTO.getName().replaceAll(ID_REGEX, "")); } else { categoryDTOBuilder.withId(categoryDirectory.getName().replaceAll(ID_REGEX, "")); } } final File categoryIconFile = new File(categoryDirectory, ICON_NAME); if (categoryIconFile.exists()) { categoryDTOBuilder.withIcon(categoryIconFile.toURI()); } categoryDTOBuilder.withApplications(fetchApplications(categoryDTOBuilder.getTypeId(), categoryDTOBuilder.getId(), categoryDirectory)); final CategoryDTO category = categoryDTOBuilder.build(); results.add(category); } } } results.sort(Comparator.comparing(CategoryDTO::getName)); return results; }