Example usage for java.util.stream Collectors toSet

List of usage examples for java.util.stream Collectors toSet

Introduction

In this page you can find the example usage for java.util.stream Collectors toSet.

Prototype

public static <T> Collector<T, ?, Set<T>> toSet() 

Source Link

Document

Returns a Collector that accumulates the input elements into a new Set .

Usage

From source file:com.hortonworks.streamline.streams.security.impl.DefaultStreamlineAuthorizer.java

@SuppressWarnings("unchecked")
@Override/* w w w  . j  a v  a2 s.  c  om*/
public void init(Map<String, Object> config) {
    LOG.info("Initializing DefaultStreamlineAuthorizer with config {}", config);
    catalogService = (SecurityCatalogService) config.get(CONF_CATALOG_SERVICE);
    adminUsers = ((Set<String>) config.get(CONF_ADMIN_PRINCIPALS)).stream().map(SecurityUtil::getUserName)
            .collect(Collectors.toSet());
    LOG.info("Admin users: {}", adminUsers);
    mayBeAddAdminUsers();
    mayBeAssignAdminRole();
}

From source file:nu.yona.server.test.util.BaseSpringIntegrationTest.java

private Set<CrudRepository<?, ?>> filterForCrudRepositories(Collection<Repository<?, ?>> values) {
    return values.stream().filter(r -> r instanceof CrudRepository).map(r -> (CrudRepository<?, ?>) r)
            .collect(Collectors.toSet());
}

From source file:io.gravitee.repository.redis.management.internal.impl.ApiRedisRepositoryImpl.java

@Override
public Set<RedisApi> findByVisibility(String visibility) {
    Set<Object> keys = redisTemplate.opsForSet().members(REDIS_KEY + ":visibility:" + visibility);
    List<Object> apiObjects = redisTemplate.opsForHash().multiGet(REDIS_KEY, keys);

    return apiObjects.stream().map(event -> convert(event, RedisApi.class)).collect(Collectors.toSet());
}

From source file:io.gravitee.repository.redis.management.internal.impl.ApiKeyRedisRepositoryImpl.java

@Override
public Set<RedisApiKey> findBySubscription(String application) {
    Set<Object> keys = redisTemplate.opsForSet().members(REDIS_KEY + ":subscription:" + application);
    List<Object> apiKeyObjects = redisTemplate.opsForHash().multiGet(REDIS_KEY, keys);

    return apiKeyObjects.stream().map(apiKey -> convert(apiKey, RedisApiKey.class)).collect(Collectors.toSet());
}

From source file:io.gravitee.repository.redis.management.internal.impl.GroupRedisRepositoryImpl.java

@Override
public Set<RedisGroup> findAll() {
    return redisTemplate.opsForHash().entries(REDIS_KEY).values().stream()
            .map(object -> convert(object, RedisGroup.class)).collect(Collectors.toSet());
}

From source file:com.athina.queue.manager.entity.JobQueueManager.java

