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


Java Stream.distinct方法代码示例

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


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

示例1: 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

示例2: 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

示例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: 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

示例5: 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

示例6: testLazyFilterAndMapAndDistinct

import java.util.stream.Stream; //导入方法依赖的package包/类
@Test
public void testLazyFilterAndMapAndDistinct() {
    ICounter<String, CompletableFuture<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)).join();
    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

示例7: list

import java.util.stream.Stream; //导入方法依赖的package包/类
@Override
public Stream<String> list() throws IOException {
    Stream<String> s = delegate().list();
    for (ResourceFinder finder : finders) {
        s = Stream.concat(s, finder.list());
    }
    return s.distinct();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:ModulePatcher.java

示例8: testWeatherServiceLazyAndCache

import java.util.stream.Stream; //导入方法依赖的package包/类
@Test
public void testWeatherServiceLazyAndCache(){
    /**
     * Arrange WeatherService --> WeatherWebApi --> Countify --> FileRequest
     */
    ICounter<String, Stream<String>> req = Countify.of(new FileRequest()::getContent);
    // Function<String, Iterable<String>> cache = Cache.memoize(req);
    WeatherService api = new WeatherServiceCache(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());
    /**
     * Counts 1 request when iterates to get the first Location
     */
    Location loc = locals.iterator().next();
    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());
    temps = api.search("Porto")
            .findFirst().get()
            .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(3, 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(3, 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(4, 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(4, req.getCount());
}
 
开发者ID:isel-leic-mpd,项目名称:mpd-2017-i41d,代码行数:59,代码来源:WeatherDomainTest.java

示例9: 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


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