import "copyrightAndOthers.stg"

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

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

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

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

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

import org.eclipse.collections.api.<name>Iterable;
import org.eclipse.collections.api.factory.list.primitive.Mutable<name>ListFactory;
import org.eclipse.collections.api.list.primitive.Mutable<name>List;
import org.eclipse.collections.impl.factory.primitive.<name>Lists;
import org.eclipse.collections.impl.utility.Iterate;
<(wideStreamImport.(type))>

/**
 * Mutable<name>ListFactoryImpl is a factory implementation which creates instances of type {@link Mutable<name>List}.
 * This file was automatically generated from template file mutablePrimitiveListFactoryImpl.stg.
 *
 * @since 6.0.
 */
public enum Mutable<name>ListFactoryImpl implements Mutable<name>ListFactory
{
    INSTANCE;

    @Override
    public Mutable<name>List empty()
    {
        return new <name>ArrayList();
    }

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

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

    @Override
    public Mutable<name>List withInitialCapacity(int capacity)
    {
        return new <name>ArrayList(capacity);
    }

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

    /**
     * Creates a new list using the passed {@code items} argument as the backing store.
     * \<p>
     * !!! WARNING: This method uses the passed in array, so can be very unsafe if the original
     * array is held onto anywhere else. !!!
     */
    @Override
    public Mutable<name>List with(<type>... items)
    {
        if (items == null || items.length == 0)
        {
            return this.with();
        }
        return <name>ArrayList.newListWith(items);
    }

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

    @Override
    public Mutable<name>List withAll(<name>Iterable items)
    {
        return <name>ArrayList.newList(items);
    }

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

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

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