Example usage for java.util.stream LongStream rangeClosed

List of usage examples for java.util.stream LongStream rangeClosed

Introduction

In this page you can find the example usage for java.util.stream LongStream rangeClosed.

Prototype

public static LongStream rangeClosed(long startInclusive, final long endInclusive) 

Source Link

Document

Returns a sequential ordered LongStream from startInclusive (inclusive) to endInclusive (inclusive) by an incremental step of 1 .

Usage

From source file:Main.java

public static void main(String... args) {
    long l = LongStream.rangeClosed(1, 200).reduce(Long::sum).getAsLong();
    System.out.println(l);//from w  w w.ja  va  2s  .  c  om
}

From source file:Main.java

public static void main(String... args) {
    long l = LongStream.rangeClosed(1, 200).parallel().reduce(Long::sum).getAsLong();
    System.out.println(l);/*from   w w w . j  a  v a 2s  .c o  m*/
}

From source file:Main.java

public static void main(String[] args) {
    LongStream b = LongStream.rangeClosed(1L, 5L);

    b.forEach(System.out::println);
}

From source file:Main.java

public static void main(String... args) {
    Accumulator accumulator = new Accumulator();
    LongStream.rangeClosed(1, 100).forEach(accumulator::add);
    System.out.println(accumulator.total);
}

From source file:com.ethercamp.harmony.service.BlockchainInfoService.java

@PostConstruct
private void postConstruct() {
    /**//from  w ww.j  a v a 2  s  .  c o m
     * - gather blocks to calculate hash rate;
     * - gather blocks to keep for client block tree;
     * - notify client on new block;
     * - track sync status.
     */
    ethereum.addListener(new EthereumListenerAdapter() {
        @Override
        public void onBlock(Block block, List<TransactionReceipt> receipts) {
            addBlock(block);
        }
    });

    if (!config.isSyncEnabled()) {
        syncStatus = BlockchainInfoService.SyncStatus.DISABLED;
    } else {
        syncStatus = syncManager.isSyncDone() ? SyncStatus.SHORT_SYNC : SyncStatus.LONG_SYNC;
        ethereum.addListener(new EthereumListenerAdapter() {
            @Override
            public void onSyncDone(SyncState state) {
                log.info("Sync done " + state);
                if (syncStatus != BlockchainInfoService.SyncStatus.SHORT_SYNC) {
                    syncStatus = BlockchainInfoService.SyncStatus.SHORT_SYNC;
                }
            }
        });
    }

    final long lastBlock = blockchain.getBestBlock().getNumber();
    final long startImportBlock = Math.max(0,
            lastBlock - Math.max(BLOCK_COUNT_FOR_HASH_RATE, KEEP_BLOCKS_FOR_CLIENT));

    LongStream.rangeClosed(startImportBlock, lastBlock).forEach(i -> addBlock(blockchain.getBlockByNumber(i)));
}

From source file:com.intuit.wasabi.repository.cassandra.impl.CassandraAssignmentsRepository.java

List<Date> getUserAssignmentPartitions(Date fromTime, Date toTime) {
    final LocalDateTime startTime = LocalDateTime.ofInstant(fromTime.toInstant(), ZoneId.systemDefault())
            .withMinute(0).withSecond(0).withNano(0);
    final LocalDateTime endTime = LocalDateTime.ofInstant(toTime.toInstant(), ZoneId.systemDefault())
            .withMinute(0).withSecond(0).withNano(0);
    final long hours = Duration.between(startTime, endTime).toHours();
    return LongStream.rangeClosed(0, hours).mapToObj(startTime::plusHours)
            .map(t -> Date.from(t.atZone(ZoneId.systemDefault()).toInstant())).collect(Collectors.toList());
}

From source file:org.apache.bookkeeper.stream.storage.impl.sc.DefaultStorageContainerController.java

static ClusterAssignmentData initializeIdealState(ClusterMetadata clusterMetadata,
        Set<BookieSocketAddress> currentCluster) {
    List<BookieSocketAddress> serverList = Lists.newArrayListWithExpectedSize(currentCluster.size());
    serverList.addAll(currentCluster);//from  ww w .j  a  va  2 s .  c om
    Collections.shuffle(serverList);

    int numServers = currentCluster.size();
    int numTotalContainers = (int) clusterMetadata.getNumStorageContainers();
    int numContainersPerServer = numTotalContainers / currentCluster.size();

    Map<String, ServerAssignmentData> assignmentMap = Maps.newHashMap();
    for (int serverIdx = 0; serverIdx < serverList.size(); serverIdx++) {
        BookieSocketAddress server = serverList.get(serverIdx);

        int finalServerIdx = serverIdx;
        ServerAssignmentData assignmentData = ServerAssignmentData.newBuilder()
                .addAllContainers(LongStream.rangeClosed(0, numContainersPerServer).boxed()
                        .map(j -> j * numServers + finalServerIdx)
                        .filter(containerId -> containerId < numTotalContainers).collect(Collectors.toSet()))
                .build();
        assignmentMap.put(server.toString(), assignmentData);
    }

    return ClusterAssignmentData.newBuilder().putAllServers(assignmentMap).build();
}

From source file:org.ballerinalang.bre.bvm.BVM.java

private static void execIntegerRangeOpcodes(StackFrame sf, int[] operands) {
    int i = operands[0];
    int j = operands[1];
    int k = operands[2];
    sf.refRegs[k] = new BValueArray(LongStream.rangeClosed(sf.longRegs[i], sf.longRegs[j]).toArray());
}

From source file:org.ballerinalang.bre.bvm.CPU.java

private static void execIntegerRangeOpcodes(WorkerData sf, int[] operands) {
    int i = operands[0];
    int j = operands[1];
    int k = operands[2];
    sf.refRegs[k] = new BIntArray(LongStream.rangeClosed(sf.longRegs[i], sf.longRegs[j]).toArray());
}

From source file:se.sawano.java.security.otp.TOTPService.java

public boolean verify(final TOTP totp, final SharedSecret secret) {
    notNull(totp);//  w w w  .  j a v a2s . c o m
    notNull(secret);

    final long numberOfSteps = numberOfSteps();

    // Make a copy to allow multiple use
    final ShaAlgorithm algorithm = secret.algorithm();
    final byte[] secretBytes = secret.value();

    final boolean isOk = LongStream.rangeClosed(-windowSize.value() / 2, windowSize.value() / 2)
            .map(i -> numberOfSteps + i).mapToObj(steps -> verify(totp, from(secretBytes, algorithm), steps))
            .anyMatch(Boolean.TRUE::equals);

    Arrays.fill(secretBytes, (byte) 0);

    return isOk;
}