ch.lambdaj.Lambda.sumFrom()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(1.7k)|赞(0)|评价(0)|浏览(130)

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

Lambda.sumFrom介绍

[英]Returns a lambda function defined as:

sumFrom : (+, iterable) => lambda : (convert : object => number) => number

It is then possibly to curry this function by selecting the convert function that defines of each item must be converted in a number. This is done by invoking on that returned object the method that returns the values of the property to be summed as in the following example

int totalAge = sumFrom(persons).getAge();

The actual class of T is inferred from the class of the first iterable's item, but you can specify a particular class by using the overloaded method.
[中]

代码示例

代码示例来源:origin: mariofusco/lambdaj

/**
 * Returns a proxy of the class of the first object in this iterable that when invoked with a method returning a number
 * returns the sum of the numbers resulting from the invocation of the same method on each item in this iterable
 * @return A proxy of the class of the first object in this iterable representing a sum lambda function
 * @throws IllegalArgumentException if this iterable is null or empty
 */
public T sumFrom() {
  return Lambda.sumFrom(innerIterable);
}

代码示例来源:origin: jtalks-org/jcommune

/**
 * Counts the total count of votes in the poll.
 *
 * @return the total count of votes in the poll
 */
public int getTotalVotesCount() {
  return sumFrom(pollItems, PollItem.class).getVotesCount();
}

代码示例来源:origin: jtalks-org/jcommune

/**
 * Returns a sum of all topic's post count for that branch.
 * <p/>
 * Value is computed only for the first time (if not set explicitly before),
 * so it may not take into account the posts added later
 *
 * @return sum of post count for all the topics in this branch
 */
public int getPostCount() {
  if (postsCount == null) {
    postsCount = Lambda.sumFrom(topics, Topic.class).getPostCount();
  }
  return postsCount;
}

相关文章