List of usage examples for java.util.stream Collectors toSet
public static <T> Collector<T, ?, Set<T>> toSet()
From source file:com.hp.octane.integrations.services.vulnerabilities.VulnerabilitiesServiceFunctionalityTest.java
@Test(timeout = 20000) public void testVulnerabilitiesFunctional() { Map<String, OctaneSPEndpointSimulator> simulators = null; try {// w w w . ja va 2 s . com String spIdA = UUID.randomUUID().toString(); String spIdB = UUID.randomUUID().toString(); String clientAInstanceId = UUID.randomUUID().toString(); String clientBInstanceId = UUID.randomUUID().toString(); Map<String, List<String>> preflightRequestCollectors = new LinkedHashMap<>(); Map<String, List<String>> pushVulnerabilitiesCollectors = new LinkedHashMap<>(); // init 2 shared space endpoints simulators simulators = initSPEPSimulators(Stream.of(spIdA, spIdB).collect(Collectors.toSet()), preflightRequestCollectors, pushVulnerabilitiesCollectors); // // I // add one client and verify it works okay // OctaneConfiguration configA = new OctaneConfiguration(clientAInstanceId, OctaneSPEndpointSimulator.getSimulatorUrl(), spIdA); OctaneClient clientA = OctaneSDK.addClient(configA, VulnerabilitiesServicePluginServicesTest.class); VulnerabilitiesService vulnerabilitiesServiceA = clientA.getVulnerabilitiesService(); vulnerabilitiesServiceA.enqueueRetrieveAndPushVulnerabilities("null-job", "null-build", System.currentTimeMillis(), 1); CIPluginSDKUtils.doWait(3000); Assert.assertFalse(preflightRequestCollectors.containsKey(spIdA)); Assert.assertFalse(preflightRequestCollectors.containsKey(spIdB)); // // II // add one more client and verify they are both works okay // OctaneConfiguration configB = new OctaneConfiguration(clientBInstanceId, OctaneSPEndpointSimulator.getSimulatorUrl(), spIdB); OctaneClient clientB = OctaneSDK.addClient(configB, VulnerabilitiesServicePluginServicesTest.class); VulnerabilitiesService vulnerabilitiesServiceB = clientB.getVulnerabilitiesService(); vulnerabilitiesServiceA.enqueueRetrieveAndPushVulnerabilities("job-preflight-true", "1", System.currentTimeMillis(), 1); vulnerabilitiesServiceA.enqueueRetrieveAndPushVulnerabilities("job-preflight-false", "1", System.currentTimeMillis(), 1); vulnerabilitiesServiceB.enqueueRetrieveAndPushVulnerabilities("job-preflight-true", "1", System.currentTimeMillis(), 1); vulnerabilitiesServiceB.enqueueRetrieveAndPushVulnerabilities("job-preflight-false", "1", System.currentTimeMillis(), 1); GeneralTestUtils.waitAtMostFor(12000, () -> { if (preflightRequestCollectors.get(spIdA) != null && preflightRequestCollectors.get(spIdA).size() == 2 && preflightRequestCollectors.get(spIdB) != null && preflightRequestCollectors.get(spIdB).size() == 2) { return true; } else { return null; } }); Assert.assertEquals(clientAInstanceId + "|job-preflight-true|1", preflightRequestCollectors.get(spIdA).get(0)); Assert.assertEquals(clientAInstanceId + "|job-preflight-false|1", preflightRequestCollectors.get(spIdA).get(1)); Assert.assertEquals(clientBInstanceId + "|job-preflight-true|1", preflightRequestCollectors.get(spIdB).get(0)); Assert.assertEquals(clientBInstanceId + "|job-preflight-false|1", preflightRequestCollectors.get(spIdB).get(1)); // // III // remove one client and verify it is shut indeed and the second continue to work okay // OctaneSDK.removeClient(clientA); // // IV // remove second client and ensure no interactions anymore // OctaneSDK.removeClient(clientB); } finally { // remove clients OctaneSDK.getClients().forEach(OctaneSDK::removeClient); // remove simulators if (simulators != null) removeSPEPSimulators(simulators.values()); } }
From source file:io.mandrel.data.extract.ExtractorService.java
public Pair<Set<Link>, Set<Link>> extractAndFilterOutlinks(Spider spider, Uri uri, Map<String, Instance<?>> cachedSelectors, Blob blob, OutlinkExtractor ol) { // Find outlinks in page Set<Link> outlinks = extractOutlinks(cachedSelectors, blob, ol); log.trace("Finding outlinks for url {}: {}", uri, outlinks); // Filter outlinks Set<Link> filteredOutlinks = null; if (outlinks != null) { Stream<Link> stream = outlinks.stream().filter(l -> l != null && l.getUri() != null); if (spider.getFilters() != null && CollectionUtils.isNotEmpty(spider.getFilters().getLinks())) { stream = stream//from w ww . j a v a 2 s .c o m .filter(link -> spider.getFilters().getLinks().stream().allMatch(f -> f.isValid(link))); } filteredOutlinks = stream.collect(Collectors.toSet()); } Set<Link> allFilteredOutlinks = null; if (filteredOutlinks != null) { Set<Uri> res = MetadataStores.get(spider.getId()) .deduplicate(filteredOutlinks.stream().map(l -> l.getUri()).collect(Collectors.toList())); allFilteredOutlinks = filteredOutlinks.stream().filter(f -> res.contains(f.getUri())) .collect(Collectors.toSet()); } log.trace("And filtering {}", allFilteredOutlinks); return Pair.of(outlinks, allFilteredOutlinks); }
From source file:io.gravitee.repository.jdbc.JdbcUserRepository.java
public Set<User> findByTeam(String teamName) throws TechnicalException { final TeamJpa team = internalJpaTeamRepository.findOne(teamName); if (team == null) { throw new IllegalStateException(format("The team '%s' does not exist", teamName)); }// w ww . java 2 s . c om final List<TeamMemberJpa> members = team.getMembers(); final Set<User> users = members.stream().map(member -> userJpaConverter.convertTo(member.getMember())) .collect(Collectors.toSet()); return users; }
From source file:org.shredzone.cilla.plugin.social.manager.SocialHandlerManager.java
/** * Sets up the manager. All beans are scanned for {@link SocialHandler} annotations. * If found, {@link SocialBookmark} annotations will further describe the social * bookmark service.//from w w w. ja v a 2 s .c o m */ @PostConstruct public void setup() { Set<String> blacklistSet = Arrays.stream(blacklist.split("[,;]+")).map(String::trim) .filter(it -> !it.isEmpty()).collect(Collectors.toSet()); Collection<Object> beans = applicationContext.getBeansWithAnnotation(SocialHandler.class).values(); for (Object bean : beans) { SocialHandler shAnno = bean.getClass().getAnnotation(SocialHandler.class); if (shAnno != null) { for (Method method : bean.getClass().getMethods()) { SocialBookmark bookmarkAnno = AnnotationUtils.findAnnotation(method, SocialBookmark.class); if (bookmarkAnno != null) { processBookmarkHandler(bean, method, bookmarkAnno, blacklistSet); } } } } }
From source file:net.e2.bw.servicereg.ldap.model.CachedOrganization.java
/** * Will make a copy of this organization and initialize the roles of a * specific user and save it to the userRoles list. * @param userId the user/*from ww w. j a v a 2 s . c o m*/ * @return the updated copy of this organization entry */ public UserOrganization toUserOrganization(String userId) { UserOrganization org = new UserOrganization(); // Copy the organization fields copyTo(org); org.setUserId(userId); // Since roles are hierarchical, e.g. "admin" implies "user", compute // the effective set of roles Set<String> roles = roleUserMap.keySet().stream().filter(r -> roleUserMap.get(r).contains(userId)) .flatMap(r -> Roles.effectiveOrganizationRoles(r).stream()).collect(Collectors.toSet()); // The "user" role is implied by membership, unless you have the "invited" or "applicant" roles if (getMemberIds().contains(userId) && !roles.contains(OrganizationRole.applicant.name()) && !roles.contains(OrganizationRole.invited.name())) { roles.add(OrganizationRole.user.name()); } org.setUserRoles(roles.toArray(new String[roles.size()])); List<String> applicants = roleUserMap.get(OrganizationRole.applicant.name()); org.setApplicantNo(applicants == null ? 0 : applicants.size()); return org; }
From source file:com.avast.server.hdfsshell.ui.ShellPromptProvider.java
private boolean isRootPrompt() { final String whoami = this.getWhoami(); final String[] groupsForUser = contextCommands.getGroupsForUser(whoami); if (groupsForUser.length == 0) { //make guess return "root".equals(whoami) || "hdfs".equals(whoami); }/*from ww w.j ava2 s . co m*/ final String[] groups = contextCommands.getConfiguration() .get("dfs.permissions.superusergroup", "supergroup").split(","); final Set<String> adminGroups = Arrays.stream(groups).map(String::trim).collect(Collectors.toSet()); adminGroups.add("Administrators");//for Windows adminGroups.add("hdfs");//special cases adminGroups.add("root"); return Arrays.stream(groupsForUser).anyMatch(adminGroups::contains); }
From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.artifact.ArtifactReplacer.java
public ReplaceResult replaceAll(KubernetesManifest input, List<Artifact> artifacts) { log.info("Doing replacement on {} using {}", input, artifacts); DocumentContext document;/*from w ww . j a v a 2 s. c om*/ try { document = JsonPath.using(configuration).parse(mapper.writeValueAsString(input)); } catch (JsonProcessingException e) { log.error("Malformed manifest", e); throw new RuntimeException(e); } Set<Artifact> replacedArtifacts = replacers.stream().map( r -> artifacts.stream().filter(a -> r.replaceIfPossible(document, a)).collect(Collectors.toSet())) .flatMap(Collection::stream).collect(Collectors.toSet()); try { return ReplaceResult.builder() .manifest(mapper.readValue(document.jsonString(), KubernetesManifest.class)) .boundArtifacts(replacedArtifacts).build(); } catch (IOException e) { log.error("Malformed Document Context", e); throw new RuntimeException(e); } }
From source file:com.siemens.sw360.datahandler.couchdb.AttachmentConnector.java
private Set<String> getAttachmentContenIds(Collection<Attachment> attachments) { return nullToEmptyCollection(attachments).stream().map(Attachment::getAttachmentContentId) .collect(Collectors.toSet()); }
From source file:nu.yona.server.properties.YonaProperties.java
public void setSupportedLocales(String supportedLocales) { this.supportedLocales.addAll(Arrays.asList(supportedLocales.split(",")).stream().map(Locale::forLanguageTag) .collect(Collectors.toSet())); }
From source file:pt.ist.fenixedu.delegates.ui.services.DelegateService.java
public DelegateSearchBean generateNewBean(DelegateSearchBean delegateSearchBean) { ExecutionYear executionYear = delegateSearchBean.getExecutionYear(); Degree degree = delegateSearchBean.getDegree(); DegreeType degreeType = delegateSearchBean.getDegreeType(); delegateSearchBean.setExecutionYears(Bennu.getInstance().getExecutionYearsSet().stream() .sorted(ExecutionYear.REVERSE_COMPARATOR_BY_YEAR).collect(Collectors.toList())); Set<DegreeType> aux = executionYear.getExecutionDegreesSet().stream() .map(d -> d.getDegree().getDegreeType()).collect(Collectors.toSet()); delegateSearchBean.setDegreeTypes(aux.stream().collect(Collectors.toList())); if (degreeType == null && (degree == null || EmptyDegree.class.isInstance(degree))) { delegateSearchBean.setDegrees(executionYear.getExecutionDegreesSet().stream().map(d -> d.getDegree()) .sorted(Degree.COMPARATOR_BY_NAME).collect(Collectors.toList())); delegateSearchBean.setDegree(delegateSearchBean.getDegrees().iterator().next()); delegateSearchBean.setDegreeType(delegateSearchBean.getDegree().getDegreeType()); return delegateSearchBean; }/*from w w w.java2 s. c o m*/ if (degree == null || EmptyDegree.class.isInstance(degree)) { delegateSearchBean.setDegrees(executionYear.getExecutionDegreesSet().stream() .filter(d -> d.getDegree().getDegreeType().equals(degreeType)).map(d -> d.getDegree()) .sorted(Degree.COMPARATOR_BY_NAME).collect(Collectors.toList())); delegateSearchBean.setDegree(delegateSearchBean.getDegrees().iterator().next()); return delegateSearchBean; } delegateSearchBean.setDegrees(executionYear.getExecutionDegreesSet().stream() .filter(d -> d.getDegree().getDegreeType().equals(degreeType)).map(d -> d.getDegree()) .sorted(Degree.COMPARATOR_BY_NAME).collect(Collectors.toList())); return delegateSearchBean; }