Example usage for java.util.stream Collectors summingInt

List of usage examples for java.util.stream Collectors summingInt

Introduction

In this page you can find the example usage for java.util.stream Collectors summingInt.

Prototype

public static <T> Collector<T, ?, Integer> summingInt(ToIntFunction<? super T> mapper) 

Source Link

Document

Returns a Collector that produces the sum of a integer-valued function applied to the input elements.

Usage

From source file:com.github.sevntu.checkstyle.ordering.MethodOrder.java

public int getRelativeOrderInconsistencyCases() {
    return getMethods().stream().collect(Collectors.summingInt(caller -> {
        int maxCalleeIndex = 0;
        int orderViolations = 0;
        for (final Method callee : getMethodDependenciesInAppearanceOrder(caller)) {
            final int calleeIndex = getMethodIndex(callee);
            if (calleeIndex < maxCalleeIndex) {
                ++orderViolations;/*from w ww .  j  a v a  2  s  .co  m*/
            } else {
                maxCalleeIndex = calleeIndex;
            }
        }
        return orderViolations;
    }));
}

From source file:co.runrightfast.vertx.orientdb.verticle.OrientDBVerticleTest.java

/**
 * Test of startUp method, of class OrientDBVerticle.
 *///  ww w.  java  2  s  . co  m
@Test
public void testVerticle() throws Exception {
    log.info("test_eventBus_GetVerticleDeployments");
    final Vertx vertx = vertxService.getVertx();

    final RunRightFastVerticleId verticleManagerId = RunRightFastVerticleManager.VERTICLE_ID;
    final CompletableFuture<GetVerticleDeployments.Response> getVerticleDeploymentsFuture = new CompletableFuture<>();
    final long timeout = 60000L;
    vertx.eventBus().send(EventBusAddress.eventBusAddress(verticleManagerId, "get-verticle-deployments"),
            GetVerticleDeployments.Request.newBuilder().build(), new DeliveryOptions().setSendTimeout(timeout),
            responseHandler(getVerticleDeploymentsFuture, GetVerticleDeployments.Response.class));
    final GetVerticleDeployments.Response getVerticleDeploymentsResponse = getVerticleDeploymentsFuture
            .get(timeout, TimeUnit.MILLISECONDS);
    final int totalHealthCheckCount = getVerticleDeploymentsResponse.getDeploymentsList().stream()
            .collect(Collectors.summingInt(VerticleDeployment::getHealthChecksCount));

    final CompletableFuture<RunVerticleHealthChecks.Response> future = new CompletableFuture<>();
    vertx.eventBus().send(EventBusAddress.eventBusAddress(verticleManagerId, "run-verticle-healthchecks"),
            RunVerticleHealthChecks.Request.newBuilder().build(),
            addRunRightFastHeaders(new DeliveryOptions().setSendTimeout(timeout)),
            responseHandler(future, RunVerticleHealthChecks.Response.class));

    final RunVerticleHealthChecks.Response response = future.get(timeout, TimeUnit.MILLISECONDS);
    assertThat(response.getResultsCount(), is(totalHealthCheckCount));

}

From source file:com.github.sevntu.checkstyle.ordering.MethodOrder.java

private int translateInitialLineNo(int lineNo) {
    return currentOrdering.stream().filter(method -> {
        final int start = method.getInitialLineNo();
        final int end = start + method.getLength();
        return start <= lineNo && lineNo <= end;
    }).findFirst().map(method -> {//from ww w. ja va2 s . c o  m
        final int initialMethodIndex = initialOrdering.indexOf(method);
        final int currentMethodIndex = currentOrdering.indexOf(method);
        final int sumOfLengthsPresidingMethodsInInitialOrder = initialOrdering.subList(0, initialMethodIndex)
                .stream().collect(Collectors.summingInt(Method::getLength));
        final int sumOfLengthsPresidingMethodInCurrentOrder = currentOrdering.subList(0, currentMethodIndex)
                .stream().collect(Collectors.summingInt(Method::getLength));
        final int change = sumOfLengthsPresidingMethodInCurrentOrder
                - sumOfLengthsPresidingMethodsInInitialOrder;
        return lineNo + change;
    }).orElseThrow(
            () -> new IllegalArgumentException(String.format("Line #%d does lies within any method", lineNo)));
}

