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

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

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

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

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

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

import org.eclipse.collections.api.block.function.primitive.<name>IntToObjectFunction;
import org.eclipse.collections.api.block.function.primitive.<name>ToObjectFunction;
import org.eclipse.collections.api.block.predicate.primitive.<name>IntPredicate;
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.list.primitive.<name>List;
import org.eclipse.collections.api.stack.MutableStack;

/**
 * This file was automatically generated from template file mutablePrimitiveStack.stg.
 *
 * @since 3.0.
 */
public interface Mutable<name>Stack extends <name>Stack
{
    /**
     * Adds an item to the top of the stack.
     */
    void push(<type> item);

    /**
     * Removes and returns the top element of the stack.
     */
    <type> pop();

    /**
     * Removes and returns a <name>List of the number of elements specified by the count, beginning with the top of the stack.
     */
    <name>List pop(int count);

    /**
     * Clears the Stack
     */
    void clear();

    <sharedAPI(fileName(primitive), name)>

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

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

    /**
     * Returns a new Mutable<name>Stack including all elements with corresponding indexes matching the specified predicate.
     *
     * @since 11.1.
     */
    @Override
    default Mutable<name>Stack selectWithIndex(<name>IntPredicate predicate)
    {
        int[] index = {0};
        return this.select(each -> predicate.accept(each, index[0]++));
    }

    /**
     * Returns a new Mutable<name>Stack excluding all elements with corresponding indexes matching the specified predicate.
     *
     * @since 11.1.
     */
    @Override
    default Mutable<name>Stack rejectWithIndex(<name>IntPredicate predicate)
    {
        int[] index = {0};
        return this.reject(each -> predicate.accept(each, index[0]++));
    }

    /**
     * Returns a new MutableStack using results obtained by applying the specified function to each element
     * and its corresponding index.
     *
     * @since 9.1.
     */
    @Override
    default \<V> MutableStack\<V> collectWithIndex(<name>IntToObjectFunction\<? extends V> function)
    {
        int[] index = {0};
        return this.collect(each -> function.value(each, index[0]++));
    }

    Mutable<name>Stack asUnmodifiable();

    Mutable<name>Stack asSynchronized();

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

>>
