List of usage examples for java.util.stream Collectors toSet
public static <T> Collector<T, ?, Set<T>> toSet()
From source file:es.upv.grycap.relevantdata.core.instance.RdInstance.java
/** * Convenient constructor which is available inside the package, allowing factory methods to create new instances of this class, * optionally passing a path to an external file with the configuration properties. * @param confname - configuration filename *//* ww w. j av a 2 s. c o m*/ RdInstance(final @Nullable String confname) { // load configuration properties config = new Configurer().loadConfig(confname, "relevantdata"); if (LOGGER.isTraceEnabled()) { LOGGER.trace(config.root().render()); } else { LOGGER.info("Configuration: " + config.getObject("relevantdata").render(concise())); } // create services final List<RdService> services = config.getStringList("relevantdata.services").stream() .map(StringUtils::trimToNull).filter(Objects::nonNull).collect(Collectors.toSet()).stream() .map(this::newService).collect(Collectors.toList()); checkState(services != null && !services.isEmpty(), "At least one service expected"); serviceManager = new ServiceManager(services); serviceManager.addListener(new Listener() { @Override public void healthy() { final double startupTime = serviceManager.startupTimes().entrySet().stream() .mapToDouble(Map.Entry::getValue).sum(); LOGGER.info("Services started in: " + ((long) startupTime / 1000l) + " seconds."); } }, MoreExecutors.directExecutor()); // add termination logic Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { serviceManager.stopAsync().awaitStopped(5, TimeUnit.SECONDS); LOGGER.info("Service manager was stopped."); } catch (TimeoutException timeout) { LOGGER.info("Stopping timed out."); } } }); // start services serviceManager.startAsync(); }
From source file:io.gravitee.repository.redis.management.internal.impl.ApiRedisRepositoryImpl.java
@Override public Set<RedisApi> findByGroups(List<String> groups) { Set<Object> keys = new HashSet<>(); groups.forEach(group -> keys.addAll(redisTemplate.opsForSet().members(REDIS_KEY + ":group:" + group))); List<Object> apiObjects = redisTemplate.opsForHash().multiGet(REDIS_KEY, keys); return apiObjects.stream().filter(Objects::nonNull).map(event -> convert(event, RedisApi.class)) .collect(Collectors.toSet()); }
From source file:de.ks.flatadocdb.session.dirtycheck.DirtyChecker.java
public Collection<SessionEntry> findDirty(Collection<SessionEntry> values) { return values.stream()// .filter(e -> !insertions.contains(e.getObject()))// .filter(e -> !deletions.contains(e.getObject()))// .filter(e -> {/*from w w w . ja va 2 s .c om*/ EntityDescriptor entityDescriptor = e.getEntityDescriptor(); EntityPersister persister = entityDescriptor.getPersister(); byte[] fileContents = persister.createFileContents(repository, entityDescriptor, e.getObject()); byte[] md5 = DigestUtils.md5(fileContents); boolean dirty = !Arrays.equals(md5, e.getMd5()); if (dirty) { log.debug("Found dirty entity {} {}", e.getObject(), e.getFileName()); } else { log.trace("Non-dirty entity {} {}", e.getObject(), e.getFileName()); } return dirty; }).collect(Collectors.toSet()); }
From source file:org.openlmis.fulfillment.ExposedMessageSourceIntegrationTest.java
private Set<String> getPropertyKeys() { return exposedMessageSource.getAllMessages(Locale.ENGLISH).keySet().stream() // those keys are used in jasper templates and they don't need constant values .filter(key -> !startsWith(key, "fulfillment.print.proofOfDelivery")) .filter(key -> !startsWith(key, "fulfillment.header")).collect(Collectors.toSet()); }
From source file:com.netflix.spectator.aws.SpectatorRequestMetricCollectorTest.java
/** Returns a set of all values for a given tag key. */ private Set<String> valueSet(String k) { return registry.stream().map(m -> Utils.getTagValue(m.id(), k)).filter(v -> v != null) .collect(Collectors.toSet()); }
From source file:com.sonicle.webtop.core.app.util.ClassHelper.java
public static Set<Annotation> getClassAnnotations(Class clazz, Class annotationClass) { if (clazz == null) return null; Annotation[] annotations = clazz.getAnnotationsByType(annotationClass); return Arrays.stream(annotations).unordered().collect(Collectors.toSet()); }
From source file:io.pivotal.strepsirrhini.chaoslemur.infrastructure.StandardDirectorUtils.java
@SuppressWarnings("unchecked") @Override// www. java 2s .c om public Set<String> getDeployments() { URI deploymentsUri = UriComponentsBuilder.fromUri(this.root).path("deployments").build().toUri(); List<Map<String, String>> deployments = this.restTemplate.getForObject(deploymentsUri, List.class); return deployments.stream().map(deployment -> deployment.get("name")).collect(Collectors.toSet()); }
From source file:org.ow2.proactive.connector.iaas.cloud.provider.jclouds.openstack.OpenstackJCloudsProvider.java
@Override public Set<Instance> createInstance(Infrastructure infrastructure, Instance instance) { ComputeService computeService = getComputeServiceFromInfastructure(infrastructure); NovaApi novaApi = computeService.getContext().unwrapApi((NovaApi.class)); ServerApi serverApi = novaApi.getServerApi(region); CreateServerOptions serverOptions = createOptions(instance); return IntStream.rangeClosed(1, Integer.valueOf(instance.getNumber())) .mapToObj(i -> createOpenstackInstance(instance, serverApi, serverOptions)) .map(server -> instanceCreatorFromNodeMetadata.apply(server, infrastructure.getId())) .collect(Collectors.toSet()); }
From source file:com.netflix.spinnaker.fiat.permissions.DefaultPermissionsResolver.java
@Override public UserPermission resolveAndMerge(@NonNull ExternalUser user) { List<Role> roles; try {/*from w w w . j a va 2s .c o m*/ log.debug("Loading roles for user " + user); roles = userRolesProvider.loadRoles(user.getId()); log.debug("Got roles " + roles + " for user " + user); } catch (ProviderException pe) { throw new PermissionResolutionException("Failed to resolve user permission for user " + user.getId(), pe); } Set<Role> combo = Stream.concat(roles.stream(), user.getExternalRoles().stream()) .collect(Collectors.toSet()); return getUserPermission(user.getId(), combo); }
From source file:com.evolveum.midpoint.repo.sql.helpers.NameResolutionHelper.java
public void resolveNamesIfRequested(Session session, List<? extends PrismContainerValue> containerValues, Collection<SelectorOptions<GetOperationOptions>> options) { List<ItemPath> pathsToResolve = getPathsToResolve(options); if (pathsToResolve.isEmpty()) { return;/* ww w .ja v a 2 s. c om*/ } final Set<String> oidsToResolve = new HashSet<>(); Visitor oidExtractor = visitable -> { if (visitable instanceof PrismReferenceValue) { PrismReferenceValue value = (PrismReferenceValue) visitable; if (!ItemPath.containsSubpathOrEquivalent(pathsToResolve, value.getPath())) { return; } if (value.getTargetName() != null) { // just for sure return; } if (value.getObject() != null) { // improbable but possible value.setTargetName(value.getObject().getName()); return; } if (value.getOid() == null) { // shouldn't occur as well return; } oidsToResolve.add(value.getOid()); } }; Set<PrismContainerValue> roots = containerValues.stream().map(pcv -> pcv.getRootValue()) .collect(Collectors.toSet()); roots.forEach(root -> root.accept(oidExtractor)); Map<String, PolyString> oidNameMap = new HashMap<>(); List<String> batch = new ArrayList<>(); for (Iterator<String> iterator = oidsToResolve.iterator(); iterator.hasNext();) { batch.add(iterator.next()); if (batch.size() >= MAX_OIDS_TO_RESOLVE_AT_ONCE || !iterator.hasNext()) { Query query = session.getNamedQuery("resolveReferences"); query.setParameterList("oid", batch); @SuppressWarnings({ "unchecked", "raw" }) List<Object[]> results = query.list(); // returns oid + name for (Object[] result : results) { String oid = (String) result[0]; RPolyString name = (RPolyString) result[1]; oidNameMap.put(oid, new PolyString(name.getOrig(), name.getNorm())); } batch.clear(); } } if (!oidNameMap.isEmpty()) { Visitor nameSetter = visitable -> { if (visitable instanceof PrismReferenceValue) { PrismReferenceValue value = (PrismReferenceValue) visitable; if (value.getTargetName() == null && value.getOid() != null) { value.setTargetName(oidNameMap.get(value.getOid())); } } }; roots.forEach(root -> root.accept(nameSetter)); } }