Example usage for java.util.stream IntStream range

List of usage examples for java.util.stream IntStream range

Introduction

In this page you can find the example usage for java.util.stream IntStream range.

Prototype

public static IntStream range(int startInclusive, int endExclusive) 

Source Link

Document

Returns a sequential ordered IntStream from startInclusive (inclusive) to endExclusive (exclusive) by an incremental step of 1 .

Usage

From source file:org.apache.hadoop.hbase.client.TestAsyncNonMetaRegionLocator.java

@Test
public void testMultiRegionTable() throws IOException, InterruptedException {
    createMultiRegionTable();/*from w  ww.ja v  a2 s  .co  m*/
    byte[][] startKeys = getStartKeys();
    ServerName[] serverNames = getLocations(startKeys);
    IntStream.range(0, 2).forEach(n -> IntStream.range(0, startKeys.length).forEach(i -> {
        try {
            assertLocEquals(startKeys[i], i == startKeys.length - 1 ? EMPTY_END_ROW : startKeys[i + 1],
                    serverNames[i],
                    LOCATOR.getRegionLocation(TABLE_NAME, startKeys[i], RegionLocateType.CURRENT).get());
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException(e);
        }
    }));

    LOCATOR.clearCache(TABLE_NAME);
    IntStream.range(0, 2).forEach(n -> IntStream.range(0, startKeys.length).forEach(i -> {
        try {
            assertLocEquals(startKeys[i], i == startKeys.length - 1 ? EMPTY_END_ROW : startKeys[i + 1],
                    serverNames[i],
                    LOCATOR.getRegionLocation(TABLE_NAME, startKeys[i], RegionLocateType.AFTER).get());
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException(e);
        }
    }));
    LOCATOR.clearCache(TABLE_NAME);
    byte[][] endKeys = getEndKeys();
    IntStream.range(0, 2)
            .forEach(n -> IntStream.range(0, endKeys.length).map(i -> endKeys.length - 1 - i).forEach(i -> {
                try {
                    assertLocEquals(i == 0 ? EMPTY_START_ROW : endKeys[i - 1], endKeys[i], serverNames[i],
                            LOCATOR.getRegionLocation(TABLE_NAME, endKeys[i], RegionLocateType.BEFORE).get());
                } catch (InterruptedException | ExecutionException e) {
                    throw new RuntimeException(e);
                }
            }));
}

From source file:org.lightjason.agentspeak.common.CPath.java

@Override
public final synchronized IPath toUpper() {
    IntStream.range(0, m_path.size()).boxed().parallel()
            .forEach(i -> m_path.set(i, m_path.get(i).toUpperCase()));
    return this;
}

From source file:de.flashpixx.rrd_antlr4.engine.template.CHTML.java

@Override
protected final String choice(final IGrammarChoice p_element) {
    final String l_child = StringUtils.join(IntStream.range(0, p_element.get().size()).boxed()
            .map(i -> this.map(p_element.get().get(i))).filter(i -> i != null).collect(Collectors.toList()),
            ", ");

    return p_element.get().size() == 1 ? l_child : MessageFormat.format("Choice({0}, {1})", 0, l_child);
}

From source file:kishida.cnn.layers.ConvolutionLayer.java

@Override
public void prepareBatch() {
    float momentam = parent.getMomentam();
    IntStream.range(0, filterDelta.length).parallel().forEach(i -> filterDelta[i] = filterDelta[i] * momentam);
    IntStream.range(0, biasDelta.length).parallel().forEach(i -> biasDelta[i] = biasDelta[i] * momentam);
}

From source file:nl.rivm.cib.episim.model.disease.infection.MSEIRSTest.java

private <T> Observable<Entry<T, Stream<BigDecimal>>> averages(
        final Supplier<Observable<Entry<Double, long[]>>> sir, final Function<Double, T> bins, final int n) {
    return Observable.create(sub -> {
        final NavigableMap<T, long[]> sums = java.util.Collections
                .synchronizedNavigableMap(new TreeMap<T, long[]>());
        final long t0 = System.currentTimeMillis();
        final AtomicInteger iteration = new AtomicInteger();
        final AtomicLong sysTime = new AtomicLong(t0);
        Observable.range(0, n).flatMap(i -> Observable.just(i).subscribeOn(Schedulers.computation()).map(ii -> {
            final int iii = iteration.incrementAndGet();
            final long t = System.currentTimeMillis();
            sysTime.updateAndGet(t1 -> {
                if (t - t1 > 10000) {
                    LOG.trace("Progress {}% at ~{}/s, iteration {} of {}",
                            DecimalUtil.floor(DecimalUtil.divide(iii * 100, n)),
                            DecimalUtil.round(DecimalUtil.divide(iii * 1000, t - t0)), iii, n);
                    return t;
                }/*from  ww  w . java2  s. c o m*/
                return t1;
            });
            return sir.get()
                    // group by bin size
                    .groupBy(yt -> bins.apply(yt.getKey()))
                    // take highest floating point t in this bin
                    .flatMap(gr -> gr.reduce((yt1, yt2) -> yt1.getKey().compareTo(yt2.getKey()) > 0 ? yt1 : yt2)
                            .toObservable().map(yt -> Collections.entry(gr.getKey(), yt.getValue())))
                    // add to current sums
                    .collect(() -> sums,
                            (sum, yt) -> sum.compute(yt.getKey(),
                                    (k, v) -> v == null ? yt.getValue()
                                            : IntStream.range(0, v.length)
                                                    .mapToLong(iv -> v[iv] + yt.getValue()[iv]).toArray()))
                    .blockingGet();
        })).blockingSubscribe();

        sums.forEach((k, v) -> sub
                .onNext(Collections.entry(k, Arrays.stream(v).mapToObj(y -> DecimalUtil.divide(y, n)))));
        final long dt = System.currentTimeMillis() - t0;
        LOG.trace("Completed {} iterations in {}s = {}/s", n,
                DecimalUtil.toScale(DecimalUtil.divide(dt, 1000), 1),
                DecimalUtil.round(DecimalUtil.divide(n * 1000, dt)));
    });
}

