コード例 #1
0
ファイル: MoneyUtils.java プロジェクト: dkarav/Bo2
 /**
  * Iterates a collection, and sums the Money elements contained in the specified property of each
  * object.
  *
  * <p>Nulls are excluded from the addition.
  *
  * @param <T> Type of elements in the collection.
  * @param collection Collection to iterate.
  * @param clazz Type of elements in the collection.
  * @param property Name of the property that contains the money element.
  * @param currency Currency of the money elements.
  * @return Returns the sum.
  */
 public static <T> Money sum(
     Collection<T> collection, Class<T> clazz, String property, Currency currency) {
   PropertyDescriptor pd = JavaBeanUtils.getPropertyDescriptor(clazz, property);
   MoneyCalculator calc = new MoneyCalculator(currency, false);
   for (T t : collection) {
     Money money = (Money) JavaBeanUtils.getProperty(pd, t);
     if (money != null) {
       calc.add(money);
     }
   }
   return calc.getResult();
 }