import "copyrightAndOthers.stg"
import "primitiveAPI.stg"

targetPath() ::= "org/eclipse/collections/api/bag/primitive"

fileName(primitive) ::= "Mutable<primitive.name>Bag"

class(primitive) ::= <<
<body(primitive.type, primitive.name)>
>>

body(type, name) ::= <<
<copyrightAndOthers()>

package org.eclipse.collections.api.bag.primitive;

import org.eclipse.collections.api.<name>Iterable;
import org.eclipse.collections.api.bag.MutableBag;
import org.eclipse.collections.api.block.function.primitive.<name>ToObjectFunction;
<if(!primitive.intPrimitive)>import org.eclipse.collections.api.block.predicate.primitive.IntPredicate;<endif>
import org.eclipse.collections.api.block.predicate.primitive.<name>Predicate;
import org.eclipse.collections.api.block.procedure.primitive.<name>Procedure;
import org.eclipse.collections.api.collection.primitive.Mutable<name>Collection;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.tuple.primitive.<name>IntPair;
import org.eclipse.collections.api.set.primitive.Mutable<name>Set;

/**
 * This file was automatically generated from template file mutablePrimitiveBag.stg.
 *
 * @since 3.0.
 */
public interface Mutable<name>Bag extends Mutable<name>Collection, <name>Bag
{
    void addOccurrences(<type> item, int occurrences);

    boolean removeOccurrences(<type> item, int occurrences);

    /**
     * @since 9.0.
     */
    @Override
    default Mutable<name>Bag tap(<name>Procedure procedure)
    {
        this.forEach(procedure);
        return this;
    }

    /**
     * Returns all elements of the bag that have a number of occurrences that satisfy the predicate.
     *
     * @since 8.0
     */
    @Override
    Mutable<name>Bag selectByOccurrences(IntPredicate predicate);

    /**
     * Returns all elements of the bag that have more than one occurrence.
     *
     * @since 9.2
     */
    @Override
    default Mutable<name>Bag selectDuplicates()
    {
        return this.selectByOccurrences(occurrences -> occurrences > 1);
    }

    /**
     * Returns all elements of the bag that have exactly one occurrence.
     *
     * @since 9.2
     */
    @Override
    Mutable<name>Set selectUnique();

    /**
     * Returns the {@code count} most frequently occurring items.
     *
     * In the event of a tie, all of the items with the number of occurrences that match the occurrences of the last
     * item will be returned.
     *
     * @since 8.0
     */
    @Override
    MutableList\<<name>IntPair> topOccurrences(int count);

    /**
     * Returns the {@code count} least frequently occurring items.
     *
     * In the event of a tie, all of the items with the number of occurrences that match the occurrences of the last
     * item will be returned.
     *
     * @since 8.0
     */
    @Override
    MutableList\<<name>IntPair> bottomOccurrences(int count);

    <sharedAPI(fileName(primitive), name)>

    @Override
    \<V> MutableBag\<V> collect(<name>ToObjectFunction\<? extends V> function);

    <mutableAPI(fileName(primitive), type, name)>

    @Override
    Mutable<name>Bag asUnmodifiable();

    @Override
    Mutable<name>Bag asSynchronized();

    /**
     * Returns an immutable copy of this bag.
     */
    @Override
    Immutable<name>Bag toImmutable();

    /**
     * Creates a new empty mutable version of the same Bag type.
     *
     * @since 9.2.
     */
    default Mutable<name>Bag newEmpty()
    {
        throw new UnsupportedOperationException("Implement in concrete classes.");
    }
}

>>
