Example usage for java.util.stream IntStream rangeClosed

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

Introduction

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

Prototype

public static IntStream rangeClosed(int startInclusive, int endInclusive) 

Source Link

Document

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

Usage

From source file:io.galeb.router.tests.hostselectors.AbstractHashHostSelectorTest.java

void doRandomTest(double errorPercentMax, double limitOfNotHitsPercent, int numPopulation) {
    final HttpServerExchange exchange = new HttpServerExchange(null);
    final Host[] newHosts = numPopulation < hosts.length ? Arrays.copyOf(hosts, numPopulation) : hosts;
    final Map<Integer, String> remains = IntStream.rangeClosed(0, newHosts.length - 1).boxed()
            .collect(Collectors.toMap(x -> x, x -> ""));

    for (int retry = 1; retry <= NUM_RETRIES; retry++) {
        final SummaryStatistics statisticsOfResults = new SummaryStatistics();

        final Map<Integer, Integer> mapOfResults = new HashMap<>();
        new Random().ints(numPopulation).map(Math::abs).forEach(x -> {
            changeExchange(exchange, x);
            int result = getResult(exchange, newHosts);
            Integer lastCount = mapOfResults.get(result);
            remains.remove(result);/*from w  w  w  . j  av a  2 s .c om*/
            mapOfResults.put(result, lastCount != null ? ++lastCount : 0);
        });
        mapOfResults.entrySet().stream().mapToDouble(Map.Entry::getValue)
                .forEach(statisticsOfResults::addValue);
        double errorPercent = (statisticsOfResults.getStandardDeviation() / numPopulation) * 100;
        assertThat(errorPercent, lessThan(errorPercentMax));
    }
    final List<Integer> listOfNotHit = remains.entrySet().stream().map(Map.Entry::getKey).collect(toList());
    assertThat(listOfNotHit.size(), lessThanOrEqualTo((int) (newHosts.length * (limitOfNotHitsPercent / 100))));
}

From source file:ru.jts_dev.common.id.impl.bitset.BitSetIdPoolTest.java

@DirtiesContext
@Test//from   w  ww.j av a 2  s .  c o  m
public void testIdBorrow() {
    IntStream.rangeClosed(1, 10_000).forEach(value -> {
        final int id = idPool.borrow();
        assertThat(id).isEqualTo(value);
    });

    IntStream.rangeClosed(1, 10_000).parallel().forEach(value -> {
        final int id = idPool.borrow();
        assertThat(id).isGreaterThanOrEqualTo(10_000);
    });
}

From source file:org.marekasf.troughput.XYHistogramChart.java

public XYHistogramChart(final AdaptiveHistogram h, final String title) {

    super(title);
    final XYSeries series = new XYSeries(title);

    IntStream.rangeClosed(0, 100).forEach(i -> series.add(i, h.getValueForPercentile(i)));

    final XYSeriesCollection data = new XYSeriesCollection(series);
    final JFreeChart chart = ChartFactory.createXYLineChart("XY Histogram Chart " + title, "X", "Y", data,
            PlotOrientation.VERTICAL, true, true, false);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);/* ww  w  . j a  v  a  2 s.c  om*/
}

From source file:org.fenixedu.spaces.ui.ListOccupationsController.java

@RequestMapping
public String list(Model model,
        @RequestParam(defaultValue = "#{new org.joda.time.DateTime().getMonthOfYear()}") int month,
        @RequestParam(defaultValue = "#{new org.joda.time.DateTime().getYear()}") int year,
        @RequestParam(defaultValue = "") String name) {
    DateTime now = new DateTime();
    int currentYear = now.getYear();
    model.addAttribute("years", IntStream.rangeClosed(currentYear - 100, currentYear + 10).boxed()
            .sorted((o1, o2) -> o2.compareTo(o1)).collect(Collectors.toList()));

    List<Partial> months = IntStream.rangeClosed(1, 12).boxed()
            .map(m -> new Partial(DateTimeFieldType.monthOfYear(), m)).collect(Collectors.toList());
    model.addAttribute("months", months);
    model.addAttribute("currentMonth", month);
    model.addAttribute("currentYear", year);
    model.addAttribute("occupations",
            occupationService.getOccupations(month, year, Authenticate.getUser(), name));
    model.addAttribute("name", name);
    return "occupations/list";
}

From source file:ru.jts_dev.common.id.impl.bitset.BitSetIdPoolTest.java

@DirtiesContext
@Test//from  w w  w. j a v a 2  s  .co  m
public void testIdRelease() {
    IntStream.rangeClosed(1, 20_000).forEach(value -> idPool.borrow());

    IntStream.rangeClosed(1, 20_000).parallel().forEach(value -> idPool.release(value));
}

From source file:io.yields.math.concepts.operator.CurveLength.java

protected Double simpsonIntegration(Function<Double, Double> originalFunction) {
    UnivariateFunction function = getLengthFunction(originalFunction);
    double delta = (max - min) / MAX_EVAL;
    double integral = IntStream.rangeClosed(0, MAX_EVAL).mapToDouble(index -> function.value(index * delta))
            .sum() * delta;//from   w  w w  . j a v a 2 s .c o  m
    return integral - .5 * delta * (function.value(min) + function.value(max));
}

