Example usage for java.util.stream Stream map

List of usage examples for java.util.stream Stream map

Introduction

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

Prototype

<R> Stream<R> map(Function<? super T, ? extends R> mapper);

Source Link

Document

Returns a stream consisting of the results of applying the given function to the elements of this stream.

Usage

From source file:org.trustedanalytics.examples.hbase.services.HBaseService.java

/**
 * Get list of tables in given namespace;
 *///from ww  w  .  ja  v  a 2  s  . co  m
public List<TableDescription> listTables() throws LoginException {
    List<TableDescription> result = null;

    try (Connection connection = hBaseConnectionFactory.connect(); Admin admin = connection.getAdmin()) {
        HTableDescriptor[] tables = admin.listTables();

        Stream<HTableDescriptor> tableDescriptorsStream = Arrays.stream(tables);

        result = tableDescriptorsStream.map(conversionsService::constructTableDescription)
                .collect(Collectors.toList());
    } catch (IOException e) {
        LOG.error("Error while talking to HBase.", e);
    }

    return result;
}

From source file:it.polimi.diceH2020.SPACE4Cloud.shared.inputData.old.InstanceData_old.java

private Stream<Optional<JobClass_old>> getStreamJobClasses(Stream<String> strmJobID) {
    return strmJobID.map(j -> lstClass.stream().filter(job -> job.getId().equals(j)).findAny());
}

From source file:com.liferay.dynamic.data.lists.form.web.internal.converter.DDLFormRuleToDDMFormRuleConverter.java

protected String convertOperand(DDLFormRuleCondition.Operand operand) {
    if (Objects.equals("field", operand.getType())) {
        return String.format(_functionCallUnaryExpressionFormat, "getValue",
                StringUtil.quote(operand.getValue()));
    }/*from w  w w  .j a va2 s . c om*/

    String value = operand.getValue();

    if (NumberUtils.isNumber(value)) {
        return value;
    }

    String[] values = StringUtil.split(value);

    UnaryOperator<String> quoteOperation = StringUtil::quote;
    UnaryOperator<String> trimOperation = StringUtil::trim;

    Stream<String> valuesStream = Stream.of(values);

    Stream<String> valueStream = valuesStream.map(trimOperation.andThen(quoteOperation));

    return valueStream.collect(Collectors.joining(StringPool.COMMA_AND_SPACE));
}

From source file:io.github.carlomicieli.footballdb.starter.parsers.DraftParser.java

protected List<DraftedPlayer> picks(Document doc) {
    Stream<Element> rows = picksTable(doc).flatMap(this::extractTableBody).map(this::extractTableRows)
            .orElseThrow(() -> new NoSuchElementException("Drafts table not found"));
    return rows.map(this::mapToDraftedPlayer).collect(Collectors.toList());
}

From source file:io.github.carlomicieli.footballdb.starter.parsers.TeamRosterParser.java

@Override
protected TeamRoster parseDocument(Document doc) {
    Stream<Element> rows = rosterTable(doc).flatMap(TeamRosterParser::rosterTableBody)
            .map(TeamRosterParser::rosterTableRows).orElseThrow(RuntimeException::new);

    List<TeamRoster.RosterEntry> players = rows.map(TeamRosterParser::rosterEntryValues)
            .map(TeamRoster.RosterEntry::of).collect(Collectors.toList());

    App.log().info("{} player(s) found.", players.size());

    return TeamRoster.builder().players(players).build();
}

From source file:it.polimi.diceH2020.SPACE4Cloud.shared.inputData.old.InstanceData_old.java

private <R> List<R> getFromMapper(List<JobClass_old> lstTypeJobClass,
        Function<Optional<JobClass_old>, ? extends R> mapper) {
    Stream<String> strmJobID = lstTypeJobClass.stream().map(JobClass_old::getId);
    Stream<Optional<JobClass_old>> strmJob = getStreamJobClasses(strmJobID);
    Stream<Optional<JobClass_old>> strm = strmJob.filter(Optional::isPresent);
    return strm.map(mapper).collect(toList());
}

From source file:example.UserGuideTest.java

