當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。