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.vaadin.framework8.demo.restjson.RestDataProvider.java

@Override
public Stream<JsonObject> fetchFromBackEnd(Query<JsonObject, Void> query) {
    URL url;// w  ww  .  ja  v a 2 s. c o m
    try {
        url = new URL(restApiUrl);
        String jsonData = IOUtils.toString(url, StandardCharsets.UTF_8);
        JsonObject json = Json.parse(jsonData);

        JsonArray results = json.getArray("results");
        return stream(results);
    } catch (IOException e) {
        Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Error fetching JSON", e);
        // Must return something which matches size, or grid will keep
        // asking and asking...
        return IntStream.range(0, 200).mapToObj(i -> Json.createObject());
    }
}

From source file:com.simiacryptus.mindseye.test.PCAUtil.java

/**
 * Pca features inv tensor [ ]./*from   w ww.  j  a  v a2 s .c om*/
 *
 * @param covariance        the covariance
 * @param components        the components
 * @param featureDimensions the feature dimensions
 * @param power             the power
 * @return the tensor [ ]
 */
public static Tensor[] pcaFeatures(final RealMatrix covariance, final int components,
        final int[] featureDimensions, final double power) {
    @Nonnull
    final EigenDecomposition decomposition = new EigenDecomposition(covariance);
    final int[] orderedVectors = IntStream.range(0, components).mapToObj(x -> x)
            .sorted(Comparator.comparing(x -> -decomposition.getRealEigenvalue(x))).mapToInt(x -> x).toArray();
    return IntStream.range(0, orderedVectors.length).mapToObj(i -> {
        @Nonnull
        final Tensor src = new Tensor(decomposition.getEigenvector(orderedVectors[i]).toArray(),
                featureDimensions).copy();
        return src.scale(1.0 / src.rms()).scale((Math.pow(decomposition.getRealEigenvalue(orderedVectors[i])
                / decomposition.getRealEigenvalue(orderedVectors[0]), power)));
    }).toArray(i -> new Tensor[i]);
}

From source file:alfio.model.TicketFieldConfigurationDescriptionAndValue.java

public List<TicketFieldValue> getFields() {
    if (count == 1) {
        return Collections.singletonList(new TicketFieldValue(0, 1, value));
    }//ww w.  ja va 2s.  c o m
    List<String> values = StringUtils.isBlank(value) ? Collections.emptyList()
            : Json.fromJson(value, new TypeReference<List<String>>() {
            });
    return IntStream.range(0, count)
            .mapToObj(i -> new TicketFieldValue(i, i + 1, i < values.size() ? values.get(i) : ""))
            .collect(Collectors.toList());

}

From source file:org.gitia.jdataanalysis.data.stats.FilterConstantColumns.java

/**
 * generamos un vector de tamao igual a la cantidad de columnas, colocamos
 * un 1 en las columas que sern quitadas y colocamos un 0 en las columnas a
 * mantener./* ww  w.j  a v a2 s.c o m*/
 *
 * @param matrix
 */
public void fit(SimpleMatrix matrix) {
    colsFiltered = new double[matrix.numCols()];
    int size = matrix.numCols();
    IntStream.range(0, size).parallel()
            .forEach(i -> colsFiltered[i] = (constant(matrix.extractVector(false, i)) ? 1 : 0));
    //        for (int i = 0; i < matrix.numCols(); i++) {
    //            if (constant(matrix.extractVector(false, i))) {
    //                colsFiltered[i] = 1;
    //            } else {
    //                colsFiltered[i] = 0;
    //            }
    //        }
}

From source file:com.github.mavogel.ilias.utils.IOUtils.java

/**
 * Reads and parses a multiple choices from the user.<br>
 * Handles wrong inputs and ensures the choices are meaningful (lo <= up) and in
 * the range of the possible choices.//from   ww w. ja  va 2 s .co m
 *
 * @param choices the possible choices
 * @return the choice of the user.
 */
