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.TestAsyncTable.java

@Test
public void testCheckAndPut() throws InterruptedException, ExecutionException {
    AsyncTableBase table = getTable.get();
    AtomicInteger successCount = new AtomicInteger(0);
    AtomicInteger successIndex = new AtomicInteger(-1);
    int count = 10;
    CountDownLatch latch = new CountDownLatch(count);
    IntStream.range(0, count)
            .forEach(/*from   ww w  .  java  2  s .com*/
                    i -> table
                            .checkAndPut(row, FAMILY, QUALIFIER, null,
                                    new Put(row).addColumn(FAMILY, QUALIFIER, concat(VALUE, i)))
                            .thenAccept(x -> {
                                if (x) {
                                    successCount.incrementAndGet();
                                    successIndex.set(i);
                                }
                                latch.countDown();
                            }));
    latch.await();
    assertEquals(1, successCount.get());
    String actual = Bytes.toString(table.get(new Get(row)).get().getValue(FAMILY, QUALIFIER));
    assertTrue(actual.endsWith(Integer.toString(successIndex.get())));
}

From source file:org.lightjason.agentspeak.action.builtin.TestCActionStorage.java

/**
 * test clear action with key stream// w  w w  .ja v a 2 s.c  o m
 */
@Test
public final void clearwithkeystream() {
    Assume.assumeNotNull(m_context);

    IntStream.range(0, 100)
            .forEach(i -> m_context.agent().storage().put(MessageFormat.format("value {0}", i), i));

    Assert.assertEquals(m_context.agent().storage().size(), 100);

    new CClear(Stream.of("value 7", "value 23", "value 91")).execute(false, m_context, Collections.emptyList(),
            Collections.emptyList());

    Assert.assertEquals(m_context.agent().storage().size(), 3);
    Assert.assertArrayEquals(m_context.agent().storage().keySet().toArray(),
            Stream.of("value 7", "value 23", "value 91").toArray());
    Assert.assertArrayEquals(m_context.agent().storage().values().toArray(), Stream.of(7, 23, 91).toArray());
}

From source file:com.vsthost.rnd.DMatrixUtilsTest.java

/**
 * Testing ZMBD multiple times with predefined args.
 */
public void testMultipleZMBD() {
    IntStream.range(0, 1000).forEach(e -> this.testZmbd());
}

From source file:com.vsthost.rnd.commons.math.ext.linear.DMatrixUtils.java

/**
 * Get the order of the elements in descending or ascending order.
 *
 * @param values A vector of integer values.
 * @param descending Flag indicating if we go descending or not.
 * @return A vector of indices sorted in the provided order.
 *//*from w  w w  . ja va 2  s.c  o m*/
public static int[] getOrder(int[] values, boolean descending) {
    return DMatrixUtils.getOrder(values, IntStream.range(0, values.length).toArray(), descending);
}

From source file:org.lightjason.examples.pokemon.simulation.agent.pokemon.CPokemon.java

@Override
public final void spriteinitialize(final int p_rows, final int p_columns, final int p_cellsize,
        final float p_unit) {
    m_sprite = CDefinition.INSTANCE.tupel(m_pokemon, 0).sprite(p_cellsize, p_unit);
    m_attack.values().forEach(i -> CParticleSystem.INSTANCE.initialize(i.particlesystem(), p_unit));

    // initialize all other sprites and particle systems
    IntStream.range(1, CDefinition.INSTANCE.level(m_pokemon)).parallel()
            .forEach(i -> CDefinition.INSTANCE.tupel(m_pokemon, i).sprite(p_cellsize, p_unit));
    IntStream.range(1, CDefinition.INSTANCE.level(m_pokemon)).boxed()
            .flatMap(i -> CDefinition.INSTANCE.tupel(m_pokemon, i).attack().stream())
            .forEach(i -> CParticleSystem.INSTANCE.initialize(i.particlesystem(), p_unit));
}

From source file:org.apache.hadoop.hbase.master.assignment.AssignmentManagerUtil.java

static void removeNonDefaultReplicas(MasterProcedureEnv env, Stream<RegionInfo> regions,
        int regionReplication) {
    // Remove from in-memory states
    regions.flatMap(hri -> IntStream.range(1, regionReplication)
            .mapToObj(i -> RegionReplicaUtil.getRegionInfoForReplica(hri, i))).forEach(hri -> {
                env.getAssignmentManager().getRegionStates().deleteRegion(hri);
                env.getMasterServices().getServerManager().removeRegion(hri);
                FavoredNodesManager fnm = env.getMasterServices().getFavoredNodesManager();
                if (fnm != null) {
                    fnm.deleteFavoredNodesForRegions(Collections.singletonList(hri));
                }/*from w w w.  ja  va 2  s . c  o m*/
            });
}

From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java