From source file:ru.jts_dev.common.id.impl.bitset.BitSetIdPoolTest.java

@DirtiesContext
@Test//from w  w w  . j  a v a2  s .c o m
public void testIdReusing() {
    IntStream.rangeClosed(1, 20_000).forEach(value -> idPool.borrow());

    IntStream.rangeClosed(1, 20_000).parallel().forEach(value -> idPool.release(value));

    IntStream.rangeClosed(1, 20_000).parallel().forEach(value -> {
        int id = idPool.borrow();
        assertThat(id).isGreaterThanOrEqualTo(1).isLessThanOrEqualTo(20_000);
    });
}

From source file:io.github.pellse.decorator.util.reflection.ReflectionUtils.java

public static DelegateInstantiationInfo findDelegateInstantiationInfo(Class<?> clazz, Class<?> delegateType,
        Class<?>[] otherConstructorParameterTypes) {
    return IntStream.rangeClosed(0, otherConstructorParameterTypes.length)
            .mapToObj(i -> new DelegateInstantiationInfo(
                    getMatchingAccessibleConstructor(clazz,
                            insert(otherConstructorParameterTypes, i, delegateType)),
                    i, findFields(clazz, delegateType, Inject.class)))
            .filter(dii -> dii.getConstructor() != null).findFirst()
            .orElseGet(() -> new DelegateInstantiationInfo(
                    getMatchingAccessibleConstructor(clazz, otherConstructorParameterTypes), -1,
                    findFields(clazz, delegateType, Inject.class)));
}

From source file:com.github.jackygurui.vertxredissonrepository.repository.SaveCustomerCocurrentTest.java

@Test
public void test3SaveCustomerConcurrent(TestContext context) throws Exception {
    Async async = context.async();/* ww w.j  av a  2s .com*/
    JsonNode source = JsonLoader.fromResource("/Customer.json");
    int records = 10000;
    HanyuPinyin.convert("");//warm up
    AtomicLong c = new AtomicLong(0);
    StopWatch sw = new StopWatch();
    sw.start();
    IntStream.rangeClosed(1, records).parallel().forEach(e -> {
        JsonObject clone = new JsonObject(Json.encode(source));
        clone.getJsonObject("personalDetails").put("phoneNumber",
                ((Long.parseLong(clone.getJsonObject("personalDetails").getString("phoneNumber")) + 100 + e)
                        + ""));
        customerRepository.create(Json.encode(clone), r -> {
            AsyncResult<String> result = (AsyncResult<String>) r;
            if (result.failed()) {
                context.fail(result.cause());
                async.complete();
            }
            if (c.incrementAndGet() == records) {
                sw.stop();
                logger.info("time to concurrently save " + records + " customer records: " + sw.getTime());
                async.complete();
            }
        });
    });
}

From source file:com.github.jackygurui.vertxredissonrepository.repository.SaveAndGetCustomerConcurrentWaterfallTest.java

@Test
public void test4SaveAndGetCustomerConcurrentWaterfall(TestContext context) throws Exception {
    Async async = context.async();//from ww w.ja v  a2s  . c  om
    JsonNode source = JsonLoader.fromResource("/Customer.json");
    int records = 10000;
    HanyuPinyin.convert("");//warm up
    AtomicLong counter = new AtomicLong(0);
    StopWatch sw = new StopWatch();
    sw.start();
    IntStream.rangeClosed(1, records).parallel().forEach(e -> {
        JsonObject clone = new JsonObject(Json.encode(source));
        clone.getJsonObject("personalDetails").put("phoneNumber",
                ((Long.parseLong(clone.getJsonObject("personalDetails").getString("phoneNumber")) + 5000 + e)
                        + ""));
        org.simondean.vertx.async.Async.waterfall().<String>task(t -> {
            customerRepository.create(Json.encode(clone), t);
        }).<Customer>task((id, t) -> {
            customerRepository.get(id, t);
        }).run(rr -> {
            long ct = counter.incrementAndGet();
            //                logger.info("Counter = " + ct + " | success = " + !r.failed());
            if (rr.succeeded()) {
                try {
                    Customer loaded = rr.result();
                    Customer c = Json.decodeValue(clone.encode(), Customer.class);
                    c.setId(loaded.getId());
                    c.getAddressDetails().setId(loaded.getId());
                    c.getPersonalDetails().setId(loaded.getId());
                    String encoded = Json.encode(c);
                    if (!rr.result().equals(encoded)) {
                        logger.info(loaded.getId() + " - SOURCE : " + encoded);
                        logger.info(loaded.getId() + " - RESULT : " + rr.result());
                    }
                    context.assertEquals(Json.encode(rr.result()), encoded);
                } catch (Exception ex) {
                    context.fail(ex);
                    async.complete();
                }
            } else {
                context.fail(rr.cause());
                async.complete();
            }
            if (ct == records) {
                sw.stop();
                logger.info("time to concurrently save and get using waterfall " + records
                        + " customer records: " + sw.getTime());
                async.complete();
            }
        });
    });
}