本文整理了Java中java.util.stream.LongStream.boxed()
方法的一些代码示例,展示了LongStream.boxed()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LongStream.boxed()
方法的具体详情如下:
包路径:java.util.stream.LongStream
类名称:LongStream
方法名:boxed
[英]Returns a Stream consisting of the elements of this stream, each boxed to a Long.
This is an intermediate operation.
[中]返回一个由该流的元素组成的流,每个元素都被装箱为长字符串。
这是一个intermediate operation。
代码示例来源:origin: speedment/speedment
public LongBoxedAction() {
super(s -> s.boxed(), Stream.class, BOXED);
}
代码示例来源:origin: stackoverflow.com
long[] arr = {1,2,3,4};
List<Long> list = Arrays.stream(arr).boxed().collect(Collectors.toList());
代码示例来源:origin: google/guava
/**
* Returns the last element of the specified stream, or {@link OptionalLong#empty} if the stream
* is empty.
*
* <p>Equivalent to {@code stream.reduce((a, b) -> b)}, but may perform significantly better. This
* method's runtime will be between O(log n) and O(n), performing better on <a
* href="http://gee.cs.oswego.edu/dl/html/StreamParallelGuidance.html">efficiently splittable</a>
* streams.
*
* @see LongStream#findFirst()
* @throws NullPointerException if the last element of the stream is null
*/
public static OptionalLong findLast(LongStream stream) {
// findLast(Stream) does some allocation, so we might as well box some more
java.util.Optional<Long> boxedLast = findLast(stream.boxed());
return boxedLast.isPresent() ? OptionalLong.of(boxedLast.get()) : OptionalLong.empty();
}
代码示例来源:origin: apache/hive
@Override
public List<Long> getTxnIds() {
if (txnIds != null) {
return txnIds;
}
return LongStream.rangeClosed(fromTxnId, toTxnId)
.boxed().collect(Collectors.toList());
}
代码示例来源:origin: google/truth
private LongStreamSubject(FailureMetadata failureMetadata, @NullableDecl LongStream stream) {
super(failureMetadata, stream);
this.actualList =
(stream == null) ? null : stream.boxed().collect(toCollection(ArrayList::new));
}
代码示例来源:origin: prestodb/presto
/**
* Returns the last element of the specified stream, or {@link OptionalLong#empty} if the stream
* is empty.
*
* <p>Equivalent to {@code stream.reduce((a, b) -> b)}, but may perform significantly better. This
* method's runtime will be between O(log n) and O(n), performing better on <a
* href="http://gee.cs.oswego.edu/dl/html/StreamParallelGuidance.html">efficiently splittable</a>
* streams.
*
* @see LongStream#findFirst()
* @throws NullPointerException if the last element of the stream is null
*/
public static OptionalLong findLast(LongStream stream) {
// findLast(Stream) does some allocation, so we might as well box some more
java.util.Optional<Long> boxedLast = findLast(stream.boxed());
return boxedLast.isPresent() ? OptionalLong.of(boxedLast.get()) : OptionalLong.empty();
}
代码示例来源:origin: google/truth
private static Object[] box(long[] rest) {
return LongStream.of(rest).boxed().toArray(Long[]::new);
}
代码示例来源:origin: google/j2objc
/**
* Returns the last element of the specified stream, or {@link OptionalLong#empty} if the stream
* is empty.
*
* <p>Equivalent to {@code stream.reduce((a, b) -> b)}, but may perform significantly better. This
* method's runtime will be between O(log n) and O(n), performing better on <a
* href="http://gee.cs.oswego.edu/dl/html/StreamParallelGuidance.html">efficiently splittable</a>
* streams.
*
* @see LongStream#findFirst()
* @throws NullPointerException if the last element of the stream is null
*/
public static OptionalLong findLast(LongStream stream) {
// findLast(Stream) does some allocation, so we might as well box some more
java.util.Optional<Long> boxedLast = findLast(stream.boxed());
return boxedLast.isPresent() ? OptionalLong.of(boxedLast.get()) : OptionalLong.empty();
}
代码示例来源:origin: wildfly/wildfly
/**
* Returns the last element of the specified stream, or {@link OptionalLong#empty} if the stream
* is empty.
*
* <p>Equivalent to {@code stream.reduce((a, b) -> b)}, but may perform significantly better. This
* method's runtime will be between O(log n) and O(n), performing better on <a
* href="http://gee.cs.oswego.edu/dl/html/StreamParallelGuidance.html">efficiently splittable</a>
* streams.
*
* @see LongStream#findFirst()
* @throws NullPointerException if the last element of the stream is null
*/
public static OptionalLong findLast(LongStream stream) {
// findLast(Stream) does some allocation, so we might as well box some more
java.util.Optional<Long> boxedLast = findLast(stream.boxed());
return boxedLast.isPresent() ? OptionalLong.of(boxedLast.get()) : OptionalLong.empty();
}
代码示例来源:origin: org.assertj/assertj-core
/**
* Verifies that {@link LongPredicate} evaluates all the given values to {@code false}.
* <p>
* Example :
* <pre><code class='java'> LongPredicate evenNumber = n -> n % 2 == 0;
*
* // assertion succeeds:
* assertThat(evenNumber).rejects(1, 3, 5);
*
* // assertion fails because of 2:
* assertThat(evenNumber).rejects(1, 2, 3);</code></pre>
*
* @param values values that the actual {@code Predicate} should reject.
* @return this assertion object.
* @throws AssertionError if the actual {@code Predicate} accepts one of the given values.
*/
public LongPredicateAssert rejects(long... values) {
if (values.length == 1) return rejectsInternal(values[0]);
return rejectsAllInternal(LongStream.of(values).boxed().collect(Collectors.toList()));
}
}
代码示例来源:origin: neo4j/neo4j
private Set<Value> randomLongs( long min, long max )
{
return ThreadLocalRandom.current()
.longs( nodesToCreate, min, max )
.boxed()
.map( Values::of )
.collect( toSet() );
}
代码示例来源:origin: speedment/speedment
@Override
public Stream<Long> boxed() {
return wrap(stream().boxed());
}
代码示例来源:origin: org.assertj/assertj-core
/**
* Verifies that {@link LongPredicate} evaluates all the given values to {@code true}.
* <p>
* Example :
* <pre><code class='java'> LongPredicate evenNumber = n -> n % 2 == 0;
*
* // assertion succeeds:
* assertThat(evenNumber).accepts(2, 4, 6);
*
* // assertion fails because of 3:
* assertThat(evenNumber).accepts(2, 3, 4);</code></pre>
*
* @param values values that the actual {@code Predicate} should accept.
* @return this assertion object.
* @throws AssertionError if the actual {@code Predicate} does not accept all given values.
*/
public LongPredicateAssert accepts(long... values) {
if (values.length == 1) return acceptsInternal(values[0]);
return acceptsAllInternal(LongStream.of(values).boxed().collect(Collectors.toList()));
}
代码示例来源:origin: prestodb/presto
public static Block createLongArraySequenceBlock(int start, int length)
{
return createLongArraysBlock(LongStream.range(start, length).boxed().toArray(Long[]::new));
}
代码示例来源:origin: ben-manes/caffeine
@Test(dataProvider = "snapshot")
public void snapshot(boolean ascending, int limit, long nanos, Function<Long, Long> transformer) {
int count = 21;
timerWheel.nanos = nanos;
int expected = Math.min(limit, count);
Comparator<Long> order = ascending ? Comparator.naturalOrder() : Comparator.reverseOrder();
List<Long> times = IntStream.range(0, count).mapToLong(i -> {
long time = nanos + TimeUnit.SECONDS.toNanos(2 << i);
timerWheel.schedule(new Timer(time));
return time;
}).boxed().sorted(order).collect(toList()).subList(0, expected);
when(transformer.apply(anyLong())).thenAnswer(invocation -> invocation.getArgument(0));
assertThat(snapshot(ascending, limit, transformer), is(times));
verify(transformer, times(expected)).apply(anyLong());
}
代码示例来源:origin: neo4j/neo4j
private void assertLabelScanStoreContains( LabelScanStore labelScanStore, int labelId, long... nodes )
{
try ( LabelScanReader labelScanReader = labelScanStore.newReader() )
{
List<Long> actualNodeIds = extractPrimitiveLongIteratorAsList( labelScanReader.nodesWithLabel( labelId ) );
List<Long> expectedNodeIds = Arrays.stream( nodes ).boxed().collect( Collectors.toList() );
assertEquals( expectedNodeIds, actualNodeIds );
}
}
代码示例来源:origin: prestodb/presto
private void testAggregationBigints(InternalAggregationFunction function, Page page, double maxError, long... inputs)
{
// aggregate level
assertAggregation(function,
QDIGEST_EQUALITY,
"test multiple positions",
page,
getExpectedValueLongs(maxError, inputs));
// test scalars
List<Long> rows = Arrays.stream(inputs).sorted().boxed().collect(Collectors.toList());
SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(function, page);
assertPercentileWithinError(StandardTypes.BIGINT, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99);
}
代码示例来源:origin: prestodb/presto
Set<Long> expectedIds = LongStream.range(0, rowCount)
.filter(x -> bucketIds.contains(toIntExact(x % bucketCount)))
.boxed()
.collect(toImmutableSet());
代码示例来源:origin: apache/hive
private List<Long> replOpenTxnForTest(long startId, int numTxn, String replPolicy)
throws Exception {
conf.setIntVar(HiveConf.ConfVars.HIVE_TXN_MAX_OPEN_BATCH, numTxn);
long lastId = startId + numTxn - 1;
OpenTxnRequest rqst = new OpenTxnRequest(numTxn, "me", "localhost");
rqst.setReplPolicy(replPolicy);
rqst.setReplSrcTxnIds(LongStream.rangeClosed(startId, lastId)
.boxed().collect(Collectors.toList()));
OpenTxnsResponse openedTxns = txnHandler.openTxns(rqst);
List<Long> txnList = openedTxns.getTxn_ids();
assertEquals(txnList.size(), numTxn);
int numTxnPresentNow = TxnDbUtil.countQueryAgent(conf, "select count(*) from TXNS where TXN_ID >= " +
txnList.get(0) + " and TXN_ID <= " + txnList.get(numTxn - 1));
assertEquals(numTxn, numTxnPresentNow);
checkReplTxnForTest(startId, lastId, replPolicy, txnList);
return txnList;
}
代码示例来源:origin: SonarSource/sonarqube
@Before
public void setUp() throws Exception {
organization = db.organizations().insert();
user = db.users().insertUser();
group1 = db.users().insertGroup(organization, "group1");
group2 = db.users().insertGroup(organization, "group2");
randomExistingUserIds = IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
.map(i -> db.users().insertUser().getId())
.boxed()
.collect(MoreCollectors.toSet());
randomPublicProjectIds = IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
.mapToLong(i -> db.components().insertPublicProject(organization).getId())
.boxed()
.collect(MoreCollectors.toSet());
randomPrivateProjectIds = IntStream.range(0, 1 + Math.abs(random.nextInt(5)))
.mapToLong(i -> db.components().insertPrivateProject(organization).getId())
.boxed()
.collect(MoreCollectors.toSet());
}
内容来源于网络,如有侵权,请联系作者删除!