import "copyright.stg"

skipBoolean() ::= "true"

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

fileName(primitive) ::= "AbstractImmutable<primitive.name>Set"

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

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

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

import org.eclipse.collections.api.<name>Iterable;
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.primitive.<name>Sets;
import org.eclipse.collections.api.iterator.<name>Iterator;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.set.primitive.Immutable<name>Set;
import org.eclipse.collections.api.set.primitive.<name>Set;
import org.eclipse.collections.api.set.primitive.Mutable<name>Set;
import org.eclipse.collections.impl.set.mutable.primitive.<name>HashSet;
import org.eclipse.collections.impl.set.primitive.Abstract<name>Set;

/**
 * This file was automatically generated from template file abstractImmutablePrimitiveSet.stg.
 *
 * @since 6.0.
 */
public abstract class AbstractImmutable<name>Set extends Abstract<name>Set implements Immutable<name>Set
{
    @Override
    public Immutable<name>Set newWith(<type> element)
    {
        return <name>HashSet.newSet(this).with(element).toImmutable();
    }

    @Override
    public Immutable<name>Set newWithout(<type> element)
    {
        return <name>HashSet.newSet(this).without(element).toImmutable();
    }

    @Override
    public Immutable<name>Set newWithAll(<name>Iterable elements)
    {
        return <name>HashSet.newSet(this).withAll(elements).toImmutable();
    }

    @Override
    public Immutable<name>Set newWithoutAll(<name>Iterable elements)
    {
        return <name>HashSet.newSet(this).withoutAll(elements).toImmutable();
    }

    @Override
    public <name>Set freeze()
    {
        return this;
    }

    @Override
    public Immutable<name>Set toImmutable()
    {
        return this;
    }

    @Override
    public RichIterable\<<name>Iterable> chunk(int size)
    {
        if (size \<= 0)
        {
            throw new IllegalArgumentException("Size for groups must be positive but was: " + size);
        }
        MutableList\<<name>Iterable> result = Lists.mutable.empty();
        if (this.notEmpty())
        {
            if (this.size() \<= size)
            {
                result.add(this);
            }
            else
            {
                <name>Iterator iterator = this.<type>Iterator();
                while (iterator.hasNext())
                {
                    Mutable<name>Set batch = <name>Sets.mutable.empty();
                    for (int i = 0; i \< size && iterator.hasNext(); i++)
                    {
                        batch.add(iterator.next());
                    }
                    result.add(batch.toImmutable());
                }
            }
        }
        return result.toImmutable();
    }
}

>>
