package org.javamoney.moneta.function;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import javax.money.CurrencyUnit;

/**
 * This statisticsMap is decorator of HashMap that returns an empty Summary when there
 * isn't currency in get's method
 *
 * @author otaviojava
 */
class MonetarySummaryMap implements
        Map<CurrencyUnit, MonetarySummaryStatistics> {


    private final Map<CurrencyUnit, MonetarySummaryStatistics> map = new HashMap<>();

    @Override
    public int size() {
        return map.size();
    }

    @Override
    public boolean isEmpty() {
        return map.isEmpty();
    }

    @Override
    public boolean containsKey(Object key) {
        return map.containsKey(key);
    }

    @Override
    public boolean containsValue(Object value) {
        return map.containsValue(value);
    }

    @Override
    public MonetarySummaryStatistics get(Object key) {
        if (CurrencyUnit.class.isInstance(key)) {
            CurrencyUnit unit = CurrencyUnit.class.cast(key);
            MonetarySummaryStatistics stats = map.get(key);
            if(stats==null){
                stats = new DefaultMonetarySummaryStatistics(unit);
                map.put(unit, stats);
            }
            return stats;
        }
        return map.get(key);
    }

    @Override
    public MonetarySummaryStatistics put(CurrencyUnit key,
                                         MonetarySummaryStatistics value) {
        return map.put(key, value);
    }

    @Override
    public MonetarySummaryStatistics remove(Object key) {
        return map.remove(key);
    }

    @Override
    public void putAll(
            Map<? extends CurrencyUnit, ? extends MonetarySummaryStatistics> m) {
        map.putAll(m);
    }

    @Override
    public void clear() {
        map.clear();
    }

    @Override
    public Set<CurrencyUnit> keySet() {
        return map.keySet();
    }

    @Override
    public Collection<MonetarySummaryStatistics> values() {
        return map.values();
    }

    @Override
    public Set<java.util.Map.Entry<CurrencyUnit, MonetarySummaryStatistics>> entrySet() {
        return map.entrySet();
    }

    @Override
    public boolean equals(Object obj) {
        if (MonetarySummaryMap.class.isInstance(obj)) {
            MonetarySummaryMap other = MonetarySummaryMap.class.cast(obj);
            return map.equals(other.map);
        }
        return false;
    }

    @Override
    public int hashCode() {
        return map.hashCode();
    }

    @Override
    public String toString() {
        return "MonetarySummaryMap: " + map.toString();
    }
}

@@ -2452,32 +2452,337 @@
 n false;%0A    %7D%0A%0A
+    @Override%0A%09public MonetarySummaryStatistics putIfAbsent(CurrencyUnit key,%0A                                                 MonetarySummaryStatistics value) %7B%0A        MonetarySummaryStatistics v = map.get(key);%0A        if (v==null) %7B%0A            v = put(key, value);%0A        %7D%0A        return v;%0A    %7D%0A%0A
     @Override%0A  

Revert "Removes unnecessary method"