@Override public LongStream events() throws IOException { return lines().flatMapToLong(line -> { String[] array = line.split(" ", 3); long startBlock = Long.parseLong(array[0]); int sequence = Integer.parseInt(array[1]); return LongStream.range(startBlock, startBlock + sequence); }); } }
/** Returns a sequence of items constructed by the generator. */ private static LongStream generate(NumberGenerator generator, long count) { return LongStream.range(0, count).map(ignored -> generator.nextValue().longValue()); } }
@SafeVarargs @SuppressWarnings("varargs") // Creating a List from an array is safe public static <T> Stream<Stream<T>> of(final T... items) { final List<T> itemList = Arrays.asList(items); return LongStream.range(0, factorial(items.length)) .mapToObj(no -> permutation(no, itemList).stream()); }
@Override public Object getExpectedValue(int start, int length) { if (length == 0) { return null; } return LongStream.range(start, start + length).reduce(start, (x, y) -> x & y); }
@Override public Object getExpectedValue(int start, int length) { if (length == 0) { return null; } return LongStream.range(start, start + length).reduce(start, (x, y) -> x | y); }
@Override public LongStream events() throws IOException { return lines().flatMapToLong(line -> { String[] array = line.split(",", 5); if (array.length <= 4) { return LongStream.empty(); } long startBlock = Long.parseLong(array[1]); int size = Integer.parseInt(array[2]); int sequence = IntMath.divide(size, BLOCK_SIZE, RoundingMode.UP); char readWrite = Character.toLowerCase(array[3].charAt(0)); return (readWrite == 'w') ? LongStream.empty() : LongStream.range(startBlock, startBlock + sequence); }); } }
public static Block createLongArraySequenceBlock(int start, int length) { return createLongArraysBlock(LongStream.range(start, length).boxed().toArray(Long[]::new)); }
@Test public void mustDeleteLogFilesThatCanBePruned() { when( factory.strategyFromConfigValue( eq( fs ), eq( logFiles ), eq( clock ), anyString() ) ) .thenReturn( upTo -> LongStream.range( 3, upTo ) ); LogPruning pruning = new LogPruningImpl( fs, logFiles,logProvider,factory, clock, config ); pruning.pruneLogs( 5 ); InOrder order = inOrder( fs ); order.verify( fs ).deleteFile( new File( "3" ) ); order.verify( fs ).deleteFile( new File( "4" ) ); // Log file 5 is not deleted; it's the lowest version expected to remain after pruning. verifyNoMoreInteractions( fs ); }
@Test public void mustHaveLogFilesToPruneIfStrategyFindsFiles() { when( factory.strategyFromConfigValue( eq( fs ), eq( logFiles ), eq( clock ), anyString() ) ) .thenReturn( upTo -> LongStream.range( 3, upTo ) ); when( logFiles.getHighestLogVersion() ).thenReturn( 4L ); LogPruning pruning = new LogPruningImpl( fs, logFiles, logProvider, factory, clock, config ); assertTrue( pruning.mightHaveLogsToPrune() ); }
Set<Long> expectedIds = LongStream.range(0, rowCount) .filter(x -> bucketIds.contains(toIntExact(x % bucketCount))) .boxed()
@Test public void testStd() throws InterruptedException, ExecutionException { double avgSq = LongStream.range(0, COUNT).map(l -> l * l).reduce((l1, l2) -> l1 + l2).getAsLong() / (double) COUNT; double avg = (COUNT - 1) / 2.0; double std = Math.sqrt(avgSq - avg * avg); assertEquals(std, AsyncAggregationClient .std(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get().doubleValue(), DELTA); }
@BeforeClass public static void setUp() throws Exception { Configuration conf = UTIL.getConfiguration(); conf.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, AggregateImplementation.class.getName()); UTIL.startMiniCluster(3); byte[][] splitKeys = new byte[8][]; for (int i = 111; i < 999; i += 111) { splitKeys[i / 111 - 1] = Bytes.toBytes(String.format("%03d", i)); } UTIL.createTable(TABLE_NAME, CF, splitKeys); CONN = ConnectionFactory.createAsyncConnection(UTIL.getConfiguration()).get(); TABLE = CONN.getTable(TABLE_NAME); TABLE.putAll(LongStream.range(0, COUNT) .mapToObj(l -> new Put(Bytes.toBytes(String.format("%03d", l))) .addColumn(CF, CQ, Bytes.toBytes(l)).addColumn(CF, CQ2, Bytes.toBytes(l * l))) .collect(Collectors.toList())).get(); }
contains(LongStream.range(0, numPartitions).boxed().collect(Collectors.toList()).toArray(new Long[0])));
iterations = Flux.fromStream(LongStream.range(0, Long.MAX_VALUE).boxed());
@Test public void testMedianWithWeight() throws InterruptedException, ExecutionException { long halfSum = LongStream.range(0, COUNT).map(l -> l * l).reduce((l1, l2) -> l1 + l2).getAsLong() / 2; long median = 0L; long sum = 0L; for (int i = 0; i < COUNT; i++) { sum += i * i; if (sum > halfSum) { median = i - 1; break; } } assertEquals(median, AsyncAggregationClient .median(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ).addColumn(CF, CQ2)) .get().longValue()); } }
session, "SELECT * FROM " + partitionsTable, "VALUES " + LongStream.range(0, 1200) .mapToObj(String::valueOf) .collect(joining(",")));
@Test public void concurrentLuceneIndexSnapshotUseDifferentSnapshots() throws Exception { Label label = Label.label( "testLabel" ); database.withSetting( GraphDatabaseSettings.default_schema_provider, GraphDatabaseSettings.SchemaIndex.NATIVE20.providerName() ); prepareDatabase( label ); forceCheckpoint( checkPointer ); ResourceIterator<File> firstCheckpointSnapshot = indexingService.snapshotIndexFiles(); generateData( label ); removeOldNodes( LongStream.range( 1, 20 ) ); updateOldNodes( LongStream.range( 30, 40 ) ); forceCheckpoint( checkPointer ); ResourceIterator<File> secondCheckpointSnapshot = indexingService.snapshotIndexFiles(); generateData( label ); removeOldNodes( LongStream.range( 50, 60 ) ); updateOldNodes( LongStream.range( 70, 80 ) ); forceCheckpoint( checkPointer ); ResourceIterator<File> thirdCheckpointSnapshot = indexingService.snapshotIndexFiles(); Set<String> firstSnapshotFileNames = getFileNames( firstCheckpointSnapshot ); Set<String> secondSnapshotFileNames = getFileNames( secondCheckpointSnapshot ); Set<String> thirdSnapshotFileNames = getFileNames( thirdCheckpointSnapshot ); compareSnapshotFiles( firstSnapshotFileNames, secondSnapshotFileNames, fileSystem ); compareSnapshotFiles( secondSnapshotFileNames, thirdSnapshotFileNames, fileSystem); compareSnapshotFiles( thirdSnapshotFileNames, firstSnapshotFileNames, fileSystem); firstCheckpointSnapshot.close(); secondCheckpointSnapshot.close(); thirdCheckpointSnapshot.close(); }
createRLEBlock(1, 2000), 0.01, Floats.toArray(LongStream.range(-1000, 1000).mapToObj(Float::new).collect(toImmutableList())));
createRLEBlock(1, 2000), 0.01, LongStream.range(-1000, 1000).toArray());
createRLEBlock(1, 2000), 0.01, LongStream.range(-1000, 1000).asDoubleStream().toArray());