import "copyright.stg"
import "primitiveEquals.stg"
import "primitiveHashCode.stg"
import "primitiveLiteral.stg"

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

fileName(primitive) ::= "AbstractImmutableObject<primitive.name>Map"

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

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

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

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

import org.eclipse.collections.api.map.primitive.ImmutableObject<name>Map;
import org.eclipse.collections.api.map.primitive.Object<name>Map;
import org.eclipse.collections.api.map.primitive.MutableObject<name>Map;
import org.eclipse.collections.impl.block.procedure.checked.primitive.CheckedObject<name>Procedure;
import org.eclipse.collections.impl.map.mutable.primitive.Object<name>HashMap;

/**
 * This file was automatically generated from template file abstractImmutableObjectPrimitiveMap.stg.
 *
 * @since 4.0.
 */
public abstract class AbstractImmutableObject<name>Map\<V> implements ImmutableObject<name>Map\<V>
{
    protected static class ImmutableObject<name>MapSerializationProxy\<V> implements Externalizable
    {
        private static final long serialVersionUID = 1L;

        private Object<name>Map\<V> map;

        public ImmutableObject<name>MapSerializationProxy()
        {
            // Empty constructor for Externalizable class
        }

        protected ImmutableObject<name>MapSerializationProxy(Object<name>Map\<V> map)
        {
            this.map = map;
        }

        @Override
        public void writeExternal(final ObjectOutput out) throws IOException
        {
            out.writeInt(this.map.size());
            try
            {
                this.map.forEachKeyValue(new CheckedObject<name>Procedure\<V>()
                {
                    @Override
                    public void safeValue(V key, <type> value) throws IOException
                    {
                        out.writeObject(key);
                        out.write<name>(value);
                    }
                });
            }
            catch (RuntimeException e)
            {
                if (e.getCause() instanceof IOException)
                {
                    throw (IOException) e.getCause();
                }
                throw e;
            }
        }

        @Override
        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
        {
            int size = in.readInt();
            MutableObject<name>Map\<V> deserializedMap = new Object<name>HashMap\<>();

            for (int i = 0; i \< size; i++)
            {
                deserializedMap.put((V) in.readObject(), in.read<name>());
            }

            this.map = deserializedMap;
        }

        protected Object readResolve()
        {
            return this.map.toImmutable();
        }
    }
}

>>
