java.util.stream.Collectors.summingInt()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(322)

本文整理了Java中java.util.stream.Collectors.summingInt()方法的一些代码示例,展示了Collectors.summingInt()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collectors.summingInt()方法的具体详情如下:
包路径:java.util.stream.Collectors
类名称:Collectors
方法名:summingInt

Collectors.summingInt介绍

暂无

代码示例

代码示例来源:origin: zalando/zalenium

@Override
public List<MetricFamilySamples> collect() {
  GaugeMetricFamily testSessionMetric = new GaugeMetricFamily("selenium_test_sessions_running",
      "The number of Selenium test sessions that are running by proxy type",
      Collections.singletonList("proxy"));
  Iterable<RemoteProxy> iterable = () -> proxySet.iterator();
  Map<String, Integer> countByProxies = StreamSupport.stream(iterable.spliterator(), false).collect(
      Collectors.groupingBy(p -> p.getClass().getSimpleName(), Collectors.summingInt(p -> p.getTotalUsed())));
  
  countByProxies.entrySet().stream()
      .forEach(e -> testSessionMetric.addMetric(Collections.singletonList(e.getKey()), e.getValue()));
  List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>();
  mfs.add(testSessionMetric);
  return mfs;
}

代码示例来源:origin: Vedenin/useful-java-links

long sumOdd = numbers.stream().collect(Collectors.summingInt(((p) -> p % 2 == 1 ? p : 0)));
System.out.println("sumOdd = " + sumOdd); // print  sumEven = 4

代码示例来源:origin: apache/opennlp

public LeipzigLanguageSampleStream(File leipzigFolder, final int sentencesPerSample,
                  final int samplesPerLanguage) throws IOException {
 this.sentencesPerSample = sentencesPerSample;
 sentencesFiles = leipzigFolder.listFiles(new FileFilter() {
  @Override
  public boolean accept(File pathname) {
   return !pathname.isHidden() && pathname.isFile()
       && pathname.getName().length() >= 3
       && pathname.getName().substring(0,3).matches("[a-z]+");
  }
 });
 Arrays.sort(sentencesFiles);
 Map<String, Integer> langCounts = Arrays.stream(sentencesFiles)
   .map(file -> file.getName().substring(0, 3))
   .collect(Collectors.groupingBy(String::toString, Collectors.summingInt(v -> 1)));
 langSampleCounts = langCounts.entrySet().stream()
   .collect(Collectors.toMap(Map.Entry::getKey, e -> samplesPerLanguage / e.getValue()));
 random = new Random(23);
 reset();
}

代码示例来源:origin: org.lastaflute/lastaflute

@Override
public String toString() {
  final Integer total = facadeCountMap.values().stream().collect(Collectors.summingInt(vl -> vl));
  final StringBuilder sb = new StringBuilder();
  sb.append("{total=").append(total);
  facadeCountMap.forEach((facadeName, count) -> {
    sb.append(", ").append(facadeName).append("=").append(count);
  });
  sb.append("}");
  return sb.toString();
}

代码示例来源:origin: org.lastaflute/lastaflute

public String toLineDisp() { // basically format is same as requested mail count
  final Map<String, Integer> resolvedMap = facadeCountMap != null ? facadeCountMap : Collections.emptyMap();
  final Integer total = resolvedMap.values().stream().collect(Collectors.summingInt(vl -> vl));
  final StringBuilder sb = new StringBuilder();
  sb.append("{total=").append(total);
  resolvedMap.forEach((facadeName, count) -> {
    sb.append(", ").append(facadeName).append("=").append(count);
  });
  sb.append("}");
  return sb.toString();
}

代码示例来源:origin: lastaflute/lastaflute

@Override
public String toString() {
  final Integer total = facadeCountMap.values().stream().collect(Collectors.summingInt(vl -> vl));
  final StringBuilder sb = new StringBuilder();
  sb.append("{total=").append(total);
  facadeCountMap.forEach((facadeName, count) -> {
    sb.append(", ").append(facadeName).append("=").append(count);
  });
  sb.append("}");
  return sb.toString();
}

代码示例来源:origin: OpenNMS/opennms

@Override
public int size() {
  // Sum up the size of the children
  int retval = getChildren().stream().collect(Collectors.summingInt(RadixTreeNode::size));
  // And add 1 if our node has content
  return content == null ? retval : ++retval;
}

