/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.collection.maps;

import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;
import net.ranides.assira.collection.sets.HashSet;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public interface MultiMap<K,V> extends Map<K,V> {
    
    Collection<V> getAll(Object key);
    
    default V get(Object key, BinaryOperator<V> fold) {
        return getAll(key).stream().reduce(null, fold);
    }
    
    default boolean containsEntry(Object key, Object value) {
        return getAll(key).contains(value);
    }

    default void putAll(K key, Iterable<? extends V> values) {
        for(V value : values) {
            put(key, value);
        }
    }

    default Collection<V> removeAll(Object key) {
        Collection<V> prev = new ArrayList<>();
        while(null != remove(key));
        return prev;
    }
    
    default Set<K> uniqueKeySet() {
        return new HashSet<>(keySet());
    }
    
}
