Java BigDecimal Add sumCurrencyMap(Map> destMap, Map> mapToSum)

Here you can find the source of sumCurrencyMap(Map> destMap, Map> mapToSum)

Description

sum Currency Map

License

Open Source License

Declaration

public static Map sumCurrencyMap(Map<String, Map<String, BigDecimal>> destMap,
            Map<String, Map<String, BigDecimal>> mapToSum) 

Method Source Code

//package com.java2s;
/**/*  www. j  av a2s .  c o m*/
* License: https://github.com/votingsystem/votingsystem/wiki/Licencia
 */

import java.math.BigDecimal;
import java.util.HashMap;

import java.util.Map;

public class Main {
    public static Map sumCurrencyMap(Map<String, Map<String, BigDecimal>> destMap,
            Map<String, Map<String, BigDecimal>> mapToSum) {
        Map<String, BigDecimal> tagMap = null;
        for (String currency : mapToSum.keySet()) {
            if ((tagMap = destMap.get(currency)) != null) {
                for (String tag : mapToSum.get(currency).keySet()) {
                    if (tagMap.containsKey(tag)) {
                        BigDecimal newAmount = tagMap.get(tag).add(mapToSum.get(currency).get(tag));
                        tagMap.put(tag, newAmount);
                    } else {
                        tagMap.put(tag, mapToSum.get(currency).get(tag));
                    }
                }
            } else {
                destMap.put(currency, new HashMap<>(mapToSum.get(currency)));
            }
        }
        return destMap;
    }
}

Related

  1. sum(BigDecimal[] bigDecimalNumbers)
  2. sum(final List list)
  3. sum(List numbers)
  4. sumBig(final Collection values)
  5. sumBigDecimal(List vector)