public Set<JobKey> getJobKeys() {
    try {/*from w  w w.j ava2 s .c om*/
        return quartzScheduler.getJobKeys(GroupMatcher.anyJobGroup()).stream().map(JobKey::fromQuartzJobKey)
                .collect(Collectors.toSet());
    } catch (SchedulerException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.zalando.baigan.proxy.ConfigurationBeanDefinitionRegistrar.java

@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
        BeanDefinitionRegistry registry) {
    final AnnotationAttributes annotationAttributes = AnnotationAttributes
            .fromMap(importingClassMetadata.getAnnotationAttributes(ConfigurationServiceScan.class.getName()));

    if (annotationAttributes == null || annotationAttributes.isEmpty()) {
        throw new IllegalArgumentException("ConfigurationServiceScan requires at least 1 scan package.");
    }/*from  w w w .ja  v a2 s  .  c o m*/

    final List<String> basePackages = Lists.newArrayList();
    basePackages.addAll(Arrays.asList(annotationAttributes.getStringArray("value")));
    basePackages.addAll(Arrays.asList(annotationAttributes.getStringArray("basePackages")));

    final Set<String> saneSet = basePackages.stream().filter(str -> !StringUtils.isEmpty(str))
            .collect(Collectors.toSet());

    createAndRegisterBeanDefinitions(saneSet, registry);

}

From source file:org.trustedanalytics.servicecatalog.service.ApplicationsService.java

/**
 * @param space unique space identifier/*  w  w w  .j  a v a 2 s. c o  m*/
 * @param serviceFilter service filter
 * @return applications within space matching given space filter
 */
public Collection<CcApp> getSpaceAppsByService(UUID space, Predicate<CcServiceInstance> serviceFilter) {
    final CcSummary summary = ccOperations.getSpaceSummary(space);

    final Set<String> services = summary.getServiceInstances().stream().filter(serviceFilter)
            .map(CcServiceInstance::getName).collect(Collectors.toSet());

    return summary.getApps().stream().filter(app -> app.getServiceNames().stream().anyMatch(services::contains))
            .collect(Collectors.toList());
}

From source file:mtsar.processors.task.InverseCountAllocator.java

@Override
@Nonnull/*  w  w  w  .ja  v  a 2 s.co  m*/
public Optional<TaskAllocation> allocate(@Nonnull Worker worker, @Nonnegative int n) {
    requireNonNull(stage, "the stage provider should not provide null");
    final Set<Integer> answered = answerDAO.listForWorker(worker.getId(), stage.getId()).stream()
            .map(Answer::getTaskId).collect(Collectors.toSet());

    final Map<Integer, Integer> counts = countDAO.getCountsSQL(stage.getId()).stream()
            .filter(pair -> !answered.contains(pair.getKey()))
            .collect(Collectors.toMap(Pair::getKey, Pair::getValue));

    final List<Integer> ids = filterTasks(counts);
    final int taskRemaining = ids.size();

    if (ids.isEmpty())
        return Optional.empty();
    if (taskRemaining > n)
        ids.subList(n, ids.size()).clear();
    final List<Task> tasks = taskDAO.select(ids, stage.getId());

    final int taskCount = taskDAO.count(stage.getId());
    final TaskAllocation allocation = new TaskAllocation.Builder().setWorker(worker).addAllTasks(tasks)
            .setTaskRemaining(taskRemaining).setTaskCount(taskCount).build();
    return Optional.of(allocation);
}

From source file:com.haulmont.cuba.web.widgets.CubaDateField.java

@Override
protected void updateInternal(String newDateString, Map<String, Integer> resolutions) {
    // CAUTION: copied from AbstractDateField
    Set<String> resolutionNames = getResolutions().map(Enum::name).collect(Collectors.toSet());
    resolutionNames.retainAll(resolutions.keySet());
    if (!isReadOnly() && (!resolutionNames.isEmpty() || newDateString != null)) {

        // Old and new dates
        final LocalDate oldDate = getValue();

        LocalDate newDate;/*  w  w w . j  a  va 2  s. c  o  m*/

        String mask = StringUtils.replaceChars(getState(false).dateMask, "#U", "__");
        if ("".equals(newDateString) || mask.equals(newDateString)) {

            newDate = null;
        } else {
            newDate = reconstructDateFromFields(resolutions, oldDate);
        }

        boolean hasChanges = !Objects.equals(dateString, newDateString) || !Objects.equals(oldDate, newDate);

        if (hasChanges) {
            dateString = newDateString;
            currentParseErrorMessage = null;
            if (newDateString == null || newDateString.isEmpty() || mask.equals(newDateString)) {
                setValue(newDate, true);
            } else {
                // invalid date string
                if (resolutions.isEmpty()) {
                    Result<LocalDate> parsedDate = handleUnparsableDateString(dateString);
                    parsedDate.ifOk(v -> setValue(v, true));
                    if (parsedDate.isError()) {
                        dateString = null;
                        currentParseErrorMessage = parsedDate.getMessage().orElse("Parsing error");

                        if (!isDifferentValue(null)) {
                            doSetValue(null);
                        } else {
                            setValue(null, true);
                        }
                    }
                } else {
                    setValue(newDate, true);
                }
            }
        }
    }
}