private void getByListBlocking(List<String> ids, AsyncResultHandler<List<T>> resultHandler) {
    if (ids == null) {
        resultHandler.handle(Future.failedFuture(new IllegalArgumentException("List of ids can't be null.")));
        return;//from w  ww .j a va  2 s . co m
    } else if (ids.isEmpty()) {
        resultHandler.handle(Future.succeededFuture(Collections.emptyList()));
        return;
    }
    AtomicLong c = new AtomicLong(0);
    ArrayList<T> l = new ArrayList<>(ids.size());
    IntStream.range(0, ids.size()).forEach(i -> l.add(null));
    ids.stream().forEach(e -> {
        getBlocking(e, r -> {
            l.set(ids.indexOf(e), r.result());
            if (c.incrementAndGet() == ids.size()) {
                resultHandler.handle(Future.succeededFuture(
                        l.stream().filter(s -> s != null).collect(Collectors.toCollection(ArrayList::new))));
            }
        });
    });
}

From source file:org.lightjason.agentspeak.action.builtin.TestCActionAgent.java

/**
 * test belieflist/* w ww .  j  a  va  2 s  . c o m*/
 */
@Test
public final void belieflist() {
    final List<ITerm> l_return = new ArrayList<>();
    final Set<String> l_list = IntStream.range(0, 100)
            .mapToObj(i -> RandomStringUtils.random(12, "abcdefghijklmnop"))
            .peek(i -> m_context.agent().beliefbase().add(CLiteral.from(i))).collect(Collectors.toSet());

    Assert.assertEquals(m_context.agent().beliefbase().size(), 100);

    new CBeliefList().execute(false, m_context, Collections.emptyList(), l_return);

    Assert.assertEquals(l_return.size(), 1);
    Assert.assertTrue(l_return.get(0).raw() instanceof List<?>);

    Assert.assertTrue(l_return.get(0).<List<ILiteral>>raw().stream().map(i -> i.fqnfunctor().toString())
            .allMatch(l_list::contains));
}

From source file:ijfx.ui.display.image.DefaultFXImageDisplay.java

public int[] getCompositeChannels() {
    if (getDatasetView().getProjector() == null) {
        return new int[0];
    }//from  w ww. java2s .  c  om
    return IntStream.range(0, getChannelNumber()).filter(i -> getDatasetView().getProjector().isComposite(i))
            .toArray();
}

From source file:com.wso2.code.quality.matrices.ChangesFinder.java

/**
 * This method is used to save the line ranges being modified in a given file to a list and add that list to the root list of
 *
 * @param fileNames   Arraylist of files names that are being affected by the relevant commit
 * @param patchString Array list having the patch string value for each of the file being changed
 */// w w  w.  j  a  va  2  s . c om

public void saveRelaventEditLineNumbers(ArrayList<String> fileNames, ArrayList<String> patchString) {
    //filtering only the line ranges that are modified and saving to a string array

    // cannot ues parallel streams here as the order of the line changes must be preserved
    patchString.stream().map(patch -> StringUtils.substringsBetween(patch, "@@ ", " @@"))
            .forEach(lineChanges -> {
                //filtering the lines ranges that existed in the previous file, that exists in the new file and saving them in to the same array
                IntStream.range(0, lineChanges.length).forEach(j -> {
                    //@@ -22,7 +22,7 @@ => -22,7 +22,7 => 22,28/22,28
                    String tempString = lineChanges[j];
                    String lineRangeInTheOldFileBeingModified = StringUtils.substringBetween(tempString, "-",
                            " +"); // for taking the authors and commit hashes of the previous lines
                    String lineRangeInTheNewFileResultedFromModification = StringUtils
                            .substringAfter(tempString, "+"); // for taking the parent commit

                    int intialLineNoInOldFile = Integer
                            .parseInt(StringUtils.substringBefore(lineRangeInTheOldFileBeingModified, ","));
                    int tempEndLineNoInOldFile = Integer
                            .parseInt(StringUtils.substringAfter(lineRangeInTheOldFileBeingModified, ","));
                    int endLineNoOfOldFile;
                    if (intialLineNoInOldFile != 0) {
                        // to filterout the newly created files
                        endLineNoOfOldFile = intialLineNoInOldFile + (tempEndLineNoInOldFile - 1);
                    } else {
                        endLineNoOfOldFile = tempEndLineNoInOldFile;
                    }
                    int intialLineNoInNewFile = Integer.parseInt(
                            StringUtils.substringBefore(lineRangeInTheNewFileResultedFromModification, ","));
                    int tempEndLineNoInNewFile = Integer.parseInt(
                            StringUtils.substringAfter(lineRangeInTheNewFileResultedFromModification, ","));
                    int endLineNoOfNewFile = intialLineNoInNewFile + (tempEndLineNoInNewFile - 1);
                    // storing the line ranges that are being modified in the same array by replacing values
                    lineChanges[j] = intialLineNoInOldFile + "," + endLineNoOfOldFile + "/"
                            + intialLineNoInNewFile + "," + endLineNoOfNewFile;
                });
                ArrayList<String> tempArrayList = new ArrayList<>(Arrays.asList(lineChanges));
                //adding to the array list which keep track of the line ranges being changed
                lineRangesChanged.add(tempArrayList);
            });
    System.out.println("done saving file names and their relevant modification line ranges");
    System.out.println(fileNames);
    System.out.println(lineRangesChanged + "\n");
}