From source file:com.epam.catgenome.manager.GffManagerTest.java

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testUnmappedGenes() throws InterruptedException, NoSuchAlgorithmException, FeatureIndexException,
        IOException, GeneReadingException, HistogramReadingException {
    Chromosome testChr1 = EntityHelper.createNewChromosome();
    testChr1.setName("chr1");
    testChr1.setSize(TEST_CHROMOSOME_SIZE);
    Reference testRef = EntityHelper.createNewReference(testChr1, referenceGenomeManager.createReferenceId());

    referenceGenomeManager.register(testRef);
    Long testRefId = testReference.getId();

    Resource resource = context.getResource("classpath:templates/mrna.sorted.chunk.gtf");

    FeatureIndexedFileRegistrationRequest request = new FeatureIndexedFileRegistrationRequest();
    request.setReferenceId(testRefId);/*ww  w  .j  ava 2  s .  com*/
    request.setPath(resource.getFile().getAbsolutePath());

    GeneFile geneFile = gffManager.registerGeneFile(request);
    Assert.assertNotNull(geneFile);
    Assert.assertNotNull(geneFile.getId());

    Track<Gene> track = new Track<>();
    track.setId(geneFile.getId());
    track.setStartIndex(1);
    track.setEndIndex(TEST_UNMAPPED_END_INDEX);
    track.setChromosome(testChr1);
    track.setScaleFactor(FULL_QUERY_SCALE_FACTOR);

    double time1 = Utils.getSystemTimeMilliseconds();
    Track<Gene> featureList = gffManager.loadGenes(track, false);
    double time2 = Utils.getSystemTimeMilliseconds();
    logger.info("genes loading : {} ms", time2 - time1);
    Assert.assertNotNull(featureList);
    Assert.assertFalse(featureList.getBlocks().isEmpty());
    Assert.assertTrue(featureList.getBlocks().stream().allMatch(g -> !g.isMapped()));

    Track<Gene> smallScaleFactorTrack = new Track<>();
    smallScaleFactorTrack.setId(geneFile.getId());
    smallScaleFactorTrack.setStartIndex(1);
    smallScaleFactorTrack.setEndIndex(TEST_UNMAPPED_END_INDEX);
    smallScaleFactorTrack.setChromosome(testChr1);
    smallScaleFactorTrack.setScaleFactor(SMALL_SCALE_FACTOR);

    time1 = Utils.getSystemTimeMilliseconds();
    featureList = gffManager.loadGenes(smallScaleFactorTrack, false);
    time2 = Utils.getSystemTimeMilliseconds();
    logger.info("genes large scale loading : {} ms", time2 - time1);
    Assert.assertNotNull(featureList);
    Assert.assertFalse(featureList.getBlocks().isEmpty());
    Assert.assertTrue(featureList.getBlocks().stream().allMatch(g -> !g.isMapped()));
    int groupedGenesCount = featureList.getBlocks().stream()
            .collect(Collectors.summingInt(Gene::getFeatureCount));
    logger.debug("{} features total", groupedGenesCount);
    Assert.assertEquals(TEST_FEATURE_COUNT, groupedGenesCount);

    Track<Wig> histogram = new Track<>();
    histogram.setId(geneFile.getId());
    histogram.setChromosome(testChr1);
    histogram.setScaleFactor(1.0);

    gffManager.loadHistogram(histogram);
    Assert.assertFalse(histogram.getBlocks().isEmpty());
}

From source file:com.epam.catgenome.manager.GffManagerTest.java

private void testFillRange(List<Block> exons, int viewPortSize, int centerPosition, boolean forward,
        int bound) {
    int totalLength = exons.stream()
            .collect(Collectors.summingInt(e -> gffManager.calculateExonLength(e, centerPosition, forward)));

    boolean isBounded;
    if (forward) {
        isBounded = exons.get(exons.size() - 1).getEndIndex() >= bound;
    } else {/*w  w  w.  jav  a2s.co m*/
        isBounded = exons.get(0).getStartIndex() <= bound;
    }

    Assert.assertTrue(totalLength >= viewPortSize || isBounded);
}