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


Java LongStream类代码示例

本文整理汇总了Java中java.util.stream.LongStream的典型用法代码示例。如果您正苦于以下问题:Java LongStream类的具体用法?Java LongStream怎么用?Java LongStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testLongSize

import java.util.stream.LongStream; //导入依赖的package包/类
public void testLongSize() {
    assertSized(LongStream.concat(
            LongStream.range(0, Long.MAX_VALUE / 2),
            LongStream.range(0, Long.MAX_VALUE / 2)));

    assertUnsized(LongStream.concat(
            LongStream.range(0, Long.MAX_VALUE),
            LongStream.range(0, Long.MAX_VALUE)));

    assertUnsized(LongStream.concat(
            LongStream.range(0, Long.MAX_VALUE),
            LongStream.iterate(0, i -> i + 1)));

    assertUnsized(LongStream.concat(
            LongStream.iterate(0, i -> i + 1),
            LongStream.range(0, Long.MAX_VALUE)));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:ConcatOpTest.java

示例2: testDropWhileMulti

import java.util.stream.LongStream; //导入依赖的package包/类
private void testDropWhileMulti(Consumer<Stream<Integer>> mRef,
                                Consumer<IntStream> mInt,
                                Consumer<LongStream> mLong,
                                Consumer<DoubleStream> mDouble) {
    Map<String, Supplier<Stream<Integer>>> sources = new HashMap<>();
    sources.put("IntStream.range().boxed()",
                () -> IntStream.range(0, DROP_SOURCE_SIZE).boxed());
    sources.put("IntStream.range().boxed().unordered()",
                () -> IntStream.range(0, DROP_SOURCE_SIZE).boxed().unordered());
    sources.put("LinkedList.stream()",
                () -> IntStream.range(0, DROP_SOURCE_SIZE).boxed()
                        .collect(toCollection(LinkedList::new))
                        .stream());
    sources.put("LinkedList.stream().unordered()",
                () -> IntStream.range(0, DROP_SOURCE_SIZE).boxed()
                        .collect(toCollection(LinkedList::new))
                        .stream()
                        .unordered());
    testWhileMulti(sources, mRef, mInt, mLong, mDouble);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:WhileOpStatefulTest.java

示例3: getStateRender

import java.util.stream.LongStream; //导入依赖的package包/类
@Override
public TimeGraphStateRender getStateRender(TimeGraphTreeElement treeElement,
        TimeRange timeRange, long resolution, FutureTask<?> task) {

    int entryIndex = Integer.valueOf(treeElement.getName().substring(TestModelProvider.ENTRY_NAME_PREFIX.length()));
    long stateLength = entryIndex * DURATION_FACTOR;

    List<TimeGraphStateInterval> intervals = LongStream.iterate(timeRange.getStartTime(), i -> i + stateLength)
            .limit((timeRange.getDuration() / stateLength) + 1)
            .mapToObj(startTime -> {
                long endTime = startTime + stateLength - 1;
                StateDefinition stateDef = getNextStateDef();
                return new BasicTimeGraphStateInterval(startTime, endTime, treeElement, stateDef, stateDef.getName(), Collections.emptyMap());
            })
            .collect(Collectors.toList());

    return new TimeGraphStateRender(timeRange, treeElement, intervals);
}
 
开发者ID:lttng,项目名称:lttng-scope,代码行数:19,代码来源:TestModelStateProvider.java

示例4: buildDateList

import java.util.stream.LongStream; //导入依赖的package包/类
@Test
public void buildDateList() {
	
	LocalDate today = LocalDate.now() ;
	logger.info( "now: {} ", today.format(DateTimeFormatter.ofPattern( "yyyy-MM-dd" )  ) );
	
	List<String> past10days= LongStream
		.rangeClosed(1, 10)
		.mapToObj( day ->  today.minusDays( day ) )
		.map( offsetDate ->  offsetDate.format(DateTimeFormatter.ofPattern( "yyyy-MM-dd" ) ) )
		.collect( Collectors.toList() );
	
	List<String> past10daysReverse = LongStream.iterate(10, e -> e - 1)
     	.limit(10)
     	.mapToObj( day ->  today.minusDays( day ) )
		.map( offsetDate ->  offsetDate.format(DateTimeFormatter.ofPattern( "yyyy-MM-dd" ) ) )
		.collect( Collectors.toList() );

	logger.info( "past10days: {} \n reverse: {}", past10days, past10daysReverse );
	
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:22,代码来源:SimpleTests.java

示例5: LongPredicate

import java.util.stream.LongStream; //导入依赖的package包/类
@Test
public void LongPredicate()
{
    // TODO - Convert the anonymous inner class to a lambda
    LongPredicate predicate = new LongPredicate()
    {
        @Override
        public boolean test(long value)
        {
            return value % 2 == 0;
        }
    };
    List<Long> evens =
            LongStream.rangeClosed(1, 5).filter(predicate).boxed().collect(Collectors.toList());
    Assert.assertEquals(Arrays.asList(2L, 4L), evens);
    List<Long> odds =
            LongStream.rangeClosed(1, 5).filter(predicate.negate()).boxed().collect(Collectors.toList());
    Assert.assertEquals(Arrays.asList(1L, 3L, 5L), odds);
    Assert.assertTrue(LongStream.rangeClosed(1, 5).anyMatch(predicate));
    Assert.assertFalse(LongStream.rangeClosed(1, 5).allMatch(predicate));
    Assert.assertFalse(LongStream.rangeClosed(1, 5).noneMatch(predicate));
}
 
开发者ID:BNYMellon,项目名称:CodeKatas,代码行数:23,代码来源:PrimitiveFunctionalInterfaceTest.java

示例6: testWhileMulti

import java.util.stream.LongStream; //导入依赖的package包/类
private void testWhileMulti(TestData.OfRef<Integer> data,
                            ResultAsserter<Iterable<Integer>> ra,
                            Function<Stream<Integer>, Stream<Integer>> mRef,
                            Function<IntStream, IntStream> mInt,
                            Function<LongStream, LongStream> mLong,
                            Function<DoubleStream, DoubleStream> mDouble) {
    Map<String, Function<Stream<Integer>, Stream<Integer>>> ms = new HashMap<>();
    ms.put("Ref", mRef);
    ms.put("Int", s -> mInt.apply(s.mapToInt(e -> e)).mapToObj(e -> e));
    ms.put("Long", s -> mLong.apply(s.mapToLong(e -> e)).mapToObj(e -> (int) e));
    ms.put("Double", s -> mDouble.apply(s.mapToDouble(e -> e)).mapToObj(e -> (int) e));
    ms.put("Ref using defaults", s -> mRef.apply(DefaultMethodStreams.delegateTo(s)));
    ms.put("Int using defaults", s -> mInt.apply(DefaultMethodStreams.delegateTo(s.mapToInt(e -> e))).mapToObj(e -> e));
    ms.put("Long using defaults", s -> mLong.apply(DefaultMethodStreams.delegateTo(s.mapToLong(e -> e))).mapToObj(e -> (int) e));
    ms.put("Double using defaults", s -> mDouble.apply(DefaultMethodStreams.delegateTo(s.mapToDouble(e -> e))).mapToObj(e -> (int) e));

    testWhileMulti(data, ra, ms);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:WhileOpTest.java

示例7: testSize

import java.util.stream.LongStream; //导入依赖的package包/类
public void testSize() {
    assertSized(Stream.concat(
            LongStream.range(0, Long.MAX_VALUE / 2).boxed(),
            LongStream.range(0, Long.MAX_VALUE / 2).boxed()));

    assertUnsized(Stream.concat(
            LongStream.range(0, Long.MAX_VALUE).boxed(),
            LongStream.range(0, Long.MAX_VALUE).boxed()));

    assertUnsized(Stream.concat(
            LongStream.range(0, Long.MAX_VALUE).boxed(),
            Stream.iterate(0, i -> i + 1)));

    assertUnsized(Stream.concat(
            Stream.iterate(0, i -> i + 1),
            LongStream.range(0, Long.MAX_VALUE).boxed()));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:ConcatOpTest.java

示例8: produceRecords

import java.util.stream.LongStream; //导入依赖的package包/类
private static void produceRecords(String bootstrapServers) {
    Properties properties = new Properties();
    properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
    properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, LongSerializer.class.getName());
    properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, ByteArraySerializer.class.getName());

    Producer<Long, byte[]> producer = new KafkaProducer<>(properties);

    LongStream.rangeClosed(1, 100).boxed()
            .map(number ->
                    new ProducerRecord<>(
                            TOPIC, //topic
                            number, //key
                            String.format("record-%s", number.toString()).getBytes())) //value
            .forEach(record -> producer.send(record));
    producer.close();
}
 
开发者ID:jeqo,项目名称:talk-kafka-messaging-logs,代码行数:18,代码来源:ProduceConsumeLongByteArrayRecord.java

示例9: testOps

import java.util.stream.LongStream; //导入依赖的package包/类
@Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
public void testOps(String name, TestData.OfRef<Integer> data) {
    exerciseOpsInt(data,
                   s -> Stream.concat(s, data.stream()),
                   s -> IntStream.concat(s, data.stream().mapToInt(Integer::intValue)),
                   s -> LongStream.concat(s, data.stream().mapToLong(Integer::longValue)),
                   s -> DoubleStream.concat(s, data.stream().mapToDouble(Integer::doubleValue)));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:ConcatOpTest.java

示例10: testLongOps

import java.util.stream.LongStream; //导入依赖的package包/类
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class)
public void testLongOps(String name, TestData.OfLong data) {
    Collection<Long> result = exerciseOps(data, s -> s.flatMap(i -> Collections.singleton(i).stream().mapToLong(j -> j)));
    assertEquals(data.size(), result.size());
    assertContents(data, result);

    result = exerciseOps(data, s -> LongStream.empty());
    assertEquals(0, result.size());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:FlatMapOpTest.java

示例11: longSliceFunctionsDataProvider

import java.util.stream.LongStream; //导入依赖的package包/类
@DataProvider(name = "LongStream.limit")
public static Object[][] longSliceFunctionsDataProvider() {
    Function<String, String> f = s -> String.format(s, SKIP_LIMIT_SIZE);

    List<Object[]> data = new ArrayList<>();

    data.add(new Object[]{f.apply("LongStream.limit(%d)"),
            (UnaryOperator<LongStream>) s -> s.limit(SKIP_LIMIT_SIZE)});
    data.add(new Object[]{f.apply("LongStream.skip(%1$d).limit(%1$d)"),
            (UnaryOperator<LongStream>) s -> s.skip(SKIP_LIMIT_SIZE).limit(SKIP_LIMIT_SIZE)});

    return data.toArray(new Object[0][]);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:InfiniteStreamWithLimitOpTest.java

示例12: testDoubleStreamMatches

import java.util.stream.LongStream; //导入依赖的package包/类
public void testDoubleStreamMatches() {
    assertDoublePredicates(() -> LongStream.range(0, 0).asDoubleStream(), Kind.ANY, DOUBLE_PREDICATES, false, false, false, false);
    assertDoublePredicates(() -> LongStream.range(0, 0).asDoubleStream(), Kind.ALL, DOUBLE_PREDICATES, true, true, true, true);
    assertDoublePredicates(() -> LongStream.range(0, 0).asDoubleStream(), Kind.NONE, DOUBLE_PREDICATES, true, true, true, true);

    assertDoublePredicates(() -> LongStream.range(1, 2).asDoubleStream(), Kind.ANY, DOUBLE_PREDICATES, true, false, false, true);
    assertDoublePredicates(() -> LongStream.range(1, 2).asDoubleStream(), Kind.ALL, DOUBLE_PREDICATES, true, false, false, true);
    assertDoublePredicates(() -> LongStream.range(1, 2).asDoubleStream(), Kind.NONE, DOUBLE_PREDICATES, false, true, true, false);

    assertDoublePredicates(() -> LongStream.range(1, 6).asDoubleStream(), Kind.ANY, DOUBLE_PREDICATES, true, false, true, true);
    assertDoublePredicates(() -> LongStream.range(1, 6).asDoubleStream(), Kind.ALL, DOUBLE_PREDICATES, true, false, false, false);
    assertDoublePredicates(() -> LongStream.range(1, 6).asDoubleStream(), Kind.NONE, DOUBLE_PREDICATES, false, true, false, false);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:MatchOpTest.java

示例13: testFindLast_longStream

import java.util.stream.LongStream; //导入依赖的package包/类
public void testFindLast_longStream() {
  Truth.assertThat(findLast(LongStream.of())).isEqualTo(OptionalLong.empty());
  Truth.assertThat(findLast(LongStream.of(1, 2, 3, 4, 5))).isEqualTo(OptionalLong.of(5));

  // test with a large, not-subsized Spliterator
  List<Long> list =
      LongStream.rangeClosed(0, 10000).boxed().collect(Collectors.toCollection(LinkedList::new));
  Truth.assertThat(findLast(list.stream().mapToLong(i -> i))).isEqualTo(OptionalLong.of(10000));

  // no way to find out the stream is empty without walking its spliterator
  Truth.assertThat(findLast(list.stream().mapToLong(i -> i).filter(i -> i < 0)))
      .isEqualTo(OptionalLong.empty());
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:14,代码来源:StreamsTest.java

示例14: testLongSingleton

import java.util.stream.LongStream; //导入依赖的package包/类
@Test
public void testLongSingleton() {
    TestData.OfLong data = TestData.Factory.ofLongSupplier("[0, 1)",
                                                           () -> LongStream.of(1));

    withData(data).
            stream(s -> s).
            expectedResult(Collections.singletonList(1L)).
            exercise();

    withData(data).
            stream(s -> s.map(i -> i)).
            expectedResult(Collections.singletonList(1L)).
            exercise();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:StreamBuilderTest.java

示例15: testManageTempList

import java.util.stream.LongStream; //导入依赖的package包/类
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testManageTempList() {
    final List<Long> values = LongStream.range(0L, TEMP_LIST_CAPACITY)
        .collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
    final Long listId = daoHelper.createTempLongList(0L, values);
    assertNotNull("The temporary list ID cannot be null.", listId);
    assertEquals("Unexpected capacity of a temporary list.", TEMP_LIST_CAPACITY,
        new Long(daoHelper.clearTempList(listId)));
    // make sure that previously created values has been cleared
    daoHelper.createTempLongList(0L, values);
    assertEquals("Unexpected capacity of a temporary list.", TEMP_LIST_CAPACITY,
        new Long(daoHelper.clearTempList(listId)));
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:15,代码来源:DaoHelperTest.java


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