public static List<Integer> readAndParseChoicesFromUser(final List<?> choices) {
    boolean isCorrectDigits = false, isCorrectRanges = false;
    String line = null;
    List<Integer> digits = null;
    List<String[]> ranges = null;

    Scanner scanner = new Scanner(System.in);
    while (!(isCorrectDigits && isCorrectRanges)) {
        try {
            LOG.info(
                    "Your choice: \n - Comma separated choices and/or ranges (e.g.: 1, 2, 4-6, 8, 10-15 -> or a combination) \n - The Wildcard 'A' for selecting all choices");
            line = scanner.nextLine();

            if (containsWildcard(line)) {
                return IntStream.range(0, choices.size()).mapToObj(Integer::valueOf)
                        .collect(Collectors.toList());
            }
            // == 1
            List<String> trimmedSplit = splitAndTrim(line);
            checkForInvalidCharacters(trimmedSplit);

            // == 2
            digits = parseDigits(trimmedSplit);
            isCorrectDigits = checkInputDigits(choices, digits);

            // == 3
            ranges = parseRanges(trimmedSplit);
            isCorrectRanges = checkRanges(choices, ranges);
        } catch (NumberFormatException nfe) {
            if (!isCorrectDigits) {
                LOG.error("'" + line + "' contains incorrect indexes! Try again");
            }
            if (!isCorrectRanges) {
                LOG.error("'" + line + "' contains incorrect ranges! Try again");
            }
        } catch (Exception e) {
            LOG.error(e.getMessage());
        }
    }

    return concatDigitsAndRanges(digits, ranges);
}

From source file:io.yields.math.framework.property.SortedProperty.java

@Override
public boolean isValid(List<T> value, FunctionalContext<List<T>> context) {
    Validate.notEmpty(value, "An empty collection cannot be ordered.");
    int sign = increasing ? 1 : -1;
    List<T> sorted = value.stream().sorted((t1, t2) -> sign * t1.compareTo(t2)).collect(Collectors.toList());
    return IntStream.range(0, value.size())
            .allMatch(index -> comparator.compare(sorted.get(index), value.get(index)) == 0);
}

From source file:de.bund.bfr.knime.chart.ChartUtils.java

public static List<NamedShape> createShapeList(int n) {
    NamedShape[] shapes = NamedShape.values();

    return IntStream.range(0, n).mapToObj(i -> shapes[i % shapes.length]).collect(Collectors.toList());
}

From source file:Combiner.MaxDepthCombiner.java

public double[][][] combine(double[][][] called, double[][][] imputed, int[][][] reads) {
    double[][][] probs = new double[called.length][][];

    Progress progress = ProgressFactory.get(called.length);

    IntStream.range(0, called.length).parallel().forEach(i -> {
        int l = called[i].length;
        double[][] p = new double[l][];
        probs[i] = p;/*from   w ww  . j ava 2s  .c  om*/
        IntStream.range(0, l).forEach(j -> p[j] = combineSingle(called[i][j], imputed[i][j], reads[i][j]));
        progress.done();
    });

    return probs;
}

From source file:nova.minecraft.wrapper.mc.forge.v17.wrapper.redstone.backward.BWRedstone.java

@Override
public int getOutputWeakPower() {
    return IntStream.range(0, 6).map(side -> block().mcBlock.isProvidingWeakPower(mcWorld(), block().x(),
            block().y(), block().z(), side)).max().orElse(0);
}

From source file:com.firewallid.util.FIUtils.java

public static List<Tuple2<Integer, Double>> vectorToList(Vector v) {
    int[] indices = v.toSparse().indices();
    double[] values = v.toSparse().values();

    List<Tuple2<Integer, Double>> list = IntStream.range(0, indices.length).parallel()
            .mapToObj((int x) -> new Tuple2<Integer, Double>(indices[x], values[x]))
            .collect(Collectors.toList());

    return list;/*  ww  w.ja v a2  s. co  m*/
}