java.util.stream.LongStream Java Examples
The following examples show how to use
java.util.stream.LongStream.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConcatOpTest.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
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))); }
Example #2
Source File: JDBCMessageStoreTest.java From qpid-broker-j with Apache License 2.0 | 6 votes |
@Test public void testInClauseMaxSize() throws Exception { final GenericJDBCMessageStore store = spy((GenericJDBCMessageStore) getStore()); reOpenStoreWithInClauseMaxSize(store, 10); store.removeMessages(LongStream.rangeClosed(1, 21L).boxed().collect(Collectors.toList())); verify(store).removeMessagesFromDatabase(any(Connection.class), eq(LongStream.rangeClosed(1L, 10L) .boxed() .collect(Collectors.toList()))); verify(store).removeMessagesFromDatabase(any(Connection.class), eq(LongStream.rangeClosed(11L, 20L) .boxed() .collect(Collectors.toList()))); verify(store).removeMessagesFromDatabase(any(Connection.class), eq(Collections.singletonList(21L))); }
Example #3
Source File: WorkingDaysToDaysConverter.java From taskana with Apache License 2.0 | 6 votes |
public boolean isGermanHoliday(LocalDate date) { if (GERMAN_HOLIDAYS.contains(CustomHoliday.of(date.getDayOfMonth(), date.getMonthValue()))) { return true; } // Easter holidays Good Friday, Easter Monday, Ascension Day, Whit Monday. long diffFromEasterSunday = DAYS.between(easterCalculator.getEasterSunday(date.getYear()), date); Builder builder = LongStream.builder() .add(OFFSET_GOOD_FRIDAY) .add(OFFSET_EASTER_MONDAY) .add(OFFSET_ASCENSION_DAY) .add(OFFSET_WHIT_MONDAY); if (corpusChristiEnabled) { builder.add(OFFSET_CORPUS_CHRISTI); } return builder.build().anyMatch(c -> c == diffFromEasterSunday); }
Example #4
Source File: ConcatOpTest.java From hottub with GNU General Public License v2.0 | 6 votes |
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))); }
Example #5
Source File: ConcatOpTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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))); }
Example #6
Source File: PlanCacheSizePerformanceTest.java From high-performance-java-persistence with Apache License 2.0 | 6 votes |
@Override public void init() { metricRegistry.register(getClass().getSimpleName(), timer); super.init(); int commentsSize = 5; doInJPA(entityManager -> { LongStream.range(0, 50).forEach(i -> { Post post = new Post(); post.setId(i); post.setTitle(String.format("Post nr. %d", i)); LongStream.range(0, commentsSize).forEach(j -> { PostComment comment = new PostComment(); comment.setId((i * commentsSize) + j); comment.setReview(String.format("Good review nr. %d", comment.getId())); post.addComment(comment); }); entityManager.persist(post); }); }); }
Example #7
Source File: MongoSinkConnectorTest.java From mongo-kafka with Apache License 2.0 | 6 votes |
private void assertCollectionOrder(final String collectionName, final boolean exactOrdering) { List<Long> expectedIdOrder = LongStream.range(0, 100).boxed().collect(Collectors.toList()); List<Long> idOrder = getCollection(collectionName).find().sort(Sorts.ascending("_id")).into(new ArrayList<>()) .stream() .map(d -> d.getLong("id")) .collect(Collectors.toList()); assertEquals( new HashSet<>(expectedIdOrder), new HashSet<>(idOrder), format("%s missing expected values.", collectionName)); if (exactOrdering) { assertEquals(expectedIdOrder, idOrder, format("%s is out of order.", collectionName)); } else { assertNotEquals( expectedIdOrder, idOrder, format("%s unexpectedly in order.", collectionName)); } }
Example #8
Source File: InfiniteStreamWithLimitOpTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@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][]); }
Example #9
Source File: ConcatOpTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@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))); }
Example #10
Source File: InfiniteStreamWithLimitOpTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "LongStream.limit") public void testLongSubsizedWithRange(String description, UnaryOperator<LongStream> fs) { // Range is [0, Long.MAX_VALUE), splits are SUBSIZED // Such a size will induce out of memory errors for incorrect // slice implementations withData(longs()). stream(s -> fs.apply(s)). without(LongStreamTestScenario.PAR_STREAM_TO_ARRAY_CLEAR_SIZED). exercise(); }
Example #11
Source File: StateMachineUpdater.java From incubator-ratis with Apache License 2.0 | 5 votes |
private void takeSnapshot() { final long i; try { Timer.Context takeSnapshotTimerContext = stateMachineMetrics.getTakeSnapshotTimer().time(); i = stateMachine.takeSnapshot(); takeSnapshotTimerContext.stop(); final long lastAppliedIndex = getLastAppliedIndex(); if (i > lastAppliedIndex) { throw new StateMachineException( "Bug in StateMachine: snapshot index = " + i + " > appliedIndex = " + lastAppliedIndex + "; StateMachine class=" + stateMachine.getClass().getName() + ", stateMachine=" + stateMachine); } stateMachine.getStateMachineStorage().cleanupOldSnapshots(snapshotRetentionPolicy); } catch (IOException e) { LOG.error(name + ": Failed to take snapshot", e); return; } if (i >= 0) { LOG.info("{}: Took a snapshot at index {}", name, i); snapshotIndex.updateIncreasingly(i, infoIndexChange); final long purgeIndex; if (purgeUptoSnapshotIndex) { // We can purge up to snapshot index even if all the peers do not have // commitIndex up to this snapshot index. purgeIndex = i; } else { final LongStream commitIndexStream = server.getCommitInfos().stream().mapToLong( CommitInfoProto::getCommitIndex); purgeIndex = LongStream.concat(LongStream.of(i), commitIndexStream).min().orElse(i); } raftLog.purge(purgeIndex); } }
Example #12
Source File: Select.java From robozonky with Apache License 2.0 | 5 votes |
private void addLongs(final String field, final String operation, final long... value) { final String key = operation == null ? field : field + "__" + operation; conditions.compute(key, (k, v) -> { final String val = LongStream.of(value) .mapToObj(String::valueOf) .collect(Collectors.joining("\",\"", "[\"", "\"]")); final List<Object> result = (v == null) ? new ArrayList<>(1) : v; result.add(val); return result; }); }
Example #13
Source File: MatchOpTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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); }
Example #14
Source File: TestMinMax.java From incubator-ratis with Apache License 2.0 | 5 votes |
static void runTestMinMax(LongStream stream) { final List<Long> list = stream.collect(ArrayList::new, List::add, List::addAll); final LongMinMax longMinMax = toLongStream(list).collect(LongMinMax::new, LongMinMax::accumulate, LongMinMax::combine); if (longMinMax.isInitialized()) { Assert.assertEquals(toLongStream(list).min().getAsLong(), longMinMax.getMin()); Assert.assertEquals(toLongStream(list).max().getAsLong(), longMinMax.getMax()); } else { Assert.assertEquals(OptionalLong.empty(), toLongStream(list).min()); Assert.assertEquals(OptionalLong.empty(), toLongStream(list).max()); } }
Example #15
Source File: InfiniteStreamWithLimitOpTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "LongStream.limit") public void testLongUnorderedFinite(String description, UnaryOperator<LongStream> fs) { // Range is [0, Long.MAX_VALUE), splits are SUBSIZED // Such a size will induce out of memory errors for incorrect // slice implementations withData(longs()). stream(s -> fs.apply(s.filter(i -> true).unordered())). resultAsserter(unorderedAsserter()). exercise(); }
Example #16
Source File: WhileOpTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(groups = { "serialization-hostile" }) public void testLongDefaultClose() { AtomicBoolean isClosed = new AtomicBoolean(); LongStream s = LongStream.of(1, 2, 3).onClose(() -> isClosed.set(true)); try (LongStream ds = DefaultMethodStreams.delegateTo(s).takeWhile(e -> e < 3)) { ds.count(); } assertTrue(isClosed.get()); }
Example #17
Source File: StreamBuilderTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@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(); }
Example #18
Source File: InfiniteStreamWithLimitOpTest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "LongStream.limit") public void testLongUnorderedIteration(String description, UnaryOperator<LongStream> fs) { // Source is a right-balanced tree of infinite size TestData.OfLong iterator = TestData.Factory.ofLongSupplier( "[1L, 2L, 3L, ...]", () -> LongStream.iterate(1, i -> i + 1)); // Ref withData(iterator). stream(s -> fs.apply(s.unordered())). resultAsserter(unorderedAsserter()). exercise(); }
Example #19
Source File: TestFutureUtils.java From distributedlog with Apache License 2.0 | 5 votes |
@Test public void testProcessListSuccess() throws Exception { List<Long> longList = Lists.newArrayList(LongStream.range(0L, 10L).iterator()); List<Long> expectedList = Lists.transform( longList, aLong -> 2 * aLong); Function<Long, CompletableFuture<Long>> sumFunc = value -> FutureUtils.value(2 * value); CompletableFuture<List<Long>> totalFuture = FutureUtils.processList( longList, sumFunc, null); assertEquals(expectedList, FutureUtils.result(totalFuture)); }
Example #20
Source File: DynamicOps.java From DataFixerUpper with MIT License | 5 votes |
default DataResult<LongStream> getLongStream(final T input) { return getStream(input).flatMap(stream -> { final List<T> list = stream.collect(Collectors.toList()); if (list.stream().allMatch(element -> getNumberValue(element).result().isPresent())) { return DataResult.success(list.stream().mapToLong(element -> getNumberValue(element).result().get().longValue())); } return DataResult.error("Some elements are not longs: " + input); }); }
Example #21
Source File: StreamBuilderTest.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@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(); }
Example #22
Source File: Utils.java From flink with Apache License 2.0 | 5 votes |
/** * Gets a stream of values from a collection of range resources. */ public static LongStream rangeValues(Collection<Protos.Resource> resources) { checkNotNull(resources); return resources.stream() .filter(Protos.Resource::hasRanges) .flatMap(r -> r.getRanges().getRangeList().stream()) .flatMapToLong(Utils::rangeValues); }
Example #23
Source File: OnlineIndexerBuildSumIndexTest.java From fdb-record-layer with Apache License 2.0 | 5 votes |
@Test @Tag(Tags.Slow) public void addSequentialWhileBuildingSum() { Random r = new Random(0xba5eba11); List<TestRecords1Proto.MySimpleRecord> records = LongStream.range(0, 100).mapToObj(val -> TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(val).setNumValue2(r.nextInt(20)).build() ).collect(Collectors.toList()); List<TestRecords1Proto.MySimpleRecord> recordsWhileBuilding = Stream.generate(() -> TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(r.nextInt(100)).setNumValue2(r.nextInt(20) + 20).build() ).limit(100).sorted(Comparator.comparingLong(TestRecords1Proto.MySimpleRecord::getRecNo)).collect(Collectors.toList()); sumRebuild(records, recordsWhileBuilding); }
Example #24
Source File: ColumnVectorTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testDouble() { HeapDoubleVector vector = new HeapDoubleVector(SIZE); for (int i = 0; i < SIZE; i++) { vector.setDouble(i, i); } for (int i = 0; i < SIZE; i++) { assertEquals(i, vector.getDouble(i), 0); } vector.fill(22); for (int i = 0; i < SIZE; i++) { assertEquals(22, vector.getDouble(i), 0); } vector.setDictionary(new TestDictionary(LongStream.range(0, SIZE).boxed() .map(Number::doubleValue).toArray())); setRangeDictIds(vector); for (int i = 0; i < SIZE; i++) { assertEquals(i, vector.getDouble(i), 0); } double[] doubles = LongStream.range(0, SIZE).boxed().mapToDouble(Number::doubleValue).toArray(); byte[] binary = new byte[SIZE * 8]; UNSAFE.copyMemory(doubles, DOUBLE_ARRAY_OFFSET, binary, BYTE_ARRAY_OFFSET, binary.length); vector = new HeapDoubleVector(SIZE); vector.setDoublesFromBinary(0, SIZE, binary, 0); for (int i = 0; i < SIZE; i++) { assertEquals(i, vector.getDouble(i), 0); } }
Example #25
Source File: OrderedLuceneBatchIteratorFactoryTest.java From crate with Apache License 2.0 | 5 votes |
@Before public void prepareSearchers() throws Exception { IndexWriter iw1 = new IndexWriter(new ByteBuffersDirectory(), new IndexWriterConfig(new StandardAnalyzer())); IndexWriter iw2 = new IndexWriter(new ByteBuffersDirectory(), new IndexWriterConfig(new StandardAnalyzer())); expectedResult = LongStream.range(0, 20) .mapToObj(i -> new Object[]{i}) .collect(Collectors.toList()); // expect descending order to differentiate between insert order expectedResult.sort(Comparator.comparingLong((Object[] o) -> ((long) o[0])).reversed()); for (int i = 0; i < 20; i++) { Document doc = new Document(); doc.add(new NumericDocValuesField(columnName, i)); if (i % 2 == 0) { iw1.addDocument(doc); } else { iw2.addDocument(doc); } } iw1.commit(); iw2.commit(); searcher1 = new IndexSearcher(DirectoryReader.open(iw1)); searcher2 = new IndexSearcher(DirectoryReader.open(iw2)); orderBy = new OrderBy( Collections.singletonList(reference), reverseFlags, nullsFirst ); }
Example #26
Source File: ConstantZeroRandomNumberGenerator.java From jinjava with Apache License 2.0 | 5 votes |
@Override public LongStream longs( long streamSize, long randomNumberOrigin, long randomNumberBound ) { throw new UnsupportedOperationException(); }
Example #27
Source File: DatasetTest.java From djl with Apache License 2.0 | 5 votes |
@Test public void testSequenceSampler() { try (Model model = Model.newInstance("model")) { model.setBlock(Blocks.identityBlock()); NDManager manager = model.getNDManager(); ArrayDataset dataset = new ArrayDataset.Builder() .setData( manager.arange( 0, 100, 1, DataType.INT64, Device.defaultDevice())) .setSampling(new BatchSampler(new SequenceSampler(), 1, false)) .build(); List<Long> original = new ArrayList<>(); try (Trainer trainer = model.newTrainer(config)) { trainer.iterateDataset(dataset) .iterator() .forEachRemaining( record -> original.add( record.getData().singletonOrThrow().getLong())); List<Long> expected = LongStream.range(0, 100).boxed().collect(Collectors.toList()); Assert.assertEquals(original, expected, "SequentialSampler test failed"); } } }
Example #28
Source File: StreamBuilderTest.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@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(); }
Example #29
Source File: StackBatchifier.java From djl with Apache License 2.0 | 5 votes |
/** * Splits an {@code NDArray} into the given number of slices along the given batch axis. * * <p>Usually used for data parallelism where each slice is sent to one device (i.e. GPU). * * @param array a batch of {@code NDArray} * @param numOfSlices the number of desired slices * @param evenSplit whether to force all slices to have the same number of elements * @return an NDList even if `numOfSlice` is 1 */ private NDList split(NDArray array, int numOfSlices, boolean evenSplit) { int batchSize = Math.toIntExact(array.size(0)); if (batchSize < numOfSlices) { throw new IllegalArgumentException( "Batch size(" + batchSize + ") is less then slice number(" + numOfSlices + ")."); } if (evenSplit && batchSize % numOfSlices != 0) { throw new IllegalArgumentException( "data with shape " + batchSize + " cannot be evenly split into " + numOfSlices + ". Use a batch size that's multiple of " + numOfSlices + " or set even_split=true to allow" + " uneven partitioning of data."); } if (evenSplit) { return array.split(numOfSlices); } int step = (int) Math.ceil((double) batchSize / numOfSlices); long[] indices = LongStream.range(1, numOfSlices).map(i -> i * step).toArray(); return array.split(indices); }
Example #30
Source File: InfiniteStreamWithLimitOpTest.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "LongStream.limit") public void testLongSubsizedWithRange(String description, UnaryOperator<LongStream> fs) { // Range is [0, Long.MAX_VALUE), splits are SUBSIZED // Such a size will induce out of memory errors for incorrect // slice implementations withData(longs()). stream(s -> fs.apply(s)). without(LongStreamTestScenario.PAR_STREAM_TO_ARRAY_CLEAR_SIZED). exercise(); }