List of usage examples for java.util.stream Collectors toSet
public static <T> Collector<T, ?, Set<T>> toSet()
From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.view.provider.KubernetesV2LoadBalancerProvider.java
private Set<KubernetesV2LoadBalancer> fromLoadBalancerCacheData(List<CacheData> loadBalancerData) { List<CacheData> serverGroupData = kindMap.translateSpinnakerKind(SERVER_GROUPS).stream() .map(kind -> cacheUtils.loadRelationshipsFromCache(loadBalancerData, kind.toString())) .flatMap(Collection::stream).collect(Collectors.toList()); List<CacheData> instanceData = kindMap.translateSpinnakerKind(INSTANCES).stream() .map(kind -> cacheUtils.loadRelationshipsFromCache(serverGroupData, kind.toString())) .flatMap(Collection::stream).collect(Collectors.toList()); Map<String, List<CacheData>> loadBalancerToServerGroups = cacheUtils.mapByRelationship(serverGroupData, LOAD_BALANCERS);//from w ww . ja v a 2s . c o m Map<String, List<CacheData>> serverGroupToInstances = cacheUtils.mapByRelationship(instanceData, SERVER_GROUPS); return loadBalancerData.stream() .map(cd -> KubernetesV2LoadBalancer.fromCacheData(cd, loadBalancerToServerGroups.getOrDefault(cd.getId(), new ArrayList<>()), serverGroupToInstances)) .filter(Objects::nonNull).collect(Collectors.toSet()); }
From source file:org.hawkular.apm.api.model.trace.Node.java
/** * This method returns the set of properties having the * supplied property name.//from ww w . j a v a2 s . co m * * @param name The property name * @return The set of properties with the supplied name */ public Set<Property> getProperties(String name) { return this.properties.stream().filter(property -> property.getName().equals(name)) .collect(Collectors.toSet()); }
From source file:com.haulmont.cuba.core.sys.dbupdate.ScriptScanner.java
public List<String> getModuleDirs() { try {/* ww w . j ava 2s . com*/ Resource[] resources = createAppropriateResourceResolver() .getResources(dbScriptsDirectoryForSearch() + "/**/*.*"); String dbDirPath = dbScriptDirectoryPath(); log.trace("DB scripts directory: {}", dbDirPath); List<String> modules = Arrays.stream(resources).map(resource -> { try { String decodedUrl = URLEncodeUtils.decodeUtf8(resource.getURL().toString()); String resourcePath = decodedUrl.replaceFirst(".+?:", ""); Matcher matcher = Pattern.compile(".*" + Pattern.quote(dbDirPath) + "/?(.+?)/.*") .matcher(resourcePath); return matcher.find() ? matcher.group(1) : null; } catch (IOException e) { throw new RuntimeException("An error occurred while detecting modules", e); } }).filter(element -> element != null).collect(Collectors.toSet()).stream().sorted() .collect(Collectors.toList()); if (modules.isEmpty()) { throw new RuntimeException(String.format( "No existing modules found. " + "Please check if [%s] contains DB scripts.", dbDirPath)); } log.trace("Found modules: {}", modules); return modules; } catch (IOException e) { throw new RuntimeException("An error occurred while detecting modules", e); } }
From source file:com.bitbreeds.webrtc.sctp.impl.SendService.java
/** * @param gaps retrieved gaps/* ww w .j a va 2s.c om*/ * @param duplicates TODO not sure what to do with these */ public void updateAcknowledgedTSNS(long cumulativeTsnAck, List<SackUtil.GapAck> gaps, List<Long> duplicates) { final HashPMap<Long, TimeData> sent = sentTSNS; logger.debug("Before removal contains: " + sent); logger.debug("Updating acks with cumulative " + cumulativeTsnAck + " and gaps " + gaps); /** * Filter and remove those with TSN below cumulativeTsnAck. */ final Collection<Long> ls = sent.keySet().stream().filter(j -> j <= cumulativeTsnAck) .collect(Collectors.toSet()); synchronized (dataMutex) { sentTSNS = sentTSNS.minusAll(ls); } removeAllAcknowledged(cumulativeTsnAck, gaps); logger.debug("After remove it contains: " + sentTSNS); }
From source file:org.fcrepo.apix.jena.impl.JenaServiceRegistry.java
@Override public void update() { // For all resources in the registry, get the URIs of everything that calls itself a Service, or is explicitly // registered as a service final Set<URI> serviceURIs = Stream.concat(super.list().stream().map(this::get).map(Util::parse) .flatMap(m -> m.listSubjectsWithProperty(m.getProperty(RDF_TYPE), m.getResource(CLASS_SERVICE)) .mapWith(Resource::getURI).toSet().stream().map(URI::create)), objectResourcesOf(null, PROP_CONTAINS_SERVICE, parse(this.get(registryContainer))).stream()) .collect(Collectors.toSet()); // Map canonical URI to service resource. If multiple service resources // indicate the same canonical URI, pick one arbitrarily. final Map<URI, URI> canonical = serviceURIs.stream().flatMap(this::attemptLookupService) .collect(Collectors.toMap(s -> s.canonicalURI(), s -> s.uri(), (a, b) -> a)); canonicalUriMap.putAll(canonical);/*from w w w .j av a 2 s .c om*/ canonicalUriMap.keySet().removeIf(k -> !canonical.containsKey(k)); }
From source file:nu.yona.server.subscriptions.service.BuddyService.java
public Set<BuddyDto> getBuddiesOfUserThatAcceptedSending(UUID forUserId) { return getBuddiesOfUser(forUserId).stream().filter(b -> b.getSendingStatus() == Status.ACCEPTED) .collect(Collectors.toSet()); }
From source file:com.sri.tasklearning.ui.core.term.ExerciseStepParameter.java
public Set<ExerciseStepParameter> getEqualByValueParameters() { Stream<ExerciseStepParameter> params = ownerExerciseModel.getExerciseStepParameters().stream(); return (Set<ExerciseStepParameter>) params.filter(x -> x.isEqualParameter(this) && x != this) .collect(Collectors.toSet()); }
From source file:com.adobe.acs.commons.it.build.ScrMetadataIT.java
@Test public void test() throws Exception { List<String> problems = new ArrayList<>(); DescriptorList current = getDescriptorsFromCurrent(); if (current != null) { final DescriptorList latestRelease = getDescriptorsFromLatestRelease(); current.stream().forEach(cd -> { Optional<Descriptor> fromLatest = latestRelease.stream().filter(d -> d.name.equals(cd.name)) .findFirst();//from w w w.j a va2 s. c o m if (fromLatest.isPresent()) { problems.addAll(compareDescriptors(cd, fromLatest.get())); } else { System.out.printf("Component %s is only in current. Assuming OK.\n", cd.name); } if (cd.factory) { Optional<Property> nameHint = cd.properties.stream().filter(cp -> cp.name.equals(PROP_NAMEHINT)) .findFirst(); if (nameHint.isPresent()) { Set<String> propertyNames = cd.properties.stream().map(cp -> cp.name) .collect(Collectors.toSet()); String nameHintValue = nameHint.get().value; Matcher variableMatcher = EXTRACT_VARIABLES.matcher(nameHintValue); while (variableMatcher.find()) { String variable = variableMatcher.group(1); if (!propertyNames.contains(variable)) { problems.add( String.format("Property %s referenced in nameHint in %s is not defined.", variable, cd.name)); } } } else { problems.add(String.format("Component factory %s doesn't have a namehint.", cd.name)); } } }); if (!problems.isEmpty()) { problems.forEach(System.err::println); TestCase.fail(); } } }
From source file:com.hortonworks.streamline.streams.security.service.SecurityCatalogService.java
public Collection<User> listUsers(Role role) { List<QueryParam> qps = QueryParam.params(UserRole.ROLE_ID, role.getId().toString()); return listUserRoles(qps).stream().map(ur -> getUser(ur.getUserId())).collect(Collectors.toSet()); }
From source file:nu.yona.server.analysis.service.ActivityService.java
private void createInactivityEntities(Set<IntervalInactivityDto> missingInactivities) { Map<UUID, Set<IntervalInactivityDto>> activitiesByUserAnonymizedId = missingInactivities.stream() .collect(Collectors.groupingBy(mia -> mia.getUserAnonymizedId().get(), Collectors.toSet())); activitiesByUserAnonymizedId/*from w w w . ja v a 2 s .c o m*/ .forEach((u, mias) -> analysisEngineProxyService.createInactivityEntities(u, mias)); }