import "copyrightAndOthers.stg"

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

fileName(primitive) ::= "Immutable<primitive.name>StackFactoryImpl"

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

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

package org.eclipse.collections.impl.stack.immutable.primitive;

import org.eclipse.collections.api.<name>Iterable;
import org.eclipse.collections.api.factory.stack.primitive.Immutable<name>StackFactory;
import org.eclipse.collections.api.stack.primitive.Immutable<name>Stack;
import org.eclipse.collections.impl.factory.primitive.<name>Stacks;
<(wideStreamImport.(type))>

/**
 * Immutable<name>StackFactoryImpl is a factory implementation which creates instances of type {@link Immutable<name>Stack}.
 * This file was automatically generated from template file immutablePrimitiveStackFactoryImpl.stg.
 *
 * @since 4.0.
 */
public class Immutable<name>StackFactoryImpl implements Immutable<name>StackFactory
{
    public static final Immutable<name>StackFactory INSTANCE = new Immutable<name>StackFactoryImpl();

    @Override
    public Immutable<name>Stack empty()
    {
        return Immutable<name>EmptyStack.INSTANCE;
    }

    @Override
    public Immutable<name>Stack of()
    {
        return this.empty();
    }

    @Override
    public Immutable<name>Stack with()
    {
        return this.empty();
    }

    @Override
    public Immutable<name>Stack of(<type> one)
    {
        return this.with(one);
    }

    @Override
    public Immutable<name>Stack with(<type> one)
    {
        return new Immutable<name>SingletonStack(one);
    }

    @Override
    public Immutable<name>Stack of(<type>... items)
    {
        return this.with(items);
    }

    @Override
    public Immutable<name>Stack with(<type>... items)
    {
        if (items == null || items.length == 0)
        {
            return this.with();
        }
        if (items.length == 1)
        {
            return this.with(items[0]);
        }
        return Immutable<name>ArrayStack.newStackWith(items);
    }

    @Override
    public Immutable<name>Stack ofAll(<name>Iterable items)
    {
        return this.withAll(items);
    }

    @Override
    public Immutable<name>Stack withAll(<name>Iterable items)
    {
        if (items instanceof Immutable<name>Stack)
        {
            return (Immutable<name>Stack) items;
        }
        return this.with(items.toArray());
    }

    /**
     * @since 10.0
     */
    @Override
    public Immutable<name>Stack ofAll(Iterable\<<wrapperName>\> iterable)
    {
        return this.withAll(iterable);
    }

    /**
     * @since 10.0
     */
    @Override
    public Immutable<name>Stack withAll(Iterable\<<wrapperName>\> iterable)
    {
        return <name>Stacks.mutable.withAll(iterable).toImmutable();
    }

    @Override
    public Immutable<name>Stack ofAllReversed(<name>Iterable items)
    {
        return this.withAllReversed(items);
    }

    @Override
    public Immutable<name>Stack withAllReversed(<name>Iterable items)
    {
        if (items == null || items.isEmpty())
        {
            return this.with();
        }
        if (items.size() == 1)
        {
            return this.with(items.toArray());
        }
        return Immutable<name>ArrayStack.newStackFromTopToBottom(items);
    }
    <(streamMethods.(type))()>
}

>>

streamMethods ::= [
    "byte": "noMethods",
    "short": "noMethods",
    "char": "noMethods",
    "int": "allMethods",
    "long": "allMethods",
    "float": "noMethods",
    "double": "allMethods",
    "boolean": "noMethods"
    ]

allMethods() ::= <<

/**
 * @since 9.0
 */
@Override
public Immutable<name>Stack ofAll(<(wideStream.(type))> items)
{
    return this.withAll(items);
}

/**
 * @since 9.0
 */
@Override
public Immutable<name>Stack withAll(<(wideStream.(type))> items)
{
    return this.with(items.toArray());
}
>>

noMethods() ::= ""

wideStream ::= [
    "int": "IntStream",
    "long": "LongStream",
    "double": "DoubleStream",
    default: "no matching wide type"
]

wideStreamImport ::= [
    "boolean": "",
    "byte": "",
    "short": "",
    "char": "",
    "int": "import java.util.stream.IntStream;",
    "long": "import java.util.stream.LongStream;",
    "float": "",
    "double": "import java.util.stream.DoubleStream;",
    default: "no matching wide type"
]
