Example usage for java.util Set stream

List of usage examples for java.util Set stream

Introduction

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

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:nu.yona.server.analysis.service.ActivityService.java

private Set<DayActivityDto> mapDayActivitiesToDtos(Set<DayActivity> dayActivityEntities) {
    return dayActivityEntities.stream().map(e -> DayActivityDto.createInstance(e, LevelOfDetail.DAY_OVERVIEW))
            .collect(Collectors.toSet());
}

From source file:nu.yona.server.analysis.service.ActivityService.java

private Set<WeekActivityDto> mapWeekActivitiesToDtos(Set<WeekActivity> weekActivityEntities) {
    return weekActivityEntities.stream()
            .map(e -> WeekActivityDto.createInstance(e, LevelOfDetail.WEEK_OVERVIEW))
            .collect(Collectors.toSet());
}

From source file:com.thinkbiganalytics.feedmgr.rest.controller.TemplatesRestController.java

/**
 * Returns data about the NiFiTemplate and its processors related to the input connections, along with the Datasources in the flow
 *//*w  w  w  .j a  v  a 2 s  . c o  m*/
@POST
@Path("/nifi/{templateId}/flow-info")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets the flow for the specified template.")
@ApiResponses({
        @ApiResponse(code = 200, message = "Returns the flow.", response = NiFiTemplateFlowResponse.class),
        @ApiResponse(code = 500, message = "NiFi is unavailable.", response = RestResponseStatus.class) })
public Response getNiFiTemplateFlowInfo(@PathParam("templateId") String templateId,
        NiFiTemplateFlowRequest flowRequest) {
    List<TemplateProcessorDatasourceDefinition> templateProcessorDatasourceDefinitions = new ArrayList<>();
    NiFiTemplateFlowResponse response = new NiFiTemplateFlowResponse();
    response.setRequest(flowRequest);
    if (StringUtils.isNotBlank(templateId)) {

        List<RegisteredTemplate.FlowProcessor> processors = feedManagerTemplateService
                .getNiFiTemplateFlowProcessors(templateId, flowRequest.getConnectionInfo());

        Set<DatasourceDefinition> defs = datasourceService.getDatasourceDefinitions();
        Map<String, DatasourceDefinition> datasourceDefinitionMap = new HashMap<>();
        if (defs != null) {
            defs.stream().forEach(def -> datasourceDefinitionMap.put(def.getProcessorType(), def));
        }

        templateProcessorDatasourceDefinitions = processors.stream()
                .filter(processor -> datasourceDefinitionMap.containsKey(processor.getType())).map(p -> {
                    TemplateProcessorDatasourceDefinition definition = new TemplateProcessorDatasourceDefinition();
                    definition.setProcessorType(p.getType());
                    definition.setProcessorName(p.getName());
                    definition.setProcessorId(p.getId());
                    definition.setDatasourceDefinition(datasourceDefinitionMap.get(p.getType()));
                    return definition;
                }).collect(Collectors.toList());

        response.setProcessors(processors);
        response.setTemplateProcessorDatasourceDefinitions(templateProcessorDatasourceDefinitions);
    }
    return Response.ok(response).build();

}

From source file:nu.yona.server.analysis.service.ActivityService.java

private long getTotalPageableItems(Set<BuddyDto> buddies, ChronoUnit timeUnit) {
    return buddies.stream().map(this::getBuddyUserAnonymizedId)
            .map(id -> userAnonymizedService.getUserAnonymized(id))
            .map(ua -> getTotalPageableItems(ua, timeUnit)).max(Long::compareTo).orElse(0L);
}

From source file:io.reactiverse.vertx.maven.plugin.mojos.AbstractRunMojo.java

/**
 * This will resolve the project's test and runtime dependencies along with classes directory to the collection
 * of classpath urls. Notice that resources directory are NOT appended, as they should be copied to tha
 * `target/classes` directory./*from www  .  j av  a2  s.co m*/
 *
 * @return @{link {@link List<URL>}} which will have all the dependencies, classes directory, resources directory etc.,
 * @throws MojoExecutionException any error that might occur while building collection like resolution errors
 */
protected List<URL> getClassPathUrls() throws MojoExecutionException {
    List<URL> classPathUrls = new ArrayList<>();

    try {
        addClassesDirectory(classPathUrls);

        Set<Optional<File>> compileAndRuntimeDeps = extractArtifactPaths(this.project.getDependencyArtifacts());

        Set<Optional<File>> transitiveDeps = extractArtifactPaths(this.project.getArtifacts());

        classPathUrls.addAll(Stream.concat(compileAndRuntimeDeps.stream(), transitiveDeps.stream())
                .filter(Optional::isPresent).map(file -> {
                    try {
                        return file.get().toURI().toURL();
                    } catch (Exception e) {
                        getLog().error("Error building classpath", e);
                    }
                    return null;
                }).filter(Objects::nonNull).collect(Collectors.toList()));
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to run:", e);
    }
    return classPathUrls;
}

From source file:nu.yona.server.analysis.service.ActivityService.java

