import "copyrightAndOthers.stg"

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

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

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

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

package org.eclipse.collections.impl.bag.mutable.primitive;

import org.eclipse.collections.api.<name>Iterable;
import org.eclipse.collections.api.factory.bag.primitive.Mutable<name>BagFactory;
import org.eclipse.collections.api.bag.primitive.Mutable<name>Bag;
import org.eclipse.collections.impl.factory.primitive.<name>Bags;
import org.eclipse.collections.impl.utility.Iterate;
<(wideStreamImport.(type))>

/**
 * Mutable<name>BagFactoryImpl is a factory implementation which creates instances of type {@link Mutable<name>Bag}.
 * This file was automatically generated from template file mutablePrimitiveBagFactoryImpl.stg.
 *
 * @since 6.0.
 */
public class Mutable<name>BagFactoryImpl implements Mutable<name>BagFactory
{
    public static final Mutable<name>BagFactory INSTANCE = new Mutable<name>BagFactoryImpl();

    @Override
    public Mutable<name>Bag empty()
    {
        return new <name>HashBag();
    }

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

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

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

    @Override
    public Mutable<name>Bag with(<type>... items)
    {
        if (items == null || items.length == 0)
        {
            return this.with();
        }
        return <name>HashBag.newBagWith(items);
    }

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

    @Override
    public Mutable<name>Bag withAll(<name>Iterable items)
    {
        return <name>HashBag.newBag(items);
    }

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

    /**
     * @since 10.0
     */
    @Override
    public Mutable<name>Bag withAll(Iterable\<<wrapperName>\> iterable)
    {
        return Iterate.collect<name>(iterable, <wrapperName>::<type>Value, <name>Bags.mutable.empty());
    }
    <(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 Mutable<name>Bag ofAll(<(wideStream.(type))> items)
{
    return this.withAll(items);
}

/**
 * @since 9.0
 */
@Override
public Mutable<name>Bag 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"
]
