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

import java.util.NoSuchElementException;
import java.util.function.IntBinaryOperator;
import net.ranides.assira.collection.IntCollection;
import net.ranides.assira.collection.lists.IntArrayList;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public interface IntMultiSet extends IntSet {
    
    IntCollection getAll(int key);
    
    default int get(int key, IntBinaryOperator fold) {
        return getAll(key).intstream().reduce(fold).orElseThrow(()->new NoSuchElementException());
    }

    default IntCollection removeAll(int key) {
        IntCollection out = new IntArrayList(getAll(key));
        for(int k : out) {
            remove(k);
        }
        return out;
    }
    
    default IntSet uniqueSet() {
        return new IntHashSet(this);
    }

}