private <T extends IntervalActivityDto> Optional<T> getActivityForGoal(Set<T> dayActivityDtosAtDate,
        Goal goal) {//from   ww  w  .j  av  a 2  s  .  c o  m
    return dayActivityDtosAtDate.stream().filter(a -> a.getGoalId().equals(goal.getId())).findAny();
}

From source file:nu.yona.server.analysis.service.ActivityService.java

private List<DayActivityOverviewDto<DayActivityWithBuddiesDto>> getUserDayActivityOverviewsWithBuddies(
        UUID userAnonymizedId, Interval interval, Set<BuddyDto> buddies) {
    Set<UUID> userAnonymizedIds = buddies.stream().map(this::getBuddyUserAnonymizedId)
            .collect(Collectors.toSet());
    userAnonymizedIds.add(userAnonymizedId);
    // Goals of the user should only be included in the withBuddies list
    // when at least one buddy has a goal in that category
    Set<UUID> activityCategoryIdsUsedByBuddies = buddies.stream()
            .map(b -> b.getGoals().orElse(Collections.emptySet())).flatMap(Set::stream)
            .map(GoalDto::getActivityCategoryId).collect(Collectors.toSet());

    Map<ZonedDateTime, Set<DayActivityDto>> dayActivityDtosByZonedDate = executeAndCreateInactivityEntries(
            mia -> getDayActivitiesForUserAnonymizedIdsInInterval(userAnonymizedIds,
                    activityCategoryIdsUsedByBuddies, interval, mia));
    return dayActivityEntitiesToOverviewsUserWithBuddies(dayActivityDtosByZonedDate);
}

From source file:com.netflix.dyno.queues.redis.RedisDynoQueue.java

public RedisDynoQueue(String redisKeyPrefix, String queueName, Set<String> allShards, String shardName,
        ExecutorService dynoCallExecutor) {
    this.redisKeyPrefix = redisKeyPrefix;
    this.queueName = queueName;
    this.allShards = allShards.stream().collect(Collectors.toList());
    this.shardName = shardName;
    this.messageStoreKey = redisKeyPrefix + ".MESSAGE." + queueName;
    this.myQueueShard = getQueueShardKey(queueName, shardName);

    ObjectMapper om = new ObjectMapper();
    om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    om.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);
    om.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
    om.setSerializationInclusion(Include.NON_NULL);
    om.setSerializationInclusion(Include.NON_EMPTY);
    om.disable(SerializationFeature.INDENT_OUTPUT);

    this.om = om;
    this.monitor = new QueueMonitor(queueName, shardName);
    this.prefetchedIds = new LinkedBlockingQueue<>();
    this.executorService = dynoCallExecutor;

    Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> processUnacks(), unackScheduleInMS,
            unackScheduleInMS, TimeUnit.MILLISECONDS);
    Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> prefetchIds(), 0, 10, TimeUnit.MILLISECONDS);

    logger.info(RedisDynoQueue.class.getName() + " is ready to serve " + queueName);

}

From source file:com.hortonworks.streamline.streams.security.service.SecurityCatalogResource.java

private Response getRoleUsers(Long roleId) {
    Role role = catalogService.getRole(roleId);
    Set<Role> rolesToQuery = new HashSet<>();
    if (role != null) {
        rolesToQuery.add(role);//from  www . j a va2 s .  co m
        rolesToQuery.addAll(catalogService.getChildRoles(roleId));
        Set<User> res = rolesToQuery.stream().flatMap(r -> catalogService.listUsers(r).stream())
                .collect(Collectors.toSet());
        return WSUtils.respondEntities(res, OK);
    }
    throw EntityNotFoundException.byId(roleId.toString());
}

From source file:com.thinkbiganalytics.feedmgr.rest.controller.FeedCategoryRestController.java

@GET
@Path("{categoryId}/actions/allowed")
@Produces(MediaType.APPLICATION_JSON)//w  w w . ja va  2s . co m
@ApiOperation("Gets the list of actions permitted for the given username and/or groups.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the actions.", response = ActionGroup.class),
        @ApiResponse(code = 404, message = "A category with the given ID does not exist.", response = RestResponseStatus.class) })
public Response getAllowedActions(@PathParam("categoryId") String categoryIdStr,
        @QueryParam("user") Set<String> userNames, @QueryParam("group") Set<String> groupNames) {
    log.debug("Get allowed actions for category: {}", categoryIdStr);

    Set<? extends Principal> users = Arrays.stream(this.securityTransform.asUserPrincipals(userNames))
            .collect(Collectors.toSet());
    Set<? extends Principal> groups = Arrays.stream(this.securityTransform.asGroupPrincipals(groupNames))
            .collect(Collectors.toSet());

    return this.securityService
            .getAllowedCategoryActions(categoryIdStr,
                    Stream.concat(users.stream(), groups.stream()).collect(Collectors.toSet()))
            .map(g -> Response.ok(g).build()).orElseThrow(() -> new WebApplicationException(
                    "A category with the given ID does not exist: " + categoryIdStr, Status.NOT_FOUND));
}