代码示例来源:origin: lastaflute/lastaflute

public String toLineDisp() { // basically format is same as requested mail count
  final Map<String, Integer> resolvedMap = facadeCountMap != null ? facadeCountMap : Collections.emptyMap();
  final Integer total = resolvedMap.values().stream().collect(Collectors.summingInt(vl -> vl));
  final StringBuilder sb = new StringBuilder();
  sb.append("{total=").append(total);
  resolvedMap.forEach((facadeName, count) -> {
    sb.append(", ").append(facadeName).append("=").append(count);
  });
  sb.append("}");
  return sb.toString();
}

代码示例来源:origin: org.jooq/jool

@Override
public int sumInt(ToIntFunction<? super T> function) {
  return collect(Collectors.summingInt(function));
}

代码示例来源:origin: org.eobjects.datacleaner/DataCleaner-fill-pattern

public int getTotalObservationCount() {
  return _patterns.stream().collect(Collectors.summingInt(p -> p.getObservationCount()));
}

代码示例来源:origin: org.jooq/jool-java-8

@Override
public int sumInt(ToIntFunction<? super T> function) {
  return collect(Collectors.summingInt(function));
}

代码示例来源:origin: datacleaner/DataCleaner

public int getTotalObservationCount() {
  return _patterns.stream().collect(Collectors.summingInt(p -> p.getObservationCount()));
}

代码示例来源:origin: seleniumkit/selenograph

private int toFreePercentage(Region region) {
  return region.getHosts().stream().collect(summingInt(this::toFreePercentage));
}

代码示例来源:origin: mcekovic/tennis-crystal-ball

public void addScoreCounts(Map<PerfMatchScore, Integer> scores) {
  Map<Integer, Integer> bestOfCounts = scores.entrySet().stream().collect(groupingBy(e -> e.getKey().getBestOf(), summingInt(Entry::getValue)));
  for (Map.Entry<PerfMatchScore, Integer> entry : scores.entrySet()) {
    int count = entry.getValue();
    if (count > 0)
      scoreCounts.put(entry.getKey(), new WonLost(count, bestOfCounts.get(entry.getKey().getBestOf()) - count));
  }
}

代码示例来源:origin: org.nuxeo.ecm.automation/nuxeo-automation-scripting

@Override
public int size() {
  return Stream.of(doc.getParts()).collect(Collectors.summingInt(part -> part.size()));
}

代码示例来源:origin: qcadoo/mes

private Map<Entity, Integer> getGroupedStaffWorkTimes(Entity event) {
  List<Entity> staffWorkTimes = event.getHasManyField(MaintenanceEventFields.STAFF_WORK_TIMES);
  Function<Entity, Entity> toWorker = entity -> entity.getBelongsToField(StaffWorkTimeFields.WORKER);
  ToIntFunction<Entity> toInt = entity -> entity.getIntegerField(StaffWorkTimeFields.LABOR_TIME);
  
  return staffWorkTimes.stream().collect(Collectors.groupingBy(toWorker, Collectors.summingInt(toInt)));
}

代码示例来源:origin: infinispan/infinispan-simple-tutorials

@Override
public Integer call() throws Exception {
  Cache<String, String> cache = getCache();
  return cache.keySet()
   .stream()
     .map(e -> Integer.valueOf(e.substring(0, e.indexOf("-"))))
     .collect(() -> Collectors.summingInt(Integer::intValue));
}

代码示例来源:origin: spring-projects/spring-data-r2dbc

@Override
  public Mono<Integer> rowsUpdated() {
    return Mono.from(objectToInsert).flatMapMany(toInsert -> exchange(toInsert, mappingFunction).rowsUpdated())
        .collect(Collectors.summingInt(Integer::intValue));
  }
};

代码示例来源:origin: org.springframework.data/spring-data-r2dbc

@Override
  public Mono<Integer> rowsUpdated() {
    return Mono.from(objectToInsert).flatMapMany(toInsert -> exchange(toInsert, mappingFunction).rowsUpdated())
        .collect(Collectors.summingInt(Integer::intValue));
  }
};

代码示例来源:origin: epam/NGB

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 {
    isBounded = exons.get(0).getStartIndex() <= bound;
  }
  Assert.assertTrue(totalLength >= viewPortSize || isBounded);
}

相关文章