List of usage examples for java.util Set stream
default Stream<E> stream()
From source file:org.age.services.topology.internal.DefaultTopologyService.java
@Override @NonNull/* w ww.ja va 2 s . co m*/ public Set<String> neighbours() { if (!hasTopology()) { throw new IllegalStateException("Topology not ready."); } final DirectedGraph<String, DefaultEdge> graph = getCurrentTopologyGraph(); final Set<DefaultEdge> outEdges = graph.outgoingEdgesOf(identityService.nodeId()); return outEdges.stream().map(graph::getEdgeTarget).collect(Collectors.toSet()); }
From source file:de.richtercloud.validation.tools.ValidationToolsTest.java
@Property public void testBuildConstraintVioloationMessage(@ForAll boolean bean2Null, @ForAll int bean2Property0, @ForAll boolean bean1Null, @ForAll boolean bean1Bean2sNull, @ForAll boolean bean1bean2sEmpty, @ForAll @WithNull(0.5) String bean0Property0, @ForAll boolean bean0Valid, @ForAll boolean bean2Valid) throws Exception { LOGGER.info("testBuildConstraintVioloationMessage"); LOGGER.trace("testBuildConstraintVioloationMessage bean2Null: {}", bean2Null); LOGGER.trace("testBuildConstraintVioloationMessage bean2Property0: {}", bean2Property0); LOGGER.trace("testBuildConstraintVioloationMessage bean1Null: {}", bean1Null); LOGGER.trace("testBuildConstraintVioloationMessage bean1Bean2sNull: {}", bean1Bean2sNull); LOGGER.trace("testBuildConstraintVioloationMessage bean1bean2sEmpty: {}", bean1bean2sEmpty); LOGGER.trace("testBuildConstraintVioloationMessage bean0Property0: {}", bean0Property0); LOGGER.trace("testBuildConstraintVioloationMessage bean0Valid: {}", bean0Valid); LOGGER.trace("testBuildConstraintVioloationMessage bean2Valid: {}", bean2Valid); Bean0Validator.retValue = bean0Valid; Bean2Validator.retValue = bean2Valid; Bean2 bean2;//from w w w . j a v a 2 s . c o m if (bean2Null) { bean2 = null; } else { bean2 = new Bean2(bean2Property0); } Bean1 bean1; if (bean1Null) { bean1 = null; } else { List<Bean2> bean1Bean2s; if (bean1Bean2sNull) { bean1Bean2s = null; } else { //Bean1.bean2s has @Min(1) bean1Bean2s = new ArrayList<>(); if (!bean1bean2sEmpty) { bean1Bean2s.add(bean2); } } bean1 = new Bean1(bean1Bean2s); } Bean0 bean0 = new Bean0(bean1, bean0Property0); Set<ConstraintViolation<Object>> violations = Validation.buildDefaultValidatorFactory().getValidator() .validate(bean0); FieldRetriever fieldRetriever = new CachedFieldRetriever(); FieldNameLambda fieldNameLambda = field -> "+++" + field.getName() + ",,,"; Map<Path, String> pathDescriptionMap = new HashMap<>(); OutputMode outputMode = OutputMode.PLAIN_TEXT; LOGGER.debug("validations.size: {}", violations.size()); if (violations.isEmpty()) { Assertions.assertThrows(IllegalArgumentException.class, () -> ValidationTools.buildConstraintVioloationMessage(violations, bean0, fieldRetriever, pathDescriptionMap, fieldNameLambda, false, //skipPathes outputMode)); return; } Set<String> messages = new HashSet<>(); if (!bean0Valid) { messages.add("invalid Bean0"); } if (bean0Property0 == null) { messages.add("+++property0,,,: darf nicht null sein"); } if (bean1Null) { messages.add("+++bean1,,,: darf nicht null sein"); } else { if (!bean1Bean2sNull) { //bean1bean2sNull is valid if (!bean1bean2sEmpty) { if (!bean2Null) { if (!bean2Valid) { messages.add("+++bean1,,,: +++bean2s,,,: invalid Bean2"); } if (bean2Property0 < 1) { messages.add( "+++bean1,,,: +++bean2s,,,: +++property0,,,: muss grer oder gleich 1 sein"); } } } else { messages.add("+++bean1,,,: +++bean2s,,,: Bean1.bean2s mustn't be empty"); } } } Set<List<String>> permutations = new HashSet<>(); PermutationIterator<String> textsPermutationIterator = new PermutationIterator<>(messages); textsPermutationIterator.forEachRemaining(permutation -> permutations.add(permutation)); Matcher<String> expResult = anyOf(permutations.stream() .map(permutation -> equalTo( StreamEx.of(permutation).joining("\n", "The following constraints are violated:\n", "\nFix the corresponding values in the components."))) .collect(Collectors.toSet())); String result = ValidationTools.buildConstraintVioloationMessage(violations, bean0, fieldRetriever, pathDescriptionMap, fieldNameLambda, false, //skipPathes outputMode); assertTrue(String.format("result was: %s; expResult was: %s", result, expResult), expResult.matches(result)); }
From source file:com.netflix.spinnaker.clouddriver.ecs.deploy.ops.CreateServerGroupAtomicOperation.java
private void checkRoleTrustRelations(String roleName) { updateTaskStatus("Checking role trust relations for: " + roleName); AmazonIdentityManagement iamClient = getAmazonIdentityManagementClient(); GetRoleResult response = iamClient.getRole(new GetRoleRequest().withRoleName(roleName)); Role role = response.getRole(); Set<IamTrustRelationship> trustedEntities = iamPolicyReader .getTrustedEntities(role.getAssumeRolePolicyDocument()); Set<String> trustedServices = trustedEntities.stream() .filter(trustRelation -> trustRelation.getType().equals("Service")) .map(IamTrustRelationship::getValue).collect(Collectors.toSet()); if (!trustedServices.contains(NECESSARY_TRUSTED_SERVICE)) { throw new IllegalArgumentException( "The " + roleName + " role does not have a trust relationship to ecs-tasks.amazonaws.com."); }/*from www. j a va 2 s . c o m*/ }
From source file:uk.ac.ebi.ep.data.repositories.EnzymePortalCompoundRepositoryImpl.java
@Override public List<String> findEnzymesByCompound(String compoundId) { Set<String> enzymes = new TreeSet<>(); JPAQuery query = new JPAQuery(entityManager); BooleanExpression compound = $.compoundId.equalsIgnoreCase(compoundId); List<EnzymePortalCompound> compounds = query.from($).where(compound).distinct().list($); compounds.parallelStream().forEach(c -> { enzymes.add(c.getUniprotAccession().getAccession()); });/*ww w. j a va2s . c o m*/ return enzymes.stream().distinct().collect(Collectors.toList()); }
From source file:org.artifactory.ui.rest.service.admin.configuration.repositories.replication.ReplicationConfigService.java
private void updateAddedAndRemovedReplications(Set<LocalReplicationDescriptor> replications, String repoKey, MutableCentralConfigDescriptor configDescriptor) { log.info("Updating replication configurations for repo {}", repoKey); // Remove all replication configs for this repo and re-add all newly received ones and do cleanup for // descriptors that had their url changed Set<String> newUrls = replications.stream().map(LocalReplicationDescriptor::getUrl) .collect(Collectors.toSet()); List<LocalReplicationDescriptor> currentLocalReplications = configDescriptor .getMultiLocalReplications(repoKey); cleanupLocalReplications(currentLocalReplications.stream() .filter(replication -> !newUrls.contains(replication.getUrl())).collect(Collectors.toList())); currentLocalReplications.forEach(configDescriptor::removeLocalReplication); replications.forEach(configDescriptor::addLocalReplication); }
From source file:io.acme.solution.infrastructure.repo.ProfileRepositoryImpl.java
@Override public void save(final Profile profile) { log.info("Saving the profile"); PersistentEventEmitter persistentEventEmitter = this.eventEmitterDao.getById(profile.getId()); Set<PersistentEvent> persistentEventSet = new HashSet<>(); Set<Event> eventSet = null; if (persistentEventEmitter == null) { persistentEventEmitter = new PersistentEventEmitter(profile.getId(), profile.getVersion(), profile.getClass().getSimpleName()); } else {// w w w .j av a 2 s. c o m persistentEventEmitter.setVersion(profile.getVersion()); } eventSet = profile.getChangeLog(); persistentEventSet.addAll(eventSet.stream() .map(currentEvent -> new PersistentEvent(currentEvent.getId(), currentEvent.getAggregateId(), currentEvent.getVersion(), currentEvent.getClass().getSimpleName(), currentEvent.getEntries())) .collect(Collectors.toList())); this.eventEmitterDao.save(persistentEventEmitter); this.eventDao.save(persistentEventSet); this.eventPublisher.publish(persistentEventSet); profile.clear(); //TODO Add Snapshot Logic }
From source file:io.pravega.test.integration.MultiReadersEndToEndTest.java
private void runTest(final Set<String> streamNames, final int numParallelReaders, final int numSegments) throws Exception { @Cleanup// ww w.j a v a2s . c o m StreamManager streamManager = StreamManager.create(SETUP_UTILS.getControllerUri()); streamManager.createScope(SETUP_UTILS.getScope()); streamNames.stream().forEach(stream -> { streamManager.createStream(SETUP_UTILS.getScope(), stream, StreamConfiguration.builder().scope(SETUP_UTILS.getScope()).streamName(stream) .scalingPolicy(ScalingPolicy.fixed(numSegments)).build()); log.info("Created stream: {}", stream); }); @Cleanup ClientFactory clientFactory = ClientFactory.withScope(SETUP_UTILS.getScope(), SETUP_UTILS.getControllerUri()); streamNames.stream().forEach(stream -> { EventStreamWriter<Integer> eventWriter = clientFactory.createEventWriter(stream, new IntegerSerializer(), EventWriterConfig.builder().build()); for (Integer i = 0; i < NUM_TEST_EVENTS; i++) { eventWriter.writeEvent(String.valueOf(i), i); } eventWriter.flush(); log.info("Wrote {} events", NUM_TEST_EVENTS); }); final String readerGroupName = "testreadergroup" + RandomStringUtils.randomAlphanumeric(10).toLowerCase(); @Cleanup ReaderGroupManager readerGroupManager = ReaderGroupManager.withScope(SETUP_UTILS.getScope(), SETUP_UTILS.getControllerUri()); readerGroupManager.createReaderGroup(readerGroupName, ReaderGroupConfig.builder().startingTime(0).build(), streamNames); Collection<Integer> read = readAllEvents(numParallelReaders, clientFactory, readerGroupName, numSegments); Assert.assertEquals(NUM_TEST_EVENTS * streamNames.size(), read.size()); // Check unique events. Assert.assertEquals(NUM_TEST_EVENTS, new TreeSet<>(read).size()); readerGroupManager.deleteReaderGroup(readerGroupName); }
From source file:com.blackducksoftware.integration.hub.detect.detector.clang.ClangExtractor.java
private Function<File, Stream<PackageDetails>> dependencyFileToLinuxPackagesConverter(final File sourceDir, final Set<File> unManagedDependencyFiles, final ClangLinuxPackageManager pkgMgr) { return (final File f) -> { logger.trace(String.format("Querying package manager for %s", f.getAbsolutePath())); final DependencyFileDetails dependencyFileWithMetaData = new DependencyFileDetails( fileFinder.isFileUnderDir(sourceDir, f), f); final Set<PackageDetails> linuxPackages = new HashSet<>(pkgMgr.getPackages(sourceDir, executableRunner, unManagedDependencyFiles, dependencyFileWithMetaData)); logger.debug(String.format("Found %d packages for %s", linuxPackages.size(), f.getAbsolutePath())); return linuxPackages.stream(); };//from ww w .ja va 2s .c o m }
From source file:com.siemens.sw360.vulnerabilities.VulnerabilityHandler.java
@Override public List<VulnerabilityDTO> getVulnerabilitiesByProjectIdWithoutIncorrect(String projectId, User user) throws TException { if (!PermissionUtils.isUserAtLeast(UserGroup.USER, user)) { return Collections.emptyList(); }/*from ww w. j a v a 2s .c om*/ Set<String> releaseIds = projectDatabaseHandler.getProjectById(projectId, user).getReleaseIdToUsage() .keySet(); if (releaseIds == null || releaseIds.size() == 0) { return Collections.emptyList(); } return releaseIds.stream().flatMap(id -> getVulsByReleaseIdWithoutIncorrect(id, user).stream()) .collect(Collectors.toList()); }
From source file:gr.cti.android.experimentation.controller.api.SmartphoneController.java
@ResponseBody @RequestMapping(value = "/smartphone/{smartphoneId}/statistics/{experimentId}", method = RequestMethod.GET) public SmartphoneStatisticsDTO getExperimentSmartphoneStatistics( @PathVariable(value = "smartphoneId") final int smartphoneId, @PathVariable(value = "experimentId") final int experimentId) { final Smartphone smartphone = smartphoneRepository.findById(smartphoneId); if (smartphone != null) { final SmartphoneStatisticsDTO smartphoneStatistics = new SmartphoneStatisticsDTO(smartphoneId); smartphoneStatistics.setSensorRules(smartphone.getSensorsRules()); smartphoneStatistics.setReadings(resultRepository.countByDeviceId(smartphone.getId())); if (experimentId != 0) { smartphoneStatistics.setExperimentReadings( resultRepository.countByDeviceIdAndExperimentId(smartphone.getId(), experimentId)); } else {// w ww . j av a 2 s.c o m smartphoneStatistics.setExperimentReadings(0); } final Set<Result> experimentsTotal = new HashSet<>(); final Set<Integer> experimentIdsTotal = new HashSet<>(); experimentsTotal.addAll(resultRepository.findDistinctExperimentIdByDeviceId(smartphone.getId())); experimentIdsTotal .addAll(experimentsTotal.stream().map(Result::getExperimentId).collect(Collectors.toList())); smartphoneStatistics.setExperiments(experimentIdsTotal.size()); smartphoneStatistics.setLast7Days(getLast7DaysTotalReadings(smartphone)); if (experimentId != 0) { smartphoneStatistics.setExperimentRankings(getRankingList("", experimentId)); smartphoneStatistics.setExperimentBadges(newBadgeDTOSet( badgeRepository.findByExperimentIdAndDeviceId(experimentId, smartphone.getId()))); smartphoneStatistics.setExperimentUsage(getExperimentParticipationTime(experimentId, smartphoneId)); } smartphoneStatistics.setBadges(newBadgeDTOSet(badgeRepository.findByDeviceId(smartphone.getId()))); smartphoneStatistics.setRankings(getRankingList("", 0)); smartphoneStatistics.setUsage(getExperimentParticipationTime(0, smartphoneId)); return smartphoneStatistics; } return null; }