List of usage examples for java.util.stream Collectors toSet
public static <T> Collector<T, ?, Set<T>> toSet()
From source file:de.ks.flatadocdb.index.GlobalIndex.java
public Collection<IndexElement> getAllOf(Class<?> entity) { return idToElement.values().stream().filter(v -> v.getEntityClass().equals(entity)) .collect(Collectors.toSet()); }
From source file:com.haulmont.cuba.gui.dynamicattributes.DynamicAttributesGuiTools.java
protected Set<Class> collectEntityClassesWithDynamicAttributes(@Nullable View view) { if (view == null) { return Collections.emptySet(); }//from ww w. jav a 2 s . c o m DynamicAttributes dynamicAttributes = AppBeans.get(DynamicAttributes.class); Metadata metadata = AppBeans.get(Metadata.class); return collectEntityClasses(view, new HashSet<>()).stream() .filter(BaseGenericIdEntity.class::isAssignableFrom).filter(aClass -> !dynamicAttributes .getAttributesForMetaClass(metadata.getClassNN(aClass)).isEmpty()) .collect(Collectors.toSet()); }
From source file:io.pravega.common.cluster.zkImpl.ClusterZKImpl.java
/** * Get the current cluster members./*from ww w. j a v a2 s.co m*/ * * @return List of cluster members. */ @Override @Synchronized public Set<Host> getClusterMembers() { if (!cache.isPresent()) { initializeCache(); } List<ChildData> data = cache.get().getCurrentData(); return data.stream().map(d -> (Host) SerializationUtils.deserialize(d.getData())) .collect(Collectors.toSet()); }
From source file:com.act.lcms.v2.MassChargeCalculatorTest.java
@Test public void testMakeMassChargeMap() throws Exception { List<MassChargeCalculator.MZSource> sources = Arrays.asList( new MassChargeCalculator.MZSource("InChI=1S/C7H7NO2/c8-6-3-1-5(2-4-6)7(9)10/h1-4H,8H2,(H,9,10)"), // PABA new MassChargeCalculator.MZSource("InChI=1S/C7H7NO2/c1-10-7(9)6-3-2-4-8-5-6/h2-5H,1H3")); // Something crazy. MassChargeCalculator.MassChargeMap massChargeMap = MassChargeCalculator.makeMassChargeMap(sources, new HashSet<>(Arrays.asList("M+H", "M+Na"))); Double expectedMonoMass = 137.047679; List<Double> expectedIonMZs = Arrays.asList(138.054979, 160.036879); // M+H and M+Na of PABA // This is package private, but we'll use its ordering to speed testing. List<Double> actualIonMasses = massChargeMap.ionMZsSorted(); assertEqualsWithFPErr("Unique ionic masses match expected list", expectedIonMZs, actualIonMasses); assertEqualsPairWithFPErr("M+H ion mz maps to source mass and ion name", Arrays.asList(Pair.of("M+H", expectedMonoMass)), massChargeMap.ionMZtoMonoMassAndIonName(actualIonMasses.get(0))); assertEqualsPairWithFPErr("M+Na ion mz maps to source mass and ion name", Arrays.asList(Pair.of("M+Na", expectedMonoMass)), massChargeMap.ionMZtoMonoMassAndIonName(actualIonMasses.get(1))); // Test reverse mapping. for (Double ionMZ : actualIonMasses) { assertEquals(String.format("Ionic masses for %f map to two MZSources", ionMZ), new HashSet<>(sources), massChargeMap.ionMZToMZSources(ionMZ)); }//from www . j a v a2s .co m // Test iterators cover all values. assertEqualsWithFPErr("Iterable ionMZs match expected", new HashSet<>(expectedIonMZs), StreamSupport.stream(massChargeMap.ionMZIter().spliterator(), false).collect(Collectors.toSet())); assertEqualsWithFPErr("Iterable monoisotopic masses match expected", Collections.singleton(expectedMonoMass), StreamSupport.stream(massChargeMap.monoisotopicMassIter().spliterator(), false) .collect(Collectors.toSet())); assertEquals("Iterable mzSources match expected", new HashSet<>(sources), StreamSupport .stream(massChargeMap.mzSourceIter().spliterator(), false).collect(Collectors.toSet())); }
From source file:org.apache.ambari.view.web.service.PackageScannerServiceImpl.java
private void updateApplication(Application application, Registry registry) { Optional<Package> packageOptional = packageRepository.findByName(application.getName()); Package pack = packageOptional.orElseGet(() -> { Package pac = new Package(); pac.setName(application.getName()); pac.setRegistry(registry);//from www . ja va 2 s . c o m packageRepository.save(pac); return pac; }); Map<String, Application.Version> versionMap = application.getVersions().stream() .collect(Collectors.toMap(Application.Version::getVersion, Function.identity())); Set<String> versionsFromRepo = pack.getVersions().stream().map(PackageVersion::getVersion) .collect(Collectors.toSet()); versionMap.keySet().forEach(x -> { if (!versionsFromRepo.contains(x)) { PackageVersion packageVersion = new PackageVersion(); Application.Version version = versionMap.get(x); packageVersion.setVersion(version.getVersion()); packageVersion.setDeploymentDefinition(version.getApplicationConfig()); packageVersion.setViewPackage(pack); pack.getVersions().add(packageVersion); versionRepository.save(packageVersion); } }); }
From source file:com.oembedler.moon.graphql.boot.GraphQLAutoConfiguration.java
protected Set<Class<?>> initialSchemaClassesSet() { // scans the application context for classes annotated with {@link GraphQLSchema} Map<String, Object> potentialCandidates = applicationContext.getBeansWithAnnotation(GraphQLSchema.class); return potentialCandidates.values().stream().map(x -> x.getClass()).collect(Collectors.toSet()); }
From source file:org.fcrepo.apix.binding.impl.RuntimeExtensionBinding.java
@Override public Collection<Extension> getExtensionsFor(final WebResource resource, final Collection<Extension> extensions) { try (final InputStream resourceContent = resource.representation()) { final byte[] content = IOUtils.toByteArray(resourceContent); final Set<URI> rdfTypes = extensions.stream().flatMap(RuntimeExtensionBinding::getExtensionResource) .peek(r -> LOG.debug("Examinining the ontology closure of extension {}", r.uri())) .map(ontologySvc::parseOntology) .flatMap(o -> ontologySvc.inferClasses(resource.uri(), cached(resource, content), o).stream()) .peek(rdfType -> LOG.debug("Instance {} is of class {}", resource.uri(), rdfType)) .collect(Collectors.toSet()); return extensions.stream() .peek(e -> LOG.debug("Extension {} binds to instances of {}", e.uri(), e.bindingClass())) .filter(e -> rdfTypes.contains(e.bindingClass())) .peek(e -> LOG.debug("Extension {} bound to instance {} via {}", e.uri(), resource.uri(), e.bindingClass())) .collect(Collectors.toList()); } catch (final IOException e) { throw new RuntimeException(e); }/*from ww w. j ava 2 s . c o m*/ }
From source file:org.ow2.proactive.procci.service.occi.MixinService.java
/** * Add the entity to the database and update the mixins references * * @param entity is an occi entity/*from w ww .ja v a 2 s .c o m*/ * @throws ClientException if there is issue with cloud automation service response */ public void addEntity(Entity entity) { Set<String> entityMixinsTitle = entity.getMixins().stream().map(mixin -> mixin.getTitle()) .collect(Collectors.toSet()); //add entity references cloudAutomationVariablesClient.post(entity.getId(), mapObject(entityMixinsTitle)); //add entity to mixin references entity.getMixins().forEach(mixin -> setMixinReferences(mixin.getRendering())); }
From source file:com.nagarro.core.util.ws.impl.AddonAwareMessageSource.java
/** * Maps each element of <b>addonsPath</b> to valid message bundle path. Result collection is also filtered to remove * empty, invalid and duplicated entries. * * @param addonsPath//w w w . ja v a 2 s . c o m * paths to transform * @param basePath * from where result path should start * @return collection of paths to message bundles */ protected Collection<String> mapAddonLocation(final Collection<String> addonsPath, final String basePath) { return addonsPath.stream().map(p -> formatPath(p, basePath)).filter(StringUtils::isNotBlank) .collect(Collectors.toSet()); }