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:com.epam.ta.reportportal.demo_data.DemoLogsService.java

List<Log> generateDemoLogs(String itemId, String status) {
    try (BufferedReader errorsBufferedReader = new BufferedReader(
            new InputStreamReader(errorLogsResource.getInputStream(), UTF_8));
            BufferedReader demoLogsBufferedReader = new BufferedReader(
                    new InputStreamReader(demoLogs.getInputStream(), UTF_8))) {
        String error = errorsBufferedReader.lines().collect(Collectors.joining("\n"));
        List<String> logMessages = demoLogsBufferedReader.lines().collect(toList());
        int t = random.nextInt(30);
        List<Log> logs = IntStream.range(1, t + 1).mapToObj(it -> {
            Log log = new Log();
            log.setLevel(logLevel());//from www .  ja va  2s.c om
            log.setLogTime(new Date());
            log.setTestItemRef(itemId);
            log.setLogMsg(logMessages.get(random.nextInt(logMessages.size())));
            return log;
        }).collect(toList());
        if (FAILED.name().equals(status)) {
            String file = dataStorage.saveData(
                    new BinaryData(IMAGE_PNG_VALUE, img.contentLength(), img.getInputStream()), "file");
            Log log = new Log();
            log.setLevel(ERROR);
            log.setLogTime(new Date());
            log.setTestItemRef(itemId);
            log.setLogMsg(error);
            final BinaryContent binaryContent = new BinaryContent(file, file, IMAGE_PNG_VALUE);
            log.setBinaryContent(binaryContent);
            logs.add(log);
        }
        return logRepository.save(logs);
    } catch (IOException e) {
        throw new ReportPortalException("Unable to generate demo logs", e);
    }
}

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

private static Set<BookieSocketAddress> newCluster(int numServers) {
    Set<BookieSocketAddress> cluster = IntStream.range(0, numServers)
            .mapToObj(idx -> new BookieSocketAddress("127.0.0.1", 4181 + idx)).collect(Collectors.toSet());
    return ImmutableSet.copyOf(cluster);
}

From source file:alfio.manager.EventNameManager.java

private String generateRandomName() {
    return IntStream.range(0, 5).mapToObj(i -> RandomStringUtils.randomAlphanumeric(15)).filter(this::isUnique)
            .limit(1).findFirst().orElse("");
}

From source file:nova.core.util.RayTracer.java

/**
 * Check all blocks that are in a line//from w  w w  .jav  a  2s.  c o m
 * @return The blocks ray traced in the order from closest to furthest.
 */
public Stream<RayTraceBlockResult> rayTraceBlocks(World world) {
    //All relevant blocks
    return rayTraceBlocks(
            IntStream.range(0, (int) distance + 1).mapToObj(i -> ray.origin.add(ray.dir.scalarMultiply(i)))
                    .flatMap(vec -> Arrays.stream(Direction.VALID_DIRECTIONS)
                            .map(direction -> Vector3DUtil.floor(vec.add(direction.toVector())))) //Cover a larger area to be safe
                    .distinct().map(world::getBlock).filter(Optional::isPresent).map(Optional::get));
}

From source file:es.uvigo.ei.sing.laimages.core.operations.Interpolator.java

private static double[][] calculateNewValues(double[][] data, int interpolationLevel) {
    final int initialRows = data.length;
    final int initialColumns = data[0].length;

    final BivariateGridInterpolator interpolator = new BilinearInterpolator();
    final BivariateFunction function = interpolator.interpolate(
            IntStream.range(0, initialRows).asDoubleStream().toArray(),
            IntStream.range(0, initialColumns).asDoubleStream().toArray(), data);

    final int newNumRows = CALCULATE_SIZE.applyAsInt(initialRows, interpolationLevel);
    final int newNumColumns = CALCULATE_SIZE.applyAsInt(initialColumns, interpolationLevel);

    final double[][] newValues = new double[newNumRows][newNumColumns];

    final double xFactor = ((double) initialRows - 1d) / ((double) newNumRows - 1d);
    final double yFactor = ((double) initialColumns - 1d) / ((double) newNumColumns - 1d);
    for (int i = 0; i < newValues.length; i++) {
        for (int j = 0; j < newValues[i].length; j++) {
            newValues[i][j] = function.value((double) i * xFactor, (double) j * yFactor);
        }//from   ww  w .  j a  va 2 s  .  co m
    }

    return newValues;
}

From source file:org.lenskit.pf.PMFModel.java