From source file:org.apache.tinkerpop.gremlin.tinkergraph.structure.IoDataGenerationTest.java

@Test
public void shouldWriteSampleForGremlinServer() throws IOException {
    final Graph g = TinkerGraph.open();
    IntStream.range(0, 10000).forEach(i -> g.addVertex("oid", i));
    DistributionGenerator.build(g).label("knows").seedGenerator(() -> 987654321l)
            .outDistribution(new PowerLawDistribution(2.1)).inDistribution(new PowerLawDistribution(2.1))
            .expectedNumEdges(100000).create().generate();

    final OutputStream os = new FileOutputStream(tempPath + "sample.kryo");
    GryoWriter.build().create().writeGraph(os, g);
    os.close();//from  w  w  w .j  a  v  a  2 s. c  om
}

From source file:org.apache.sysml.runtime.controlprogram.paramserv.LocalPSWorker.java

private ListObject accrueGradients(ListObject accGradients, ListObject gradients) {
    IntStream.range(0, accGradients.getLength()).forEach(i -> {
        MatrixBlock mb1 = ((MatrixObject) accGradients.getData().get(i)).acquireRead();
        MatrixBlock mb2 = ((MatrixObject) gradients.getData().get(i)).acquireRead();
        mb1.binaryOperationsInPlace(new BinaryOperator(Plus.getPlusFnObject()), mb2);
        ((MatrixObject) accGradients.getData().get(i)).release();
        ((MatrixObject) gradients.getData().get(i)).release();
    });//from ww  w  .j av a2 s. c  o  m
    return accGradients;
}

From source file:org.apache.tinkerpop.gremlin.server.GremlinServerSessionIntegrateTest.java

@Test
public void shouldEnsureSessionBindingsAreThreadSafe() throws Exception {
    final Cluster cluster = Cluster.open();
    final Client client = cluster.connect(name.getMethodName());

    client.submitAsync("a=100;b=1000;c=10000;null");
    final int requests = 1000;
    final List<CompletableFuture<ResultSet>> futures = new ArrayList<>(requests);
    IntStream.range(0, requests).forEach(i -> {
        try {//w  w w.ja v  a 2 s.c o m
            futures.add(client.submitAsync("a+b+c"));
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    });

    assertEquals(requests, futures.size());

    for (CompletableFuture<ResultSet> f : futures) {
        final Result r = f.get().one();
        assertEquals(11100, r.getInt());
    }

    client.close();
    cluster.close();
}

From source file:nl.salp.warcraft4j.fileformat.dbc.DbcFile.java

/**
 * Get all ID values of all entries, in the same order as in the file.
 *
 * @return The ID values of the entries in the file.
 *
 * @throws DbcParsingException When the IDs could not be parsed.
 *//*from   w w  w  .j  av  a  2  s.co  m*/
public int[] getEntryIds() throws DbcParsingException {
    DbcHeader header = getHeader();
    try (DataReader reader = getDataReader()) {
        return IntStream.range(0, header.getEntryCount()).map(i -> getEntryId(i, reader)).toArray();
    } catch (IOException e) {
        throw new DbcParsingException(
                format("Error parsing entry IDs for DBC file %d (%s)", filenameHash, filename), e);
    }
}

From source file:org.apache.hadoop.hbase.client.TestAsyncTable.java

@Test
public void testAppend() throws InterruptedException, ExecutionException {
    AsyncTableBase table = getTable.get();
    int count = 10;
    CountDownLatch latch = new CountDownLatch(count);
    char suffix = ':';
    AtomicLong suffixCount = new AtomicLong(0L);
    IntStream.range(0, count).forEachOrdered(i -> table
            .append(new Append(row).add(FAMILY, QUALIFIER, Bytes.toBytes("" + i + suffix))).thenAccept(r -> {
                suffixCount.addAndGet(//from   ww w . j  a  v a  2  s .  c  om
                        Bytes.toString(r.getValue(FAMILY, QUALIFIER)).chars().filter(x -> x == suffix).count());
                latch.countDown();
            }));
    latch.await();
    assertEquals((1 + count) * count / 2, suffixCount.get());
    String value = Bytes
            .toString(table.get(new Get(row).addColumn(FAMILY, QUALIFIER)).get().getValue(FAMILY, QUALIFIER));
    int[] actual = Arrays.asList(value.split("" + suffix)).stream().mapToInt(Integer::parseInt).sorted()
            .toArray();
    assertArrayEquals(IntStream.range(0, count).toArray(), actual);
}