@Test
public void graph() throws Exception {
    IRI nameIri = factory.createIRI("http://example.com/name");
    BlankNode aliceBlankNode = factory.createBlankNode();
    Literal aliceLiteral = factory.createLiteral("Alice");
    Triple triple = factory.createTriple(aliceBlankNode, nameIri, aliceLiteral);

    Graph graph = factory.createGraph();

    graph.add(triple);/*w ww .j  a va  2  s  .c o  m*/

    IRI bob = factory.createIRI("http://example.com/bob");
    Literal bobName = factory.createLiteral("Bob");
    graph.add(bob, nameIri, bobName);

    System.out.println(graph.contains(triple));

    System.out.println(graph.contains(null, nameIri, bobName));

    System.out.println(graph.size());

    for (Triple t : graph.iterate()) {
        System.out.println(t.getObject());
    }

    for (Triple t : graph.iterate(null, null, bobName)) {
        System.out.println(t.getPredicate());
    }

    Stream<RDFTerm> subjects = graph.getTriples().map(t -> t.getObject());
    String s = subjects.map(RDFTerm::ntriplesString).collect(Collectors.joining(" "));
    System.out.println(s);

    Stream<? extends Triple> namedB = graph.getTriples(null, nameIri, null)
            .filter(t -> t.getObject().ntriplesString().contains("B"));
    System.out.println(namedB.map(t -> t.getSubject()).findAny().get());

    graph.remove(triple);
    System.out.println(graph.contains(triple));

    graph.remove(null, nameIri, null);

    graph.clear();
    System.out.println(graph.contains(null, null, null));

}

From source file:io.github.carlomicieli.footballdb.starter.parsers.SeasonGamesParser.java

@Override
protected Season parseDocument(Document doc) {
    Stream<Element> rows = gamesTable(doc).flatMap(this::extractTableBody).map(e -> extractRows(e))
            .orElseThrow(() -> new NoSuchElementException("Games table not found"));

    String year = extractYear(doc);
    List<Game> games = rows.map(r -> mapToGame(year, r)).collect(Collectors.toList());
    return new Season(games);
}

From source file:alfio.manager.EventStatisticsManager.java

public List<EventStatistic> getAllEventsWithStatisticsFilteredBy(String username, Predicate<Event> predicate) {
    List<Event> events = getAllEvents(username).stream().filter(predicate).collect(toList());
    Map<Integer, Event> mappedEvent = events.stream()
            .collect(Collectors.toMap(Event::getId, Function.identity()));
    if (!mappedEvent.isEmpty()) {
        boolean isOwner = userManager.isOwner(userManager.findUserByUsername(username));
        Set<Integer> ids = mappedEvent.keySet();
        Stream<EventStatisticView> stats = isOwner ? eventRepository.findStatisticsFor(ids).stream()
                : ids.stream().map(EventStatisticView::empty);
        return stats.map(stat -> {
            Event event = mappedEvent.get(stat.getEventId());
            return new EventStatistic(event, stat, displayStatisticsForEvent(event));
        }).sorted().collect(Collectors.toList());
    } else {//from ww w. j a v a 2s.c om
        return Collections.emptyList();
    }
}

From source file:org.ow2.proactive.scheduling.api.graphql.fetchers.TaskDataFetcher.java

@Override
protected Stream<Task> dataMapping(Stream<TaskData> dataStream) {
    // TODO Task progress not accessible from DB. It implies to establish a connection with
    // the SchedulerFrontend active object to get the value that is in the Scheduler memory

    return dataStream.map(taskData -> {
        TaskData.DBTaskId id = taskData.getId();

        return Task.builder().additionalClasspath(taskData.getAdditionalClasspath())
                .description(taskData.getDescription()).executionDuration(taskData.getExecutionDuration())
                .executionHostname(taskData.getExecutionHostName()).finishedTime(taskData.getFinishedTime())
                .genericInformation(taskData.getGenericInformation()).id(id.getTaskId())
                .inErrorTime(taskData.getInErrorTime()).javaHome(taskData.getJavaHome()).jobId(id.getJobId())
                .jvmArguments(taskData.getJvmArguments())
                .maxNumberOfExecution(taskData.getMaxNumberOfExecution()).name(taskData.getTaskName())
                .numberOfExecutionLeft(taskData.getNumberOfExecutionLeft())
                .numberOfExecutionOnFailureLeft(taskData.getNumberOfExecutionOnFailureLeft())
                .onTaskError(//from  www .  j  av  a 2 s  .  co m
                        CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, taskData.getOnTaskErrorString()))
                .preciousLogs(taskData.isPreciousLogs()).preciousResult(taskData.isPreciousResult())
                .restartMode(RestartMode.getMode(taskData.getRestartModeId()).getDescription().toUpperCase())
                .resultPreview(taskData.getResultPreview()).runAsMe(taskData.isRunAsMe())
                .scheduledTime(taskData.getScheduledTime()).startTime(taskData.getStartTime())
                .status(taskData.getTaskStatus().name()).tag(taskData.getTag())
                .variables(taskData.getVariables().values().stream()
                        .map(taskDataVariable -> Maps.immutableEntry(taskDataVariable.getName(),
                                taskDataVariable.getValue()))
                        .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))
                .workingDir(taskData.getWorkingDir()).walltime(taskData.getWallTime()).build();
    });
}