本文整理汇总了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)));
}
示例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);
}
示例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);
}
示例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 );
}
示例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));
}
示例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);
}
示例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()));
}
示例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();
}
示例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)));
}
示例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());
}
示例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][]);
}
示例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);
}
示例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());
}
示例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();
}
示例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)));
}