public LongBoxedAction() { super(s -> s.boxed(), Stream.class, BOXED); }
long[] arr = {1,2,3,4}; List<Long> list = Arrays.stream(arr).boxed().collect(Collectors.toList());
/** * 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(); }
@Override public List<Long> getTxnIds() { if (txnIds != null) { return txnIds; } return LongStream.rangeClosed(fromTxnId, toTxnId) .boxed().collect(Collectors.toList()); }
private LongStreamSubject(FailureMetadata failureMetadata, @NullableDecl LongStream stream) { super(failureMetadata, stream); this.actualList = (stream == null) ? null : stream.boxed().collect(toCollection(ArrayList::new)); }
/** * 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(); }
private static Object[] box(long[] rest) { return LongStream.of(rest).boxed().toArray(Long[]::new); }
/** * 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(); }
/** * 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(); }
/** * 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())); } }
private Set<Value> randomLongs( long min, long max ) { return ThreadLocalRandom.current() .longs( nodesToCreate, min, max ) .boxed() .map( Values::of ) .collect( toSet() ); }
@Override public Stream<Long> boxed() { return wrap(stream().boxed()); }
/** * 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())); }
public static Block createLongArraySequenceBlock(int start, int length) { return createLongArraysBlock(LongStream.range(start, length).boxed().toArray(Long[]::new)); }
@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()); }
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 ); } }
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); }
Set<Long> expectedIds = LongStream.range(0, rowCount) .filter(x -> bucketIds.contains(toIntExact(x % bucketCount))) .boxed() .collect(toImmutableSet());
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; }
@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()); }