当前位置: 首页>>代码示例>>Java>>正文


Java Stream.map方法代码示例

本文整理汇总了Java中java.util.stream.Stream.map方法的典型用法代码示例。如果您正苦于以下问题:Java Stream.map方法的具体用法?Java Stream.map怎么用?Java Stream.map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.stream.Stream的用法示例。


在下文中一共展示了Stream.map方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onTabCompletion

import java.util.stream.Stream; //导入方法依赖的package包/类
@Override
public List<String> onTabCompletion(CommandSender sender, Class<?> type, List<String> args) {
    Stream<? extends Player> players = Bukkit.getOnlinePlayers().stream();
    if(sender instanceof Player) {
        Player player = (Player) sender;
        players = players.filter(player::canSee);
    }
    Stream<String> strStream = players.map(Player::getName);
    if(args.isEmpty())
        return strStream.collect(Collectors.toList());
    String partial = args.get(0);
    return strStream
            .filter(s -> StringUtil.startsWithIgnoreCase(s, partial))
            .sorted(String.CASE_INSENSITIVE_ORDER)
            .collect(Collectors.toList());
}
 
开发者ID:upperlevel,项目名称:uppercore,代码行数:17,代码来源:PlayerArgumentParser.java

示例2: load

import java.util.stream.Stream; //导入方法依赖的package包/类
@Override
public Stream<PropertyBox> load(QueryConfigurationProvider configuration, int offset, int limit)
		throws DataAccessException {
	Query q = buildQuery(configuration, true);
	// paging
	if (limit > 0) {
		q.limit(limit);
		q.offset(offset);
	}
	// execute
	Stream<PropertyBox> results = q.stream(propertySet);
	if (getItemIdentifier().isPresent()) {
		return results.map(pb -> new IdentifiablePropertyBox(pb, getItemIdentifier().get()));
	}
	return results;
}
 
开发者ID:holon-platform,项目名称:holon-vaadin,代码行数:17,代码来源:DatastoreItemDataProvider.java

示例3: testLazyFilterAndMapAndDistinct

import java.util.stream.Stream; //导入方法依赖的package包/类
@Test
public void testLazyFilterAndMapAndDistinct() {
    ICounter<String, Stream<String>> req = Countify.of(new FileRequest()::getContent);
    WeatherWebApi api = new WeatherWebApi(req::apply);
    Stream<WeatherInfoDto> infos = api.pastWeather(41.15, -8.6167, of(2017, 02, 01), of(2017, 02, 28));
    assertEquals(1, req.getCount());
    infos = infos.filter(info -> info.getDescription().toLowerCase().contains("sun"));
    assertEquals(1, req.getCount());
    Stream<Integer> temps = infos.map(info -> info.getTempC());
    assertEquals(1, req.getCount());
    temps = temps.distinct();
    assertEquals(1, req.getCount());
    assertEquals(5, temps.count());
    assertEquals(1, req.getCount());
}
 
开发者ID:isel-leic-mpd,项目名称:mpd-2017-i41d,代码行数:16,代码来源:LazyQueriesTest.java

示例4: dynamicTestsFromStream

import java.util.stream.Stream; //导入方法依赖的package包/类
@TestFactory
Stream<DynamicTest> dynamicTestsFromStream() {
    Stream<String> inputStream = Stream.of("A", "B", "C");
    return inputStream.map(
            input -> dynamicTest("Display name for input " + input, () -> {
                System.out.println("Testing " + input);
            }));
}
 
开发者ID:bonigarcia,项目名称:mastering-junit5,代码行数:9,代码来源:DynamicExampleTest.java

示例5: execute

import java.util.stream.Stream; //导入方法依赖的package包/类
public MemgraphCypherScope execute(
        MemgraphCypherQueryContext ctx,
        boolean distinct,
        CypherReturnBody returnBody,
        MemgraphCypherScope scope
) {
    List<CypherReturnItem> returnItems = returnBody.getReturnItems()
            .stream()
            .flatMap(ri -> {
                if (ri.getExpression() instanceof CypherAllLiteral) {
                    return getAllFieldNamesAsReturnItems(scope);
                }
                return Stream.of(ri);
            })
            .collect(Collectors.toList());
    LinkedHashSet<String> columnNames = getColumnNames(returnItems);

    Stream<MemgraphCypherScope.Item> rows = scope.stream();

    long aggregationCount = aggregationCount(ctx, returnItems);
    if (returnItems.size() > 0 && aggregationCount == returnItems.size()) {
        rows = Stream.of(getReturnRow(ctx, returnItems, null, scope));
    } else if (aggregationCount > 0 && isGroupable(returnItems.get(0))) {
        Map<Optional<?>, MemgraphCypherScope> groups = groupBy(ctx, returnItems.get(0), rows);
        rows = groups.entrySet().stream()
                .map(group -> getReturnRow(ctx, returnItems, group.getKey(), group.getValue()));
    } else {
        rows = rows
                .map(row -> getReturnRow(ctx, returnItems, null, row));
    }

    if (distinct) {
        rows = rows.distinct();
    }

    MemgraphCypherScope results = MemgraphCypherScope.newFromItems(rows, columnNames, scope);

    return applyReturnBody(ctx, returnBody, results);
}
 
开发者ID:mware-solutions,项目名称:memory-graph,代码行数:40,代码来源:ReturnClauseExecutor.java

示例6: createBatchFor

import java.util.stream.Stream; //导入方法依赖的package包/类
/**
 * Creates a new batch containing the specified import requests.
 * @param requests the import requests to queue.
 * @return the new batch.
 * @throws NullPointerException if the stream or any of its elements is
 * {@code null}.
 * @throws IllegalArgumentException if the stream is empty.
 */
protected ImportBatch createBatchFor(Stream<ImportInput> requests) {
    requireNonNull(requests, "requests");
    Stream<ImportInput> rs = requests.map(r -> {
        requireNonNull(r, "request");
        return r;
    });

    ImportBatch batch = new ImportBatch(rs);
    ImportBatchStatus unprocessed = new ImportBatchStatus(batch);

    env.batchStore().put(batch.batchId(), unprocessed);
    return unprocessed.batch();
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:22,代码来源:BatchManager.java

示例7: testWeatherServiceLazy

import java.util.stream.Stream; //导入方法依赖的package包/类
@Test
public void testWeatherServiceLazy(){
    /**
     * Arrange WeatherService --> WeatherWebApi --> Countify --> FileRequest
     */
    ICounter<String, Stream<String>> req = Countify.of(new FileRequest()::getContent);
    WeatherService api = new WeatherService(new WeatherWebApi(req::apply));
    /**
     * Act and Assert
     */
    Stream<Location> locals = api.search("Porto");
    assertEquals(1, req.getCount());
    locals = locals.filter(l -> l.getLatitude() > 0 );
    assertEquals(1, req.getCount());
    Location loc = locals.findFirst().get();
    assertEquals(1, req.getCount());
    Stream<WeatherInfo> infos = loc.getPastWeather(of(2017,02,01), of(2017,02,28));
    assertEquals(2, req.getCount());
    infos = infos.filter(info -> info.getDescription().toLowerCase().contains("sun"));
    Stream<Integer> temps = infos.map(WeatherInfo::getTempC);
    temps = temps.distinct();
    assertEquals(2, req.getCount());
    /**
     * When we iterate over the pastWeather then we make one more request
     */
    assertEquals(5, temps.count()); // iterates all items
    assertEquals(2, req.getCount());
}
 
开发者ID:isel-leic-mpd,项目名称:mpd-2017-i41d,代码行数:29,代码来源:WeatherDomainTest.java

示例8: cacheAll

import java.util.stream.Stream; //导入方法依赖的package包/类
/**
 * Cache a bunch of guilds
 * Difference to the sync method is that this won't double check the saved DiscordGuilds against their presence in
 * the bot. This method is fine to call to cache only a subset of all guilds
 *
 * @param dbWrapper The database to run the sync on
 * @param guilds    Stream over all guilds to be cached
 * @param clazz     Class of the actual DiscordGuild entity
 * @return DatabaseExceptions caused by the execution of this method
 */
@Nonnull
public static <E extends DiscordGuild<E>> Collection<DatabaseException> cacheAll(@Nonnull final DatabaseWrapper dbWrapper,
                                                                                 @Nonnull final Stream<Guild> guilds,
                                                                                 @Nonnull final Class<E> clazz) {
    long started = System.currentTimeMillis();
    final List<DatabaseException> exceptions = new ArrayList<>();
    final AtomicInteger joined = new AtomicInteger(0);
    final AtomicInteger streamed = new AtomicInteger(0);
    final Function<Guild, Function<E, E>> cacheAndJoin = (guild) -> (discordguild) -> {
        E result = discordguild.set(guild);
        if (!result.present) {
            result = result.join();
            joined.incrementAndGet();
        }
        return result;
    };
    final Stream<Transfiguration<Long, E>> transfigurations = guilds.map(
            guild -> {
                if (streamed.incrementAndGet() % 100 == 0) {
                    log.debug("{} guilds processed while caching", streamed.get());
                }
                return Transfiguration.of(EntityKey.of(guild.getIdLong(), clazz), cacheAndJoin.apply(guild));
            }
    );

    exceptions.addAll(dbWrapper.findApplyAndMergeAll(transfigurations));

    log.debug("Cached {} DiscordGuild entities of class {} in {}ms with {} exceptions, joined {}",
            streamed.get(), clazz.getSimpleName(), System.currentTimeMillis() - started, exceptions.size(), joined.get());
    return exceptions;
}
 
开发者ID:napstr,项目名称:SqlSauce,代码行数:42,代码来源:DiscordGuild.java

示例9: testWeatherServiceLazy

import java.util.stream.Stream; //导入方法依赖的package包/类
@Test
public void testWeatherServiceLazy(){
    /**
     * Arrange WeatherService --> WeatherWebApi --> Countify --> FileRequest
     */
    ICounter<String, CompletableFuture<Stream<String>>> req = Countify.of(new FileRequest()::getContent);
    WeatherService api = new WeatherService(new WeatherWebApi(req::apply));
    /**
     * Act and Assert
     */
    Stream<Location> locals = api.search("Porto").join();
    assertEquals(1, req.getCount());
    locals = locals.filter(l -> l.getLatitude() > 0 );
    assertEquals(1, req.getCount());
    /**
     * When we get the first item from Stream we are instantiating a new
     * Location object and thus requesting its last 30 days past weather.
     */
    Location loc = locals.findFirst().get();
    assertEquals(2, req.getCount());
    Stream<WeatherInfo> infos = loc.getPastWeather(of(2017,02,01), of(2017,02,28));
    assertEquals(3, req.getCount());
    infos = infos.filter(info -> info.getDescription().toLowerCase().contains("sun"));
    Stream<Integer> temps = infos.map(WeatherInfo::getTempC);
    temps = temps.distinct();
    assertEquals(3, req.getCount());
    assertEquals(5, temps.count()); // iterates all items
    assertEquals(3, req.getCount());
}
 
开发者ID:isel-leic-mpd,项目名称:mpd-2017-i41d,代码行数:30,代码来源:WeatherDomainTest.java

示例10: mapToStream

import java.util.stream.Stream; //导入方法依赖的package包/类
/**
 * @see #mapToStream(Stream, Function) mapToStream
 */
default Stream<TARGET> mapToStream(final Stream<SOURCE> sources) {
    return sources.map(this::map);
}
 
开发者ID:yyunikov,项目名称:yunikov-commons,代码行数:7,代码来源:Mapping.java

示例11: forAll

import java.util.stream.Stream; //导入方法依赖的package包/类
static <T> Stream<Runnable> forAll(Stream<? extends T> inputs, Consumer<? super T> consumer) {
  requireNonNull(consumer);
  return inputs.map(input -> () -> consumer.accept(input));
}
 
开发者ID:google,项目名称:mug,代码行数:5,代码来源:Parallelizer.java

示例12: testWeatherServiceLazyAndCache

import java.util.stream.Stream; //导入方法依赖的package包/类
@Test
public void testWeatherServiceLazyAndCache(){
    /**
     * Arrange WeatherService --> WeatherWebApi --> Countify --> FileRequest
     */
    ICounter<String, CompletableFuture<Stream<String>>> req = Countify.of(new FileRequest()::getContent);
    // Function<String, Iterable<String>> cache = Cache.memoize(req);
    WeatherServiceCache api = new WeatherServiceCache(new WeatherWebApi(req::apply));
    /**
     * Act and Assert
     */
    Stream<Location> locals = api.search("Porto").join();
    assertEquals(1, req.getCount());
    locals = locals.filter(l -> l.getLatitude() > 0 );
    assertEquals(1, req.getCount());
    /**
     * Counts 2 request when iterates to get the first Location.
     * Location requests last 30 days past weather asynchronously.
     */
    Location loc = locals.iterator().next();
    assertEquals(2, req.getCount());
    Stream<WeatherInfo> infos = loc.getPastWeather(of(2017,02,01), of(2017,02,28));
    assertEquals(3, req.getCount());
    infos = infos.filter(info ->
            info.getDescription().toLowerCase().contains("sun"));
    Stream<Integer> temps = infos.map(WeatherInfo::getTempC);
    temps = temps.distinct();
    assertEquals(3, req.getCount());
    assertEquals(5, temps.count()); // iterates all items
    assertEquals(3, req.getCount());
    /**
     * NOT caching Locations. Just cache for Past Weather.
     * So, searching for Porto makes 2 more requests: 1 for Location and
     * 1 more for last 30 days weather.
     */
    loc = api.search("Porto").join().findFirst().get();
    assertEquals(5, req.getCount());
    /**
     * February past weather is already in cache for Porto.
     * So, we will not make no more requests.
     */
    temps = loc
            .getPastWeather(of(2017,02,01), of(2017,02,28))
            .filter(info -> info.getDescription().toLowerCase().contains("sun"))
            .map(WeatherInfo::getTempC);
    assertEquals((long) 20, (long) temps.skip(2).findFirst().get()); // another iterator
    assertEquals(5, req.getCount());
    /**
     * getting a sub-interval of past weather should return from cache
     */
    infos = loc.getPastWeather(of(2017,02,05), of(2017,02,18));
    infos.iterator().next();
    assertEquals(5, req.getCount());
    /**
     * getting a new interval gets from IO
     */
    infos = loc.getPastWeather(of(2017,02,15), of(2017,03,15));
    infos.forEach((item) -> {}); // Consume all to add all itens in cache
    assertEquals(6, req.getCount());
    /**
     * getting a sub-interval of past weather should return from cache
     */
    infos = loc.getPastWeather(of(2017,02,20), of(2017,03,10));
    infos.iterator().next();
    assertEquals(6, req.getCount());
}
 
开发者ID:isel-leic-mpd,项目名称:mpd-2017-i41d,代码行数:67,代码来源:WeatherDomainTest.java

示例13: of

import java.util.stream.Stream; //导入方法依赖的package包/类
static KitNode of(Stream<Kit> kits) {
    return new KitNodeImpl(Stream.empty(), new All<>(kits.map(Unit::new)), StaticFilter.ALLOW, empty(), empty());
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:4,代码来源:KitNode.java

示例14: indent

import java.util.stream.Stream; //导入方法依赖的package包/类
private Stream<String> indent(Stream<String> lines) {
    return lines.map(line -> "  " + line);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:4,代码来源:MultiLineTextInspector.java

示例15: parse

import java.util.stream.Stream; //导入方法依赖的package包/类
public Stream<LenderRecord> parse(Stream<String> stream) {
     return stream.map(s -> parse(s));
}
 
开发者ID:dhinojosa,项目名称:tddinjava_2017-08-14,代码行数:4,代码来源:LenderParser.java


注:本文中的java.util.stream.Stream.map方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。