public void initialize(double weightShpPrior, double activityShpPrior, double meanActivityPrior,
        int userOrItemNum, int featureCount, double maxOffsetShp, double maxOffsetRte, Random random) {
    final double activityRte = activityShpPrior + featureCount;
    PMFModel model = IntStream.range(0, userOrItemNum).parallel().mapToObj(e -> {
        ModelEntry entry = new ModelEntry(e, featureCount, weightShpPrior, activityShpPrior, meanActivityPrior);
        for (int k = 0; k < featureCount; k++) {
            double valueShp = weightShpPrior + maxOffsetShp * random.nextDouble();
            double valueRte = activityShpPrior + maxOffsetRte * random.nextDouble();
            entry.setWeightShpEntry(k, valueShp);
            entry.setWeightRteEntry(k, valueRte);
        }//  ww w . j  a va2s  .  c om
        double activityShp = activityShpPrior + maxOffsetShp * random.nextDouble();
        entry.setActivityRte(activityRte);
        entry.setActivityShp(activityShp);
        return entry;
    }).collect(new PMFModelCollector());
    addAll(model);
}

From source file:com.github.robozonky.app.version.UpdateMonitor.java

static VersionIdentifier parseNodeList(final NodeList nodeList) {
    final SortedSet<String> versions = IntStream.range(0, nodeList.getLength()).mapToObj(nodeList::item)
            .map(Node::getTextContent)
            .collect(Collectors.toCollection(() -> new TreeSet<>(new VersionComparator().reversed())));
    // find latest stable
    final String firstStable = UpdateMonitor.findFirstStable(versions);
    // and check if it is followed by any other unstable versions
    final String first = versions.first();
    if (Objects.equals(first, firstStable)) {
        return new VersionIdentifier(firstStable);
    } else {/*from   w w w . j a  v a 2s.c  o m*/
        return new VersionIdentifier(firstStable, first);
    }
}

From source file:org.gradoop.flink.model.impl.operators.matching.single.cypher.planning.queryplan.unary.ProjectEmbeddingsNode.java

@Override
protected EmbeddingMetaData computeEmbeddingMetaData() {
    final EmbeddingMetaData childMetaData = getChildNode().getEmbeddingMetaData();

    projectionKeys.sort(//w  w w.j a  v a 2s.c  o m
            Comparator.comparingInt(key -> childMetaData.getPropertyColumn(key.getLeft(), key.getRight())));

    EmbeddingMetaData embeddingMetaData = new EmbeddingMetaData();

    childMetaData.getVariables().forEach(var -> embeddingMetaData.setEntryColumn(var,
            childMetaData.getEntryType(var), childMetaData.getEntryColumn(var)));

    IntStream.range(0, projectionKeys.size()).forEach(i -> embeddingMetaData
            .setPropertyColumn(projectionKeys.get(i).getLeft(), projectionKeys.get(i).getRight(), i));

    return embeddingMetaData;
}

From source file:org.apache.samza.tools.benchmark.SystemConsumerBench.java

Set<SystemStreamPartition> createSSPs(String systemName, String physicalStreamName, int startPartition,
        int endPartition) {
    return IntStream.range(startPartition, endPartition)
            .mapToObj(x -> new SystemStreamPartition(systemName, physicalStreamName, new Partition(x)))
            .collect(Collectors.toSet());
}

From source file:nl.salp.warcraft4j.dev.casc.dbc.DbcFilenameGenerator.java

public void execute() {
    int cores = 32;
    int generators = 1;
    int consumers = cores - generators;

    ExecutorService executorService = Executors.newFixedThreadPool(cores);
    Generator generator = new Generator(CHARS, maxLength);
    /*//from w ww  .ja  v  a2 s  . c  o m
    IntStream.range(0, consumers).forEach(i -> executorService.execute(() -> {
    LOGGER.debug("Started consumer {}", i);
    Consumer<String> consumer = this.consumer.get();
    String val = null;
    //long tryCount = 0;
    while (generator.isAvailable() || !queue.isEmpty()) {
        while (val == null && (generator.isAvailable() || !queue.isEmpty())) {
            //tryCount++;
            try {
                val = queue.poll(10, TimeUnit.MILLISECONDS);
            } catch (InterruptedException e) {
            }
            //if (tryCount % 1000 == 0) {
            //    LOGGER.debug("Starvation for consumer {} with {} tries", i);
            //}
        }
        if (val != null) {
            //tryCount = 0;
            consumer.accept(val);
            val = null;
        }
    }
    LOGGER.debug("Shutting down consumer {}", i);
    }));
    */
    IntStream.range(0, generators).forEach(i -> executorService.execute(() -> {
        LOGGER.debug("Started generator {}", i);
        while (generator.isAvailable()) {
            String value = generator.next();
            //add(format(FORMAT_DBC, value));
            //add(format(FORMAT_DB2, value));
        }
        LOGGER.debug("Shutting down generator {}", i);
    }));

    LOGGER.debug("Done...");
    executorService.shutdown();
}