List of usage examples for java.util.stream Collectors toSet
public static <T> Collector<T, ?, Set<T>> toSet()
From source file:de.interactive_instruments.etf.webapp.controller.TestObjectController.java
@RequestMapping(value = "/testobjects", method = RequestMethod.GET) public String overview(Model model) throws StoreException, ConfigurationException { final Map<EID, TestObjectResourceType> resTypes = taskFactory.getTestObjectResourceTypes(); if (resTypes != null) { model.addAttribute("resourceSchemes", resTypes.values().parallelStream() .map(TestObjectResourceType::getUriScheme).collect(Collectors.toSet())); }//from ww w.j a va2s .c om model.addAttribute("testObjects", getTestObjects()); return "testobjects/overview"; }
From source file:com.github.drbookings.model.data.manager.MainManager.java
private BookingBean findBooking(final LocalDate date, final String roomName) throws MatchException { final int maxCount = 100; int count = 0; LocalDate date2 = date;// w ww . ja v a 2 s .co m Collection<BookingBean> result2 = null; do { result2 = bookingEntries.get(date2).stream().filter(b -> b.getRoom().getName().equals(roomName)) .filter(b -> !b.isCheckIn()).map(b -> b.getElement()).collect(Collectors.toSet()); if (result2.stream().anyMatch(b -> b.getCleaning() != null)) { if (logger.isDebugEnabled()) { logger.debug("Found entry with cleaning, aborting"); } throw new MatchException("Failed to find matching booking for " + date + " and " + roomName); } result2 = result2.stream().filter(b -> b.getCleaning() == null).collect(Collectors.toSet()); count++; date2 = date2.minusDays(1); } while ((result2 == null || result2.isEmpty()) && count < maxCount); if (count == maxCount) { throw new MatchException("Failed to find matching booking for " + date + " and " + roomName); } if (result2.size() > 1) { throw new MatchException("Found more than one matching booking"); } return result2.iterator().next(); }
From source file:io.gravitee.gateway.services.monitoring.MonitoringService.java
public Set<Plugin> plugins() { return pluginRegistry.plugins().stream().map(regPlugin -> { Plugin plugin = new Plugin(); plugin.setId(regPlugin.id());/*from w w w . ja v a 2s . c o m*/ plugin.setName(regPlugin.manifest().name()); plugin.setDescription(regPlugin.manifest().description()); plugin.setVersion(regPlugin.manifest().version()); plugin.setType(regPlugin.type().name().toLowerCase()); plugin.setPlugin(regPlugin.clazz()); return plugin; }).collect(Collectors.toSet()); }
From source file:delfos.rs.trustbased.WeightedGraph.java
/** * Devuelve todos los nodos del grafo. * * @return */ public Set<Node> allNodes() { return nodesIndex.keySet().stream().collect(Collectors.toSet()); }
From source file:com.romeikat.datamessie.core.base.dao.impl.DocumentDao.java
public Map<CleanedContent, Document> getForCleanedContents(final SharedSessionContract ssc, final Collection<CleanedContent> cleanedContents) { // Query for documents final Set<Long> documentIds = cleanedContents.stream().map(c -> c.getDocumentId()) .collect(Collectors.toSet()); final Map<Long, Document> documentsById = getIdsWithEntities(ssc, documentIds); // Map cleanedContents -> documents final Map<CleanedContent, Document> result = Maps.newHashMapWithExpectedSize(cleanedContents.size()); for (final CleanedContent cleanedContent : cleanedContents) { final Document document = documentsById.get(cleanedContent.getDocumentId()); result.put(cleanedContent, document); }//from ww w. j a v a 2 s . c o m return result; }
From source file:at.ac.tuwien.qse.sepm.gui.controller.impl.PhotoInspectorImpl.java
private void saveTags(Photo photo) { LOGGER.debug("updating tags of {}", photo); // Find the new tags. Set<String> oldTags = photo.getData().getTags().stream().map(Tag::getName).collect(Collectors.toSet()); Set<String> newTags = tagPicker.filter(oldTags); LOGGER.debug(tagPicker.getTags());/*from www . j a va2s .c o m*/ LOGGER.debug("old tags {} will be updated to new tags {}", oldTags, newTags); if (oldTags.equals(newTags)) { LOGGER.debug("tags have not changed of photo {}", photo); return; } // Replace tags with new ones. photo.getData().getTags().clear(); newTags.forEach(tag -> photo.getData().getTags().add(new Tag(null, tag))); savePhoto(photo); onUpdate(); }
From source file:com.diversityarrays.kdxplore.trials.SampleGroupExportDialog.java
static public Set<Integer> getExcludedTraitIds(Component comp, String msgTitle, KdxploreDatabase kdxdb, SampleGroup sg) {/*from w w w .j a v a2 s . co m*/ Set<Integer> excludeTheseTraitIds = new HashSet<>(); try { Set<Integer> traitIds = collectTraitIdsFromSamples(kdxdb, sg); List<Trait> undecidableTraits = new ArrayList<>(); Set<Integer> missingTraitIds = new TreeSet<>(); Map<Integer, Trait> traitMap = kdxdb.getKDXploreKSmartDatabase().getTraitMap(); for (Integer traitId : traitIds) { Trait t = traitMap.get(traitId); if (t == null) { missingTraitIds.add(traitId); } else if (TraitLevel.UNDECIDABLE == t.getTraitLevel()) { undecidableTraits.add(t); } } if (!missingTraitIds.isEmpty()) { String msg = missingTraitIds.stream().map(i -> Integer.toString(i)) .collect(Collectors.joining(",")); MsgBox.error(comp, msg, "Missing Trait IDs"); return null; } if (!undecidableTraits.isEmpty()) { String msg = undecidableTraits.stream().map(Trait::getTraitName) .collect(Collectors.joining("\n", "Traits that are neither Plot nor Sub-Plot:\n", "\nDo you want to continue and Exclude samples for those Traits?")); if (JOptionPane.YES_OPTION != JOptionPane.showConfirmDialog(comp, msg, msgTitle, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE)) { return null; } Set<Integer> tmp = undecidableTraits.stream().map(Trait::getTraitId).collect(Collectors.toSet()); excludeTheseTraitIds.addAll(tmp); } } catch (IOException e) { MsgBox.error(comp, "Unable to read samples from database\n" + e.getMessage(), msgTitle); return null; } return excludeTheseTraitIds; }
From source file:com.sonicle.webtop.core.app.JaxRsServiceApplication.java
private void configureServiceApis(WebTopApp wta, ServletConfig servletConfig) { ServiceManager svcMgr = wta.getServiceManager(); String serviceId = servletConfig.getInitParameter(RestApi.INIT_PARAM_WEBTOP_SERVICE_ID); if (StringUtils.isBlank(serviceId)) throw new WTRuntimeException( "Invalid servlet init parameter [" + RestApi.INIT_PARAM_WEBTOP_SERVICE_ID + "]"); ServiceDescriptor desc = svcMgr.getDescriptor(serviceId); if (desc == null) throw new WTRuntimeException("Service descriptor not found [{0}]", serviceId); if (desc.hasOpenApiDefinitions()) { for (ServiceDescriptor.OpenApiDefinition apiDefinition : desc.getOpenApiDefinitions()) { // Register resources for (Class clazz : apiDefinition.resourceClasses) { javax.ws.rs.Path pathAnnotation = (javax.ws.rs.Path) ClassHelper .getClassAnnotation(clazz.getSuperclass(), javax.ws.rs.Path.class); String resourcePath = "/" + PathUtils.concatPathParts(apiDefinition.context, pathAnnotation.value()); logger.debug("[{}] Registering JaxRs resource [{}] -> [{}]", servletConfig.getServletName(), clazz.toString(), resourcePath); registerResources(Resource.builder(clazz).path(resourcePath).build()); }/*from w w w . j a v a 2 s.c om*/ // Configure OpenApi listing OpenAPI oa = new OpenAPI(); oa.info(desc.buildOpenApiInfo(apiDefinition)); SwaggerConfiguration oaConfig = new SwaggerConfiguration().openAPI(oa).prettyPrint(true) .resourcePackages(Stream.of(apiDefinition.implPackage).collect(Collectors.toSet())); try { new JaxrsOpenApiContextBuilder().servletConfig(servletConfig).application(this) .ctxId(apiDefinition.context).openApiConfiguration(oaConfig).buildContext(true); } catch (OpenApiConfigurationException ex) { logger.error("Unable to init swagger", ex); } } } }
From source file:com.globocom.grou.report.ReportService.java
private void notifyByMail(Test test, String email, Map<String, Double> result) throws Exception { MimeMessagePreparator messagePreparator = mimeMessage -> { MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage); messageHelper.setTo(email);// w w w. j av a 2s .c o m messageHelper.setFrom(MAIL_FROM); messageHelper.setSubject(getSubject(test)); Context context = new Context(); context.setVariable("project", test.getProject()); context.setVariable("name", test.getName()); HashMap<String, Object> testContext = new HashMap<>(); testContext.put("dashboard", test.getDashboard()); testContext.put("loaders", test.getLoaders().stream().map(Loader::getName).collect(Collectors.toSet())); testContext.put("properties", test.getProperties()); testContext.put("id", test.getId()); testContext.put("created", test.getCreatedDate().toString()); testContext.put("lastModified", test.getLastModifiedDate().toString()); testContext.put("durationTimeMillis", test.getDurationTimeMillis()); context.setVariable("testContext", mapper.writeValueAsString(testContext).split("\\R")); Set<String> tags = test.getTags(); context.setVariable("tags", tags); context.setVariable("metrics", new TreeMap<>(result)); String content = templateEngine.process("reportEmail", context); messageHelper.setText(content, true); }; try { emailSender.send(messagePreparator); LOGGER.info( "Test " + test.getProject() + "." + test.getName() + ": sent notification to email " + email); } catch (MailException e) { LOGGER.error(e.getMessage(), e); } }
From source file:org.sardineproject.sbyod.rest.AppWebService.java
/** * This method removes all services from a set that are not intended for the user to manipulate, * for example the portal service or the dns service * @param services a set of services/*from ww w. j a va 2 s .co m*/ * @return an iterable of services without configuration services */ private Iterable<Service> removeConfigurationServices(Set<Service> services) { // get the portalService Service portalService = get(PortalService.class).getPortalService(); // get the dns services Set<Service> dnsServices = get(DnsService.class).getDnsServices(); // remove the configuration services return services.stream().filter(s -> !s.equals(portalService)).filter(s -> !dnsServices.contains(s)) .collect(Collectors.toSet()); }