/** Returns an immutable array containing all the values from {@code stream}, in order. */ public static ImmutableLongArray copyOf(LongStream stream) { // Note this uses very different growth behavior from copyOf(Iterable) and the builder. long[] array = stream.toArray(); return (array.length == 0) ? EMPTY : new ImmutableLongArray(array); }
protected synchronized long[] getSubprocedureIds() { if (subprocs == null) { return null; } return subprocs.stream().mapToLong(Procedure::getProcId).toArray(); }
/** Returns an immutable array containing all the values from {@code stream}, in order. */ public static ImmutableLongArray copyOf(LongStream stream) { // Note this uses very different growth behavior from copyOf(Iterable) and the builder. long[] array = stream.toArray(); return (array.length == 0) ? EMPTY : new ImmutableLongArray(array); }
private static long[] parsePath(@Nullable String snapshotPath) { if (snapshotPath == null) { return EMPTY_PATH; } return PATH_SPLITTER .splitToList(snapshotPath) .stream() .mapToLong(Long::parseLong) .toArray(); } }
@VisibleForTesting public Backoff(int minTries, Duration maxFailureInterval, Ticker ticker, List<Duration> backoffDelayIntervals) { checkArgument(minTries > 0, "minTries must be at least 1"); requireNonNull(maxFailureInterval, "maxFailureInterval is null"); requireNonNull(ticker, "ticker is null"); requireNonNull(backoffDelayIntervals, "backoffDelayIntervals is null"); checkArgument(!backoffDelayIntervals.isEmpty(), "backoffDelayIntervals must contain at least one entry"); this.minTries = minTries; this.maxFailureIntervalNanos = maxFailureInterval.roundTo(NANOSECONDS); this.ticker = ticker; this.backoffDelayIntervalsNanos = backoffDelayIntervals.stream() .mapToLong(duration -> duration.roundTo(NANOSECONDS)) .toArray(); }
/** * Will be used when there are too many proc wal files. We will rewrite the states of the active * procedures in the oldest proc wal file so that we can delete it. * @return all the active procedure ids in this tracker. */ public long[] getAllActiveProcIds() { return map.values().stream().map(BitSetNode::getActiveProcIds).filter(p -> p.length > 0) .flatMapToLong(LongStream::of).toArray(); }
/** Returns an immutable array containing all the values from {@code stream}, in order. */ public static ImmutableLongArray copyOf(LongStream stream) { // Note this uses very different growth behavior from copyOf(Iterable) and the builder. long[] array = stream.toArray(); return (array.length == 0) ? EMPTY : new ImmutableLongArray(array); }
@Override public long[] execute() { try (final LongStream stream = buildPrevious()) { return stream.toArray(); } } }
private static IterableSubject assertThat(LongStream stream) { return Truth.assertThat(stream.toArray()).asList(); }
@Override public Long[] findCategoryIdsByArticleId(long articleId) { List<Record> records = Db.find("select * from article_category_mapping where article_id = ?", articleId); if (records == null || records.isEmpty()) return null; return ArrayUtils.toObject(records.stream().mapToLong(record -> record.get("category_id")).toArray()); }
private Long[] getTagIds(String[] tags) { if (tags == null || tags.length == 0) { return null; } List<ArticleCategory> categories = categoryService.doNewOrFindByTagString(tags); long[] ids = categories.stream().mapToLong(value -> value.getId()).toArray(); return ArrayUtils.toObject(ids); }
public static long[] getReplicationBarriers(Result result) { return result.getColumnCells(HConstants.REPLICATION_BARRIER_FAMILY, HConstants.SEQNUM_QUALIFIER) .stream().mapToLong(MetaTableAccessor::getReplicationBarrier).sorted().distinct().toArray(); }
private Long[] getTagIds(String[] tags) { if (tags == null || tags.length == 0) { return null; } List<ArticleCategory> categories = categoryService.doNewOrFindByTagString(tags); long[] ids = categories.stream().mapToLong(value -> value.getId()).toArray(); return ArrayUtils.toObject(ids); }
@Override public long[] toArray() { try { return stream().toArray(); } finally { close(); } }
private void verifySnapshots(long... expectedIds) { List<Map<String, Object>> rows = db.select("select id from snapshots"); long[] ids = rows.stream() .mapToLong(row -> (long) row.get("ID")) .toArray(); assertThat(ids).containsOnly(expectedIds); }
private void assertThatMeasuresAreExactly(long... expectedMeasureIds) { long[] ids = db.select("select id as \"id\" from project_measures") .stream() .mapToLong(m -> (Long) m.get("id")) .toArray(); assertThat(ids).containsOnly(expectedMeasureIds); }
@Test(dataProvider = "filterTypes") public void bloomFilterTest(FilterType filterType) { for (int capacity = 2 << 10; capacity < (2 << 22); capacity = capacity << 2) { long[] input = new Random().longs(capacity).distinct().toArray(); List<String[]> rows = new ArrayList<>(); int expectedInsertions = capacity / 2; Membership filter = filterType.create(expectedInsertions, FPP, CONFIG); int falsePositives = falsePositives(filter, input); double falsePositiveRate = ((double) falsePositives / expectedInsertions); assertThat(filterType.toString(), falsePositiveRate, is(lessThan(FPP + 0.01))); rows.add(row(filterType, expectedInsertions, falsePositives, falsePositiveRate)); if (display) { printTable(rows); } } }
@Test public void testLazyBlockBuilderInitialization() { long[][] expectedValues = new long[ARRAY_SIZES.length][]; Random rand = new Random(47); for (int i = 0; i < ARRAY_SIZES.length; i++) { expectedValues[i] = rand.longs(ARRAY_SIZES[i]).toArray(); } BlockBuilder emptyBlockBuilder = new ArrayBlockBuilder(BIGINT, null, 0, 0); BlockBuilder blockBuilder = new ArrayBlockBuilder(BIGINT, null, 100, 100); assertEquals(blockBuilder.getSizeInBytes(), emptyBlockBuilder.getSizeInBytes()); assertEquals(blockBuilder.getRetainedSizeInBytes(), emptyBlockBuilder.getRetainedSizeInBytes()); writeValues(expectedValues, blockBuilder); assertTrue(blockBuilder.getSizeInBytes() > emptyBlockBuilder.getSizeInBytes()); assertTrue(blockBuilder.getRetainedSizeInBytes() > emptyBlockBuilder.getRetainedSizeInBytes()); blockBuilder = blockBuilder.newBlockBuilderLike(null); assertEquals(blockBuilder.getSizeInBytes(), emptyBlockBuilder.getSizeInBytes()); assertEquals(blockBuilder.getRetainedSizeInBytes(), emptyBlockBuilder.getRetainedSizeInBytes()); }
public void testStream() { ImmutableLongArray.of().stream().forEach(i -> fail()); ImmutableLongArray.of(0, 1, 3).subArray(1, 1).stream().forEach(i -> fail()); assertThat(ImmutableLongArray.of(0, 1, 3).stream().toArray()).isEqualTo(new long[] {0, 1, 3}); }
@Test public void testWithFixedWidthBlock() { long[][] expectedValues = new long[ARRAY_SIZES.length][]; Random rand = new Random(47); for (int i = 0; i < ARRAY_SIZES.length; i++) { expectedValues[i] = rand.longs(ARRAY_SIZES[i]).toArray(); } BlockBuilder blockBuilder = createBlockBuilderWithValues(expectedValues); assertBlock(blockBuilder, () -> blockBuilder.newBlockBuilderLike(null), expectedValues); assertBlock(blockBuilder.build(), () -> blockBuilder.newBlockBuilderLike(null), expectedValues); assertBlockFilteredPositions(expectedValues, blockBuilder.build(), () -> blockBuilder.newBlockBuilderLike(null), 0, 1, 3, 4, 7); assertBlockFilteredPositions(expectedValues, blockBuilder.build(), () -> blockBuilder.newBlockBuilderLike(null), 2, 3, 5, 6); long[][] expectedValuesWithNull = alternatingNullValues(expectedValues); BlockBuilder blockBuilderWithNull = createBlockBuilderWithValues(expectedValuesWithNull); assertBlock(blockBuilderWithNull, () -> blockBuilder.newBlockBuilderLike(null), expectedValuesWithNull); assertBlock(blockBuilderWithNull.build(), () -> blockBuilder.newBlockBuilderLike(null), expectedValuesWithNull); assertBlockFilteredPositions(expectedValuesWithNull, blockBuilderWithNull.build(), () -> blockBuilder.newBlockBuilderLike(null), 0, 1, 5, 6, 7, 10, 11, 12, 15); assertBlockFilteredPositions(expectedValuesWithNull, blockBuilderWithNull.build(), () -> blockBuilder.newBlockBuilderLike(null), 2, 3, 4, 9, 13, 14); }