import "copyrightAndOthers.stg"
import "primitiveEquals.stg"
import "primitiveHashCode.stg"
import "primitiveLiteral.stg"

skipBoolean() ::= "true"

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

fileName(primitive) ::= "Object<primitive.name>HashMapWithHashingStrategy"

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

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

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

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Set;

import org.eclipse.collections.api.<name>Iterable;
import org.eclipse.collections.api.Lazy<name>Iterable;
import org.eclipse.collections.api.LazyIterable;
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.bag.primitive.Mutable<name>Bag;
import org.eclipse.collections.api.block.HashingStrategy;
import org.eclipse.collections.api.block.function.primitive.<name>Function;
import org.eclipse.collections.api.block.function.primitive.<name>Function0;
import org.eclipse.collections.api.block.function.primitive.<name>To<name>Function;
import org.eclipse.collections.api.block.function.primitive.<name>ToObjectFunction;
import org.eclipse.collections.api.block.function.primitive.Object<name>To<name>Function;
import org.eclipse.collections.api.block.function.primitive.Object<name>ToObjectFunction;
import org.eclipse.collections.api.block.predicate.primitive.<name>Predicate;
import org.eclipse.collections.api.block.predicate.primitive.Object<name>Predicate;
import org.eclipse.collections.api.block.procedure.Procedure;
import org.eclipse.collections.api.block.procedure.Procedure2;
import org.eclipse.collections.api.block.procedure.primitive.<name>Procedure;
import org.eclipse.collections.api.block.procedure.primitive.Object<name>Procedure;
import org.eclipse.collections.api.collection.MutableCollection;
import org.eclipse.collections.api.collection.primitive.Immutable<name>Collection;
import org.eclipse.collections.api.collection.primitive.Mutable<name>Collection;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.primitive.<name>Bags;
import org.eclipse.collections.api.factory.primitive.<name>Lists;
import org.eclipse.collections.api.factory.primitive.<name>Sets;
import org.eclipse.collections.api.factory.primitive.Object<name>Maps;
<if(!primitive.booleanPrimitive)>import org.eclipse.collections.api.factory.primitive.<name>ObjectMaps;<endif>
import org.eclipse.collections.impl.lazy.primitive.Lazy<name>IterableAdapter;
import org.eclipse.collections.api.iterator.<name>Iterator;
import org.eclipse.collections.api.iterator.Mutable<name>Iterator;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.list.primitive.Mutable<name>List;
import org.eclipse.collections.api.map.primitive.ImmutableObject<name>Map;
import org.eclipse.collections.api.map.primitive.MutableObject<name>Map;
<if(!primitive.booleanPrimitive)>import org.eclipse.collections.api.map.primitive.Mutable<name>ObjectMap;<endif>
import org.eclipse.collections.api.map.primitive.Object<name>Map;
import org.eclipse.collections.api.set.primitive.<name>Set;
import org.eclipse.collections.api.set.primitive.Mutable<name>Set;
import org.eclipse.collections.api.tuple.primitive.Object<name>Pair;
import org.eclipse.collections.impl.collection.mutable.primitive.Synchronized<name>Collection;
import org.eclipse.collections.impl.collection.mutable.primitive.Unmodifiable<name>Collection;
import org.eclipse.collections.impl.lazy.AbstractLazyIterable;
<(procedureImport.(type))()>
import org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples;

/**
 * This file was automatically generated from template file objectPrimitiveHashMapWithHashingStrategy.stg.
 *
 * @since 7.0.
 */
public class Object<name>HashMapWithHashingStrategy\<K> implements MutableObject<name>Map\<K>, Externalizable
{
    public static final <type> EMPTY_VALUE = <zero.(type)>;

    private static final long serialVersionUID = 1L;
    private static final int DEFAULT_INITIAL_CAPACITY = 8;

    private static final Object NULL_KEY = new Object()
    {
        @Override
        public boolean equals(Object obj)
        {
            throw new RuntimeException("Possible corruption through unsynchronized concurrent modification.");
        }

        @Override
        public int hashCode()
        {
            throw new RuntimeException("Possible corruption through unsynchronized concurrent modification.");
        }

        @Override
        public String toString()
        {
            return "Object<name>HashMapWithHashingStrategy.NULL_KEY";
        }
    };

    private static final Object REMOVED_KEY = new Object()
    {
        @Override
        public boolean equals(Object obj)
        {
            throw new RuntimeException("Possible corruption through unsynchronized concurrent modification.");
        }

        @Override
        public int hashCode()
        {
            throw new RuntimeException("Possible corruption through unsynchronized concurrent modification.");
        }

        @Override
        public String toString()
        {
            return "Object<name>HashMapWithHashingStrategy.REMOVED_KEY";
        }
    };

    private Object[] keys;
    private <type>[] values;

    private int occupiedWithData;
    private int occupiedWithSentinels;

    private HashingStrategy\<? super K> hashingStrategy;

    /**
     * @deprecated Use Object<name>HashMapWithHashingStrategy(HashingStrategy) instead.
     */
    @Deprecated
    public Object<name>HashMapWithHashingStrategy()
    {
    }

    public Object<name>HashMapWithHashingStrategy(HashingStrategy\<? super K> hashingStrategy)
    {
        this.hashingStrategy = hashingStrategy;
        this.allocateTable(DEFAULT_INITIAL_CAPACITY \<\< 1);
    }

    public Object<name>HashMapWithHashingStrategy(HashingStrategy\<? super K> hashingStrategy, int initialCapacity)
    {
        if (initialCapacity \< 0)
        {
            throw new IllegalArgumentException("initial capacity cannot be less than 0");
        }
        this.hashingStrategy = hashingStrategy;
        int capacity = this.smallestPowerOfTwoGreaterThan(this.fastCeil(initialCapacity \<\< 1));
        this.allocateTable(capacity);
    }

    public Object<name>HashMapWithHashingStrategy(HashingStrategy\<? super K> hashingStrategy, Object<name>Map\<? extends K> map)
    {
        this(hashingStrategy, Math.max(map.size(), DEFAULT_INITIAL_CAPACITY));
        this.putAll(map);
    }

    public static \<K> Object<name>HashMapWithHashingStrategy\<K> newMap(HashingStrategy\<? super K> hashingStrategy)
    {
        return new Object<name>HashMapWithHashingStrategy\<>(hashingStrategy);
    }

    public static \<K> Object<name>HashMapWithHashingStrategy\<K> newMap(HashingStrategy\<? super K> hashingStrategy, Object<name>Map\<K> map)
    {
        return new Object<name>HashMapWithHashingStrategy\<>(hashingStrategy, map);
    }

    public static \<K> Object<name>HashMapWithHashingStrategy\<K> newMap(Object<name>HashMapWithHashingStrategy\<K> map)
    {
        return new Object<name>HashMapWithHashingStrategy\<>(map.hashingStrategy, map);
    }

    public static \<K> Object<name>HashMapWithHashingStrategy\<K> newMapWithInitialCapacity(HashingStrategy\<? super K> hashingStrategy, int initialCapacity)
    {
        return new Object<name>HashMapWithHashingStrategy\<>(hashingStrategy, initialCapacity);
    }

    public static \<K> Object<name>HashMapWithHashingStrategy\<K> newWithKeysValues(HashingStrategy\<? super K> hashingStrategy, K key1, <type> value1)
    {
        return new Object<name>HashMapWithHashingStrategy\<K>(hashingStrategy, 1).withKeyValue(key1, value1);
    }

    public static \<K> Object<name>HashMapWithHashingStrategy\<K> newWithKeysValues(HashingStrategy\<? super K> hashingStrategy, K key1, <type> value1, K key2, <type> value2)
    {
        return new Object<name>HashMapWithHashingStrategy\<K>(hashingStrategy, 2).withKeysValues(key1, value1, key2, value2);
    }

    public static \<K> Object<name>HashMapWithHashingStrategy\<K> newWithKeysValues(HashingStrategy\<? super K> hashingStrategy, K key1, <type> value1, K key2, <type> value2, K key3, <type> value3)
    {
        return new Object<name>HashMapWithHashingStrategy\<K>(hashingStrategy, 3).withKeysValues(key1, value1, key2, value2, key3, value3);
    }

    public static \<K> Object<name>HashMapWithHashingStrategy\<K> newWithKeysValues(HashingStrategy\<? super K> hashingStrategy, K key1, <type> value1, K key2, <type> value2, K key3, <type> value3, K key4, <type> value4)
    {
        return new Object<name>HashMapWithHashingStrategy\<K>(hashingStrategy, 4).withKeysValues(key1, value1, key2, value2, key3, value3, key4, value4);
    }

    private int smallestPowerOfTwoGreaterThan(int n)
    {
        return n > 1 ? Integer.highestOneBit(n - 1) \<\< 1 : 1;
    }

    private int fastCeil(float v)
    {
        int possibleResult = (int) v;
        if (v - possibleResult > 0.0F)
        {
            possibleResult++;
        }
        return possibleResult;
    }

    @Override
    public boolean equals(Object obj)
    {
        if (this == obj)
        {
            return true;
        }

        if (!(obj instanceof Object<name>Map))
        {
            return false;
        }

        Object<name>Map\<K> other = (Object<name>Map\<K>) obj;

        if (this.size() != other.size())
        {
            return false;
        }

        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]) && (!other.containsKey(this.toNonSentinel(this.keys[i])) || <(notEquals.(type))("this.values[i]", "other.getOrThrow(this.toNonSentinel(this.keys[i]))")>))
            {
                return false;
            }
        }
        return true;
    }

    @Override
    public int hashCode()
    {
        int result = 0;

        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]))
            {
                result += this.hashingStrategy.computeHashCode(this.toNonSentinel(this.keys[i])) ^ <(hashCode.(type))("this.values[i]")>;
            }
        }
        return result;
    }

    @Override
    public String toString()
    {
        StringBuilder appendable = new StringBuilder();

        appendable.append("{");

        boolean first = true;

        for (int i = 0; i \< this.keys.length; i++)
        {
            Object key = this.keys[i];
            if (isNonSentinel(key))
            {
                if (!first)
                {
                    appendable.append(", ");
                }
                appendable.append(this.toNonSentinel(key)).append("=").append(this.values[i]);
                first = false;
            }
        }
        appendable.append("}");

        return appendable.toString();
    }

    @Override
    public int size()
    {
        return this.occupiedWithData;
    }

    @Override
    public boolean isEmpty()
    {
        return this.size() == 0;
    }

    @Override
    public boolean notEmpty()
    {
        return this.size() != 0;
    }

    @Override
    public String makeString()
    {
        return this.makeString(", ");
    }

    @Override
    public String makeString(String separator)
    {
        return this.makeString("", separator, "");
    }

    @Override
    public String makeString(String start, String separator, String end)
    {
        Appendable stringBuilder = new StringBuilder();
        this.appendString(stringBuilder, start, separator, end);
        return stringBuilder.toString();
    }

    @Override
    public void appendString(Appendable appendable)
    {
        this.appendString(appendable, ", ");
    }

    @Override
    public void appendString(Appendable appendable, String separator)
    {
        this.appendString(appendable, "", separator, "");
    }

    @Override
    public void appendString(Appendable appendable, String start, String separator, String end)
    {
        try
        {
            appendable.append(start);

            boolean first = true;

            for (int i = 0; i \< this.keys.length; i++)
            {
                Object key = this.keys[i];
                if (isNonSentinel(key))
                {
                    if (!first)
                    {
                        appendable.append(separator);
                    }
                    appendable.append(String.valueOf(String.valueOf(this.values[i])));
                    first = false;
                }
            }
            appendable.append(end);
        }
        catch (IOException e)
        {
            throw new RuntimeException(e);
        }
    }

    @Override
    public Mutable<name>Iterator <type>Iterator()
    {
        return new Internal<name>Iterator();
    }

    @Override
    public <type>[] toArray()
    {
        <type>[] result = new <type>[this.size()];
        int index = 0;

        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]))
            {
                result[index] = this.values[i];
                index++;
            }
        }
        return result;
    }

    @Override
    public <type>[] toArray(<type>[] target)
    {
        if (target.length \< this.size())
        {
            target = new <type>[this.size()];
        }
        int index = 0;

        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]))
            {
                target[index] = this.values[i];
                index++;
            }
        }
        return target;
    }

    @Override
    public boolean contains(<type> value)
    {
        return this.containsValue(value);
    }

    @Override
    public boolean containsAll(<type>... source)
    {
        for (<type> item : source)
        {
            if (!this.containsValue(item))
            {
                return false;
            }
        }
        return true;
    }

    @Override
    public boolean containsAll(<name>Iterable source)
    {
        return this.containsAll(source.toArray());
    }

    @Override
    public void clear()
    {
        this.occupiedWithData = 0;
        this.occupiedWithSentinels = 0;
        Arrays.fill(this.keys, null);
        Arrays.fill(this.values, EMPTY_VALUE);
    }

    @Override
    public void put(K key, <type> value)
    {
        int index = this.probe(key);

        if (isNonSentinel(this.keys[index]) && this.nullSafeEquals(this.toNonSentinel(this.keys[index]), key))
        {
            // key already present in map
            this.values[index] = value;
            return;
        }

        this.addKeyValueAtIndex(key, value, index);
    }

    @Override
    public void putAll(Object<name>Map\<? extends K> map)
    {
        map.forEachKeyValue(this::put);
    }

    @Override
    public void updateValues(Object<name>To<name>Function\<? super K> function)
    {
        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]))
            {
                this.values[i] = function.valueOf(this.toNonSentinel(this.keys[i]), this.values[i]);
            }
        }
    }

    @Override
    public void removeKey(K key)
    {
        int index = this.probe(key);
        this.removeKeyAtIndex(key, index);
    }

    public void removeKeyAtIndex(K key, int index)
    {
        if (isNonSentinel(this.keys[index]) && this.nullSafeEquals(this.toNonSentinel(this.keys[index]), key))
        {
            this.keys[index] = REMOVED_KEY;
            this.values[index] = EMPTY_VALUE;
            this.occupiedWithData--;
            this.occupiedWithSentinels++;
        }
    }

    @Override
    public void remove(Object key)
    {
        this.removeKey((K) key);
    }

    @Override
    public <type> removeKeyIfAbsent(K key, <type> value)
    {
        int index = this.probe(key);
        if (isNonSentinel(this.keys[index]) && this.nullSafeEquals(this.toNonSentinel(this.keys[index]), key))
        {
            this.keys[index] = REMOVED_KEY;
            <type> oldValue = this.values[index];
            this.values[index] = EMPTY_VALUE;
            this.occupiedWithData--;
            this.occupiedWithSentinels++;

            return oldValue;
        }
        return value;
    }

    @Override
    public <type> getIfAbsentPut(K key, <type> value)
    {
        int index = this.probe(key);
        if (isNonSentinel(this.keys[index]) && this.nullSafeEquals(this.toNonSentinel(this.keys[index]), key))
        {
            return this.values[index];
        }
        this.addKeyValueAtIndex(key, value, index);
        return value;
    }

    @Override
    public <type> getAndPut(K key, <type> putValue, <type> defaultValue)
    {
        int index = this.probe(key);
        if (isNonSentinel(this.keys[index]) && nullSafeEquals(this.toNonSentinel(this.keys[index]), key))
        {
            <type> existingValue = this.values[index];
            this.values[index] = putValue;
            return existingValue;
        }
        this.addKeyValueAtIndex(key, putValue, index);
        return defaultValue;
    }

    @Override
    public <type> getIfAbsentPut(K key, <name>Function0 function)
    {
        int index = this.probe(key);
        if (isNonSentinel(this.keys[index]) && this.nullSafeEquals(this.toNonSentinel(this.keys[index]), key))
        {
            return this.values[index];
        }
        <type> value = function.value();
        this.addKeyValueAtIndex(key, value, index);
        return value;
    }

    @Override
    public \<P> <type> getIfAbsentPutWith(K key, <name>Function\<? super P> function, P parameter)
    {
        int index = this.probe(key);
        if (isNonSentinel(this.keys[index]) && this.nullSafeEquals(this.toNonSentinel(this.keys[index]), key))
        {
            return this.values[index];
        }
        <type> value = function.<type>ValueOf(parameter);
        this.addKeyValueAtIndex(key, value, index);
        return value;
    }

    @Override
    public <type> getIfAbsentPutWithKey(K key, <name>Function\<? super K> function)
    {
        int index = this.probe(key);
        if (isNonSentinel(this.keys[index]) && this.nullSafeEquals(this.toNonSentinel(this.keys[index]), key))
        {
            return this.values[index];
        }
        <type> value = function.<type>ValueOf(key);
        this.addKeyValueAtIndex(key, value, index);
        return value;
    }

    @Override
    public <type> updateValue(K key, <type> initialValueIfAbsent, <name>To<name>Function function)
    {
        int index = this.probe(key);
        if (isNonSentinel(this.keys[index]) && this.nullSafeEquals(this.toNonSentinel(this.keys[index]), key))
        {
            this.values[index] = function.valueOf(this.values[index]);
            return this.values[index];
        }
        <type> value = function.valueOf(initialValueIfAbsent);
        this.addKeyValueAtIndex(key, value, index);
        return value;
    }

    private void addKeyValueAtIndex(K key, <type> value, int index)
    {
        if (this.keys[index] == REMOVED_KEY)
        {
            --this.occupiedWithSentinels;
        }
        this.keys[index] = toSentinelIfNull(key);
        this.values[index] = value;
        ++this.occupiedWithData;
        if (this.occupiedWithData + this.occupiedWithSentinels > this.maxOccupiedWithData())
        {
            this.rehashAndGrow();
        }
    }

    @Override
    public <type> addToValue(K key, <type> toBeAdded)
    {
        int index = this.probe(key);
        if (isNonSentinel(this.keys[index]) && this.nullSafeEquals(this.toNonSentinel(this.keys[index]), key))
        {
            this.values[index] += toBeAdded;
            return this.values[index];
        }
        this.addKeyValueAtIndex(key, toBeAdded, index);
        return toBeAdded;
    }

    @Override
    public Object<name>HashMapWithHashingStrategy\<K> withKeyValue(K key1, <type> value1)
    {
        this.put(key1, value1);
        return this;
    }

    public Object<name>HashMapWithHashingStrategy\<K> withKeysValues(K key1, <type> value1, K key2, <type> value2)
    {
        this.put(key1, value1);
        this.put(key2, value2);
        return this;
    }

    public Object<name>HashMapWithHashingStrategy\<K> withKeysValues(K key1, <type> value1, K key2, <type> value2, K key3, <type> value3)
    {
        this.put(key1, value1);
        this.put(key2, value2);
        this.put(key3, value3);
        return this;
    }

    public Object<name>HashMapWithHashingStrategy\<K> withKeysValues(K key1, <type> value1, K key2, <type> value2, K key3, <type> value3, K key4, <type> value4)
    {
        this.put(key1, value1);
        this.put(key2, value2);
        this.put(key3, value3);
        this.put(key4, value4);
        return this;
    }

    @Override
    public Object<name>HashMapWithHashingStrategy\<K> withoutKey(K key)
    {
        this.removeKey(key);
        return this;
    }

    @Override
    public Object<name>HashMapWithHashingStrategy\<K> withoutAllKeys(Iterable\<? extends K> keys)
    {
        for (K key : keys)
        {
            this.removeKey(key);
        }
        return this;
    }

    @Override
    public MutableObject<name>Map\<K> asUnmodifiable()
    {
        return new UnmodifiableObject<name>Map\<>(this);
    }

    @Override
    public MutableObject<name>Map\<K> asSynchronized()
    {
        return new SynchronizedObject<name>Map\<>(this);
    }

    @Override
    public ImmutableObject<name>Map\<K> toImmutable()
    {
        return Object<name>Maps.immutable.withAll(this);
    }

    @Override
    public <type> get(Object key)
    {
        return this.getIfAbsent(key, EMPTY_VALUE);
    }

    @Override
    public <type> getOrThrow(Object key)
    {
        int index = this.probe(key);
        if (isNonSentinel(this.keys[index]))
        {
            return this.values[index];
        }
        throw new IllegalStateException("Key " + key + " not present.");
    }

    @Override
    public <type> getIfAbsent(Object key, <type> ifAbsent)
    {
        int index = this.probe(key);
        if (isNonSentinel(this.keys[index]) && this.nullSafeEquals(this.toNonSentinel(this.keys[index]), key))
        {
            return this.values[index];
        }
        return ifAbsent;
    }

    @Override
    public boolean containsKey(Object key)
    {
        int index = this.probe(key);
        return isNonSentinel(this.keys[index]) && this.nullSafeEquals(this.toNonSentinel(this.keys[index]), key);
    }

    @Override
    public boolean containsValue(<type> value)
    {
        for (int i = 0; i \< this.values.length; i++)
        {
            if (isNonSentinel(this.keys[i]) && <(equals.(type))("this.values[i]", "value")>)
            {
                return true;
            }
        }
        return false;
    }

    @Override
    public void each(<name>Procedure procedure)
    {
        this.forEachValue(procedure);
    }

    @Override
    public void forEachValue(<name>Procedure procedure)
    {
        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]))
            {
                procedure.value(this.values[i]);
            }
        }
    }

    @Override
    public void forEachKey(Procedure\<? super K> procedure)
    {
        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]))
            {
                procedure.value(this.toNonSentinel(this.keys[i]));
            }
        }
    }

    @Override
    public void forEachKeyValue(Object<name>Procedure\<? super K> procedure)
    {
        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]))
            {
                procedure.value(this.toNonSentinel(this.keys[i]), this.values[i]);
            }
        }
    }

    @Override
    public Object<name>HashMapWithHashingStrategy\<K> select(Object<name>Predicate\<? super K> predicate)
    {
        Object<name>HashMapWithHashingStrategy\<K> result = Object<name>HashMapWithHashingStrategy.newMap(this.hashingStrategy);

        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]) && predicate.accept(this.toNonSentinel(this.keys[i]), this.values[i]))
            {
                result.put(this.toNonSentinel(this.keys[i]), this.values[i]);
            }
        }
        return result;
    }

    @Override
    public Object<name>HashMapWithHashingStrategy\<K> reject(Object<name>Predicate\<? super K> predicate)
    {
        Object<name>HashMapWithHashingStrategy\<K> result = Object<name>HashMapWithHashingStrategy.newMap(this.hashingStrategy);

        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]) && !predicate.accept(this.toNonSentinel(this.keys[i]), this.values[i]))
            {
                result.put(this.toNonSentinel(this.keys[i]), this.values[i]);
            }
        }
        return result;
    }

    @Override
    public Mutable<name>Collection select(<name>Predicate predicate)
    {
        Mutable<name>List result = <name>Lists.mutable.empty();

        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]) && predicate.accept(this.values[i]))
            {
                result.add(this.values[i]);
            }
        }
        return result;
    }

    @Override
    public Mutable<name>Collection reject(<name>Predicate predicate)
    {
        Mutable<name>List result = <name>Lists.mutable.empty();

        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]) && !predicate.accept(this.values[i]))
            {
                result.add(this.values[i]);
            }
        }
        return result;
    }

    @Override
    public <type> detectIfNone(<name>Predicate predicate, <type> ifNone)
    {
        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]) && predicate.accept(this.values[i]))
            {
                return this.values[i];
            }
        }
        return ifNone;
    }

    @Override
    public \<V> MutableCollection\<V> collect(<name>ToObjectFunction\<? extends V> function)
    {
        MutableList\<V> result = Lists.mutable.withInitialCapacity(this.size());
        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]))
            {
                result.add(function.valueOf(this.values[i]));
            }
        }
        return result;
    }

    @Override
    public int count(<name>Predicate predicate)
    {
        int count = 0;

        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]) && predicate.accept(this.values[i]))
            {
                count++;
            }
        }
        return count;
    }

    @Override
    public boolean anySatisfy(<name>Predicate predicate)
    {
        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]) && predicate.accept(this.values[i]))
            {
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean allSatisfy(<name>Predicate predicate)
    {
        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]) && !predicate.accept(this.values[i]))
            {
                return false;
            }
        }
        return true;
    }

    @Override
    public boolean noneSatisfy(<name>Predicate predicate)
    {
        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]) && predicate.accept(this.values[i]))
            {
                return false;
            }
        }
        return true;
    }

    @Override
    public \<V> V injectInto(V injectedValue, Object<name>ToObjectFunction\<? super V, ? extends V> function)
    {
        V result = injectedValue;

        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]))
            {
                result = function.valueOf(result, this.values[i]);
            }
        }

        return result;
    }

    @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())
        {
            <name>Iterator iterator = this.<type>Iterator();
            while (iterator.hasNext())
            {
                Mutable<name>Bag batch = <name>Bags.mutable.empty();
                for (int i = 0; i \< size && iterator.hasNext(); i++)
                {
                    batch.add(iterator.next());
                }
                result.add(batch);
            }
        }
        return result;
    }

    @Override
    <if(primitive.floatingPoint)>public <wideType.(type)> sum()
{
    <wideType.(type)> result = <wideZero.(type)>;
    <wideType.(type)> compensation = <wideZero.(type)>;

    for (int i = 0; i \< this.keys.length; i++)
    {
        if (isNonSentinel(this.keys[i]))
        {
            <wideType.(type)> adjustedValue = this.values[i] - compensation;
            <wideType.(type)> nextSum = result + adjustedValue;
            compensation = nextSum - result - adjustedValue;
            result = nextSum;
        }
    }
    return result;
}

    <else>public <wideType.(type)> sum()
{
    <wideType.(type)> result = <wideZero.(type)>;

    for (int i = 0; i \< this.keys.length; i++)
    {
        if (isNonSentinel(this.keys[i]))
        {
            result += this.values[i];
        }
    }
    return result;
}

    <endif>
    @Override
    public <type> max()
    {
        if (this.isEmpty())
        {
            throw new NoSuchElementException();
        }
        <type> max = <zero.(type)>;
        boolean isMaxSet = false;

        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]) && (!isMaxSet || <(lessThan.(type))("max", "this.values[i]")>))
            {
                max = this.values[i];
                isMaxSet = true;
            }
        }
        return max;
    }

    @Override
    public <type> min()
    {
        if (this.isEmpty())
        {
            throw new NoSuchElementException();
        }
        <type> min = <zero.(type)>;
        boolean isMinSet = false;

        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]) && (!isMinSet || <(lessThan.(type))("this.values[i]", "min")>))
            {
                min = this.values[i];
                isMinSet = true;
            }
        }
        return min;
    }

    @Override
    public <type> maxIfEmpty(<type> defaultValue)
    {
        if (this.isEmpty())
        {
            return defaultValue;
        }
        <type> max = <zero.(type)>;
        boolean isMaxSet = false;

        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]) && (!isMaxSet || <(lessThan.(type))("max", "this.values[i]")>))
            {
                max = this.values[i];
                isMaxSet = true;
            }
        }
        return max;
    }

    @Override
    public <type> minIfEmpty(<type> defaultValue)
    {
        if (this.isEmpty())
        {
            return defaultValue;
        }
        <type> min = <zero.(type)>;
        boolean isMinSet = false;

        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]) && (!isMinSet || <(lessThan.(type))("this.values[i]", "min")>))
            {
                min = this.values[i];
                isMinSet = true;
            }
        }
        return min;
    }

    @Override
    public double average()
    {
        if (this.isEmpty())
        {
            throw new ArithmeticException();
        }
        return <castSum.(type)>this.sum() / (double) this.size();
    }

    @Override
    public double median()
    {
        if (this.isEmpty())
        {
            throw new ArithmeticException();
        }
        <type>[] sortedArray = this.toSortedArray();
        int middleIndex = sortedArray.length >\> 1;
        if (sortedArray.length > 1 && (sortedArray.length & 1) == 0)
        {
            <type> first = sortedArray[middleIndex];
            <type> second = sortedArray[middleIndex - 1];
            return ((double) first + (double) second) / 2.0;
        }
        return (double) sortedArray[middleIndex];
    }

    @Override
    public Mutable<name>List toList()
    {
        Mutable<name>List result = <name>Lists.mutable.withInitialCapacity(this.size());

        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]))
            {
                result.add(this.values[i]);
            }
        }
        return result;
    }

    @Override
    public Mutable<name>Set toSet()
    {
        Mutable<name>Set result = <name>Sets.mutable.empty();

        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]))
            {
                result.add(this.values[i]);
            }
        }
        return result;
    }

    @Override
    public Mutable<name>Bag toBag()
    {
        Mutable<name>Bag result = <name>Bags.mutable.empty();

        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]))
            {
                result.add(this.values[i]);
            }
        }
        return result;
    }

    @Override
    public Lazy<name>Iterable asLazy()
    {
        return new Lazy<name>IterableAdapter(this);
    }

    @Override
    public <type>[] toSortedArray()
    {
        <type>[] array = this.toArray();
        Arrays.sort(array);
        return array;
    }

    @Override
    public Mutable<name>List toSortedList()
    {
        return this.toList().sortThis();
    }

    @Override
    public void writeExternal(ObjectOutput out) throws IOException
    {
        out.writeObject(this.hashingStrategy);
        out.writeInt(this.size());
        for (int i = 0; i \< this.keys.length; i++)
        {
            if (isNonSentinel(this.keys[i]))
            {
                out.writeObject(this.toNonSentinel(this.keys[i]));
                out.write<name>(this.values[i]);
            }
        }
    }

    @Override
    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
    {
        this.hashingStrategy = (HashingStrategy\<? super K>) in.readObject();
        int size = in.readInt();
        int capacity = this.smallestPowerOfTwoGreaterThan(this.fastCeil(size \<\< 1));
        this.allocateTable(capacity);

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

    @Override
    public LazyIterable\<K> keysView()
    {
        return new KeysView();
    }

    @Override
    public RichIterable\<Object<name>Pair\<K>\> keyValuesView()
    {
        return new KeyValuesView();
    }

    <if(!primitive.booleanPrimitive)>
    @Override
    public Mutable<name>ObjectMap\<K> flipUniqueValues()
    {
        Mutable<name>ObjectMap\<K> result = <name>ObjectMaps.mutable.empty();
        this.forEachKeyValue((key, value) ->
        {
            K oldKey = result.put(value, key);
            if (oldKey != null)
            {
                throw new IllegalStateException("Duplicate value: " + value + " found at key: " + oldKey + " and key: " + key);
            }
        });
        return result;
    }
    <endif>

    /**
     * Rehashes every element in the set into a new backing table of the smallest possible size and eliminating removed sentinels.
     */
    public void compact()
    {
        this.rehash(this.smallestPowerOfTwoGreaterThan(this.size()));
    }

    private void rehashAndGrow()
    {
        int max = this.maxOccupiedWithData();
        int newCapacity = Math.max(max, smallestPowerOfTwoGreaterThan((this.occupiedWithData + 1) \<\< 1));
        if (this.occupiedWithSentinels > 0 && (max >\> 1) + (max >\> 2) \< this.occupiedWithData)
        {
            newCapacity \<\<= 1;
        }
        this.rehash(newCapacity);
    }

    private void rehash(int newCapacity)
    {
        int oldLength = this.keys.length;
        Object[] old = this.keys;
        <type>[] oldValues = this.values;
        this.allocateTable(newCapacity);
        this.occupiedWithData = 0;
        this.occupiedWithSentinels = 0;

        for (int i = 0; i \< oldLength; i++)
        {
            if (isNonSentinel(old[i]))
            {
                this.put(this.toNonSentinel(old[i]), oldValues[i]);
            }
        }
    }

    // exposed for testing
    int probe(Object element)
    {
        int index = this.spread(element);

        int removedIndex = -1;
        if (isRemovedKey(this.keys[index]))
        {
            removedIndex = index;
        }

        else if (this.keys[index] == null || this.nullSafeEquals(this.toNonSentinel(this.keys[index]), element))
        {
            return index;
        }

        int nextIndex = index;
        int probe = 17;

        // loop until an empty slot is reached
        while (true)
        {
            // Probe algorithm: 17*n*(n+1)/2 where n = no. of collisions
            nextIndex += probe;
            probe += 17;
            nextIndex &= this.keys.length - 1;

            if (isRemovedKey(this.keys[nextIndex]))
            {
                if (removedIndex == -1)
                {
                    removedIndex = nextIndex;
                }
            }
            else if (this.nullSafeEquals(this.toNonSentinel(this.keys[nextIndex]), element))
            {
                return nextIndex;
            }
            else if (this.keys[nextIndex] == null)
            {
                return removedIndex == -1 ? nextIndex : removedIndex;
            }
        }
    }

    // exposed for testing
    int spread(Object element)
    {
        // This function ensures that hashCodes that differ only by
        // constant multiples at each bit position have a bounded
        // number of collisions (approximately 8 at default load factor).
        K nonSentinelKey = this.toNonSentinel(element);
        int h = nonSentinelKey == null ? 0 : this.hashingStrategy.computeHashCode(nonSentinelKey);
        h ^= h >\>> 20 ^ h >\>> 12;
        h ^= h >\>> 7 ^ h >\>> 4;
        return h & (this.keys.length - 1);
    }

    private boolean nullSafeEquals(K value, Object other)
    {
        if (value == null)
        {
            if (other == null)
            {
                return true;
            }
        }
        else if (value != NULL_KEY && other != null)
        {
            if (this.hashingStrategy.equals(value, this.toNonSentinel(other)))
            {
                return true;
            }
        }
        return false;
    }

    protected void allocateTable(int sizeToAllocate)
    {
        this.keys = new Object[sizeToAllocate];
        this.values = new <type>[sizeToAllocate];
    }

    private static boolean isRemovedKey(Object key)
    {
        return key == REMOVED_KEY;
    }

    private static \<K> boolean isNonSentinel(K key)
    {
        return key != null && !isRemovedKey(key);
    }

    private K toNonSentinel(Object key)
    {
        return key == NULL_KEY ? null : (K) key;
    }

    private static Object toSentinelIfNull(Object key)
    {
        return key == null ? NULL_KEY : key;
    }

    private int maxOccupiedWithData()
    {
        int capacity = this.keys.length;
        // need at least one free slot for open addressing
        return Math.min(capacity - 1, capacity >\> 1);
    }

    private class Internal<name>Iterator implements Mutable<name>Iterator
    {
        private int count;
        private int position;

        @Override
        public boolean hasNext()
        {
            return this.count != Object<name>HashMapWithHashingStrategy.this.size();
        }

        @Override
        public <type> next()
        {
            if (!this.hasNext())
            {
                throw new NoSuchElementException();
            }

            Object[] keys = Object<name>HashMapWithHashingStrategy.this.keys;
            while (!isNonSentinel(keys[this.position]))
            {
                this.position++;
            }
            <type> result = Object<name>HashMapWithHashingStrategy.this.values[this.position];
            this.count++;
            this.position++;
            return result;
        }

        @Override
        public void remove()
        {
            if (this.position == 0 || !isNonSentinel(Object<name>HashMapWithHashingStrategy.this.keys[this.position - 1]))
            {
                throw new IllegalStateException();
            }
            Object<name>HashMapWithHashingStrategy.this.remove(Object<name>HashMapWithHashingStrategy.this.keys[this.position - 1]);
            this.count--;
        }
    }

    @Override
    public Set\<K> keySet()
    {
        return new KeySet();
    }

    @Override
    public Mutable<name>Collection values()
    {
        return new ValuesCollection();
    }

    private class KeySet implements Set\<K>
    {
        @Override
        public boolean equals(Object obj)
        {
            if (obj instanceof Set)
            {
                Set\<?> other = (Set\<?>) obj;
                if (other.size() == this.size())
                {
                    return this.containsAll(other);
                }
            }
            return false;
        }

        @Override
        public int hashCode()
        {
            int hashCode = 0;
            Object[] table = Object<name>HashMapWithHashingStrategy.this.keys;
            for (int i = 0; i \< table.length; i++)
            {
                Object key = table[i];
                if (Object<name>HashMapWithHashingStrategy.isNonSentinel(key))
                {
                    K nonSentinelKey = Object<name>HashMapWithHashingStrategy.this.toNonSentinel(key);
                    hashCode += nonSentinelKey == null ? 0 : Object<name>HashMapWithHashingStrategy.this.hashingStrategy.computeHashCode(nonSentinelKey);
                }
            }
            return hashCode;
        }

        @Override
        public int size()
        {
            return Object<name>HashMapWithHashingStrategy.this.size();
        }

        @Override
        public boolean isEmpty()
        {
            return Object<name>HashMapWithHashingStrategy.this.isEmpty();
        }

        @Override
        public boolean contains(Object o)
        {
            return Object<name>HashMapWithHashingStrategy.this.containsKey(o);
        }

        @Override
        public Object[] toArray()
        {
            int size = Object<name>HashMapWithHashingStrategy.this.size();
            Object[] result = new Object[size];
            this.copyKeys(result);
            return result;
        }

        @Override
        public \<T> T[] toArray(T[] result)
        {
            int size = Object<name>HashMapWithHashingStrategy.this.size();
            if (result.length \< size)
            {
                result = (T[]) Array.newInstance(result.getClass().getComponentType(), size);
            }
            this.copyKeys(result);
            if (size \< result.length)
            {
                result[size] = null;
            }
            return result;
        }

        @Override
        public boolean add(K key)
        {
            throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName());
        }

        @Override
        public boolean remove(Object key)
        {
            int oldSize = Object<name>HashMapWithHashingStrategy.this.size();
            Object<name>HashMapWithHashingStrategy.this.removeKey((K) key);
            return oldSize != Object<name>HashMapWithHashingStrategy.this.size();
        }

        @Override
        public boolean containsAll(Collection\<?> collection)
        {
            for (Object aCollection : collection)
            {
                if (!Object<name>HashMapWithHashingStrategy.this.containsKey(aCollection))
                {
                    return false;
                }
            }
            return true;
        }

        @Override
        public boolean addAll(Collection\<? extends K> collection)
        {
            throw new UnsupportedOperationException("Cannot call addAll() on " + this.getClass().getSimpleName());
        }

        @Override
        public boolean retainAll(Collection\<?> collection)
        {
            int oldSize = Object<name>HashMapWithHashingStrategy.this.size();
            Iterator\<K> iterator = this.iterator();
            while (iterator.hasNext())
            {
                K next = iterator.next();
                if (!collection.contains(next))
                {
                    iterator.remove();
                }
            }
            return oldSize != Object<name>HashMapWithHashingStrategy.this.size();
        }

        @Override
        public boolean removeAll(Collection\<?> collection)
        {
            int oldSize = Object<name>HashMapWithHashingStrategy.this.size();
            for (Object object : collection)
            {
                Object<name>HashMapWithHashingStrategy.this.removeKey((K) object);
            }
            return oldSize != Object<name>HashMapWithHashingStrategy.this.size();
        }

        @Override
        public void clear()
        {
            Object<name>HashMapWithHashingStrategy.this.clear();
        }

        @Override
        public Iterator\<K> iterator()
        {
            return new KeySetIterator();
        }

        private void copyKeys(Object[] result)
        {
            int count = 0;
            for (int i = 0; i \< Object<name>HashMapWithHashingStrategy.this.keys.length; i++)
            {
                Object key = Object<name>HashMapWithHashingStrategy.this.keys[i];
                if (Object<name>HashMapWithHashingStrategy.isNonSentinel(key))
                {
                    result[count++] = Object<name>HashMapWithHashingStrategy.this.keys[i];
                }
            }
        }
    }

    private class KeySetIterator implements Iterator\<K>
    {
        private int count;
        private int position;
        private K currentKey;
        private boolean isCurrentKeySet;

        @Override
        public boolean hasNext()
        {
            return this.count \< Object<name>HashMapWithHashingStrategy.this.size();
        }

        @Override
        public K next()
        {
            if (!this.hasNext())
            {
                throw new NoSuchElementException();
            }
            this.count++;
            Object[] keys = Object<name>HashMapWithHashingStrategy.this.keys;
            while (!isNonSentinel(keys[this.position]))
            {
                this.position++;
            }
            this.currentKey = (K) Object<name>HashMapWithHashingStrategy.this.keys[this.position];
            this.isCurrentKeySet = true;
            this.position++;
            return Object<name>HashMapWithHashingStrategy.this.toNonSentinel(this.currentKey);
        }

        @Override
        public void remove()
        {
            if (!this.isCurrentKeySet)
            {
                throw new IllegalStateException();
            }

            this.isCurrentKeySet = false;
            this.count--;

            if (isNonSentinel(this.currentKey))
            {
                int index = this.position - 1;
                Object<name>HashMapWithHashingStrategy.this.removeKeyAtIndex(Object<name>HashMapWithHashingStrategy.this.toNonSentinel(this.currentKey), index);
            }
            else
            {
                Object<name>HashMapWithHashingStrategy.this.removeKey(this.currentKey);
            }
        }
    }

    private class ValuesCollection implements Mutable<name>Collection
    {
        @Override
        public int size()
        {
            return Object<name>HashMapWithHashingStrategy.this.size();
        }

        @Override
        public boolean isEmpty()
        {
            return Object<name>HashMapWithHashingStrategy.this.isEmpty();
        }

        @Override
        public boolean notEmpty()
        {
            return Object<name>HashMapWithHashingStrategy.this.notEmpty();
        }

        @Override
        public String makeString()
        {
            return this.makeString(", ");
        }

        @Override
        public String makeString(String separator)
        {
            return this.makeString("", separator, "");
        }

        @Override
        public String makeString(String start, String separator, String end)
        {
            Appendable stringBuilder = new StringBuilder();
            this.appendString(stringBuilder, start, separator, end);
            return stringBuilder.toString();
        }

        @Override
        public void appendString(Appendable appendable)
        {
            this.appendString(appendable, ", ");
        }

        @Override
        public void appendString(Appendable appendable, String separator)
        {
            this.appendString(appendable, "", separator, "");
        }

        @Override
        public void appendString(Appendable appendable, String start, String separator, String end)
        {
            try
            {
                appendable.append(start);

                boolean first = true;

                for (int i = 0; i \< Object<name>HashMapWithHashingStrategy.this.keys.length; i++)
                {
                    Object key = Object<name>HashMapWithHashingStrategy.this.keys[i];
                    if (isNonSentinel(key))
                    {
                        if (!first)
                        {
                            appendable.append(separator);
                        }
                        appendable.append(String.valueOf(Object<name>HashMapWithHashingStrategy.this.values[i]));
                        first = false;
                    }
                }
                appendable.append(end);
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }
        }

        @Override
        public boolean add(<type> element)
        {
            throw new UnsupportedOperationException("Cannot call add() on " + this.getClass().getSimpleName());
        }

        @Override
        public boolean addAll(<type>... source)
        {
            throw new UnsupportedOperationException("Cannot call addAll() on " + this.getClass().getSimpleName());
        }

        @Override
        public boolean addAll(<name>Iterable source)
        {
            throw new UnsupportedOperationException("Cannot call addAll() on " + this.getClass().getSimpleName());
        }

        @Override
        public boolean remove(<type> item)
        {
            int oldSize = Object<name>HashMapWithHashingStrategy.this.size();

            for (int i = 0; i \< Object<name>HashMapWithHashingStrategy.this.keys.length; i++)
            {
                if (isNonSentinel(Object<name>HashMapWithHashingStrategy.this.keys[i]) && <(equals.(type))({item}, {Object<name>HashMapWithHashingStrategy.this.values[i]})>)
                {
                    Object<name>HashMapWithHashingStrategy.this.removeKey((K) Object<name>HashMapWithHashingStrategy.this.keys[i]);
                }
            }
            return oldSize != Object<name>HashMapWithHashingStrategy.this.size();
        }

        @Override
        public boolean removeAll(<name>Iterable source)
        {
            int oldSize = Object<name>HashMapWithHashingStrategy.this.size();

            <name>Iterator iterator = source.<type>Iterator();
            while (iterator.hasNext())
            {
                this.remove(iterator.next());
            }
            return oldSize != Object<name>HashMapWithHashingStrategy.this.size();
        }

        @Override
        public boolean removeAll(<type>... source)
        {
            int oldSize = Object<name>HashMapWithHashingStrategy.this.size();

            for (<type> item : source)
            {
                this.remove(item);
            }
            return oldSize != Object<name>HashMapWithHashingStrategy.this.size();
        }

        @Override
        public boolean retainAll(<name>Iterable source)
        {
            int oldSize = Object<name>HashMapWithHashingStrategy.this.size();
            final <name>Set sourceSet = source instanceof <name>Set ? (<name>Set) source : source.toSet();
            Object<name>HashMapWithHashingStrategy\<K> retained = Object<name>HashMapWithHashingStrategy.this.select((K object, <type> value) -> sourceSet.contains(value));
            if (retained.size() != oldSize)
            {
                Object<name>HashMapWithHashingStrategy.this.keys = retained.keys;
                Object<name>HashMapWithHashingStrategy.this.values = retained.values;
                Object<name>HashMapWithHashingStrategy.this.occupiedWithData = retained.occupiedWithData;
                Object<name>HashMapWithHashingStrategy.this.occupiedWithSentinels = retained.occupiedWithSentinels;
                return true;
            }
            return false;
        }

        @Override
        public boolean retainAll(<type>... source)
        {
            return this.retainAll(<name>Sets.mutable.with(source));
        }

        @Override
        public void clear()
        {
            Object<name>HashMapWithHashingStrategy.this.clear();
        }

        @Override
        public Mutable<name>Collection with(<type> element)
        {
            throw new UnsupportedOperationException("Cannot call with() on " + this.getClass().getSimpleName());
        }

        @Override
        public Mutable<name>Collection without(<type> element)
        {
            throw new UnsupportedOperationException("Cannot call without() on " + this.getClass().getSimpleName());
        }

        @Override
        public Mutable<name>Collection withAll(<name>Iterable elements)
        {
            throw new UnsupportedOperationException("Cannot call withAll() on " + this.getClass().getSimpleName());
        }

        @Override
        public Mutable<name>Collection withoutAll(<name>Iterable elements)
        {
            throw new UnsupportedOperationException("Cannot call withoutAll() on " + this.getClass().getSimpleName());
        }

        @Override
        public Mutable<name>Collection asUnmodifiable()
        {
            return Unmodifiable<name>Collection.of(this);
        }

        @Override
        public Mutable<name>Collection asSynchronized()
        {
            return Synchronized<name>Collection.of(this);
        }

        @Override
        public Immutable<name>Collection toImmutable()
        {
            return <name>Lists.immutable.withAll(this);
        }

        @Override
        public Mutable<name>Iterator <type>Iterator()
        {
            return Object<name>HashMapWithHashingStrategy.this.<type>Iterator();
        }

        @Override
        public <type>[] toArray()
        {
            return Object<name>HashMapWithHashingStrategy.this.toArray();
        }

        @Override
        public <type>[] toArray(<type>[] target)
        {
            return Object<name>HashMapWithHashingStrategy.this.toArray(target);
        }

        @Override
        public boolean contains(<type> value)
        {
            return Object<name>HashMapWithHashingStrategy.this.containsValue(value);
        }

        @Override
        public boolean containsAll(<type>... source)
        {
            return Object<name>HashMapWithHashingStrategy.this.containsAll(source);
        }

        @Override
        public boolean containsAll(<name>Iterable source)
        {
            return Object<name>HashMapWithHashingStrategy.this.containsAll(source);
        }

        @Override
        public void forEach(<name>Procedure procedure)
        {
            Object<name>HashMapWithHashingStrategy.this.forEach(procedure);
        }

        @Override
        public void each(<name>Procedure procedure)
        {
            this.forEach(procedure);
        }

        @Override
        public Mutable<name>Collection select(<name>Predicate predicate)
        {
            return Object<name>HashMapWithHashingStrategy.this.select(predicate);
        }

        @Override
        public Mutable<name>Collection reject(<name>Predicate predicate)
        {
            return Object<name>HashMapWithHashingStrategy.this.reject(predicate);
        }

        @Override
        public \<V> MutableCollection\<V> collect(<name>ToObjectFunction\<? extends V> function)
        {
            return Object<name>HashMapWithHashingStrategy.this.collect(function);
        }

        @Override
        public \<T> T injectInto(T injectedValue, Object<name>ToObjectFunction\<? super T, ? extends T> function)
        {
            return Object<name>HashMapWithHashingStrategy.this.injectInto(injectedValue, function);
        }

        @Override
        public RichIterable\<<name>Iterable> chunk(int size)
        {
            return Object<name>HashMapWithHashingStrategy.this.chunk(size);
        }

        @Override
        public <type> detectIfNone(<name>Predicate predicate, <type> ifNone)
        {
            return Object<name>HashMapWithHashingStrategy.this.detectIfNone(predicate, ifNone);
        }

        @Override
        public int count(<name>Predicate predicate)
        {
            return Object<name>HashMapWithHashingStrategy.this.count(predicate);
        }

        @Override
        public boolean anySatisfy(<name>Predicate predicate)
        {
            return Object<name>HashMapWithHashingStrategy.this.anySatisfy(predicate);
        }

        @Override
        public boolean allSatisfy(<name>Predicate predicate)
        {
            return Object<name>HashMapWithHashingStrategy.this.allSatisfy(predicate);
        }

        @Override
        public boolean noneSatisfy(<name>Predicate predicate)
        {
            return Object<name>HashMapWithHashingStrategy.this.noneSatisfy(predicate);
        }

        @Override
        public Mutable<name>List toList()
        {
            return Object<name>HashMapWithHashingStrategy.this.toList();
        }

        @Override
        public Mutable<name>Set toSet()
        {
            return Object<name>HashMapWithHashingStrategy.this.toSet();
        }

        @Override
        public Mutable<name>Bag toBag()
        {
            return Object<name>HashMapWithHashingStrategy.this.toBag();
        }

        @Override
        public Lazy<name>Iterable asLazy()
        {
            return new Lazy<name>IterableAdapter(this);
        }

        @Override
        public <type>[] toSortedArray()
        {
            return Object<name>HashMapWithHashingStrategy.this.toSortedArray();
        }

        @Override
        public Mutable<name>List toSortedList()
        {
            return Object<name>HashMapWithHashingStrategy.this.toSortedList();
        }

        @Override
        public <wideType.(type)> sum()
        {
            return Object<name>HashMapWithHashingStrategy.this.sum();
        }

        @Override
        public <type> max()
        {
            return Object<name>HashMapWithHashingStrategy.this.max();
        }

        @Override
        public <type> maxIfEmpty(<type> defaultValue)
        {
            return Object<name>HashMapWithHashingStrategy.this.maxIfEmpty(defaultValue);
        }

        @Override
        public <type> min()
        {
            return Object<name>HashMapWithHashingStrategy.this.min();
        }

        @Override
        public <type> minIfEmpty(<type> defaultValue)
        {
            return Object<name>HashMapWithHashingStrategy.this.minIfEmpty(defaultValue);
        }

        @Override
        public double average()
        {
            return Object<name>HashMapWithHashingStrategy.this.average();
        }

        @Override
        public double median()
        {
            return Object<name>HashMapWithHashingStrategy.this.median();
        }

        /**
         * @since 9.2.
         */
        @Override
        public Mutable<name>Collection newEmpty()
        {
            return <name>Bags.mutable.empty();
        }
    }

    private class KeysView extends AbstractLazyIterable\<K>
    {
        @Override
        public void each(Procedure\<? super K> procedure)
        {
            Object<name>HashMapWithHashingStrategy.this.forEachKey(procedure);
        }

        @Override
        public void forEachWithIndex(ObjectIntProcedure\<? super K> object<name>Procedure)
        {
            int index = 0;
            for (int i = 0; i \< Object<name>HashMapWithHashingStrategy.this.keys.length; i++)
            {
                if (Object<name>HashMapWithHashingStrategy.isNonSentinel(Object<name>HashMapWithHashingStrategy.this.keys[i]))
                {
                    object<name>Procedure.value(Object<name>HashMapWithHashingStrategy.this.toNonSentinel(Object<name>HashMapWithHashingStrategy.this.keys[i]), index);
                    index++;
                }
            }
        }

        @Override
        public \<P> void forEachWith(Procedure2\<? super K, ? super P> procedure, P parameter)
        {
            for (int i = 0; i \< Object<name>HashMapWithHashingStrategy.this.keys.length; i++)
            {
                if (Object<name>HashMapWithHashingStrategy.isNonSentinel(Object<name>HashMapWithHashingStrategy.this.keys[i]))
                {
                    procedure.value(Object<name>HashMapWithHashingStrategy.this.toNonSentinel(Object<name>HashMapWithHashingStrategy.this.keys[i]), parameter);
                }
            }
        }

        @Override
        public Iterator\<K> iterator()
        {
            return new InternalKeysViewIterator();
        }

        public class InternalKeysViewIterator implements Iterator\<K>
        {
            private int count;
            private int position;

            @Override
            public K next()
            {
                if (!this.hasNext())
                {
                    throw new NoSuchElementException();
                }

                Object[] keys = Object<name>HashMapWithHashingStrategy.this.keys;
                while (!isNonSentinel(keys[this.position]))
                {
                    this.position++;
                }
                K result = Object<name>HashMapWithHashingStrategy.this.toNonSentinel(Object<name>HashMapWithHashingStrategy.this.keys[this.position]);
                this.count++;
                this.position++;
                return result;
            }

            @Override
            public void remove()
            {
                throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName());
            }

            @Override
            public boolean hasNext()
            {
                return this.count != Object<name>HashMapWithHashingStrategy.this.size();
            }
        }
    }

    private class KeyValuesView extends AbstractLazyIterable\<Object<name>Pair\<K>\>
    {
        @Override
        public void each(Procedure\<? super Object<name>Pair\<K>\> procedure)
        {
            for (int i = 0; i \< Object<name>HashMapWithHashingStrategy.this.keys.length; i++)
            {
                if (Object<name>HashMapWithHashingStrategy.isNonSentinel(Object<name>HashMapWithHashingStrategy.this.keys[i]))
                {
                    procedure.value(PrimitiveTuples.pair(Object<name>HashMapWithHashingStrategy.this.toNonSentinel(Object<name>HashMapWithHashingStrategy.this.keys[i]), Object<name>HashMapWithHashingStrategy.this.values[i]));
                }
            }
        }

        @Override
        public void forEachWithIndex(ObjectIntProcedure\<? super Object<name>Pair\<K>\> objectIntProcedure)
        {
            int index = 0;
            for (int i = 0; i \< Object<name>HashMapWithHashingStrategy.this.keys.length; i++)
            {
                if (Object<name>HashMapWithHashingStrategy.isNonSentinel(Object<name>HashMapWithHashingStrategy.this.keys[i]))
                {
                    objectIntProcedure.value(PrimitiveTuples.pair(Object<name>HashMapWithHashingStrategy.this.toNonSentinel(Object<name>HashMapWithHashingStrategy.this.keys[i]), Object<name>HashMapWithHashingStrategy.this.values[i]), index);
                    index++;
                }
            }
        }

        @Override
        public \<P> void forEachWith(Procedure2\<? super Object<name>Pair\<K>, ? super P> procedure, P parameter)
        {
            for (int i = 0; i \< Object<name>HashMapWithHashingStrategy.this.keys.length; i++)
            {
                if (Object<name>HashMapWithHashingStrategy.isNonSentinel(Object<name>HashMapWithHashingStrategy.this.keys[i]))
                {
                    procedure.value(PrimitiveTuples.pair(Object<name>HashMapWithHashingStrategy.this.toNonSentinel(Object<name>HashMapWithHashingStrategy.this.keys[i]), Object<name>HashMapWithHashingStrategy.this.values[i]), parameter);
                }
            }
        }

        @Override
        public Iterator\<Object<name>Pair\<K>\> iterator()
        {
            return new InternalKeyValuesIterator();
        }

        public class InternalKeyValuesIterator implements Iterator\<Object<name>Pair\<K>\>
        {
            private int count;
            private int position;

            @Override
            public Object<name>Pair\<K> next()
            {
                if (!this.hasNext())
                {
                    throw new NoSuchElementException();
                }

                Object[] keys = Object<name>HashMapWithHashingStrategy.this.keys;
                while (!isNonSentinel(keys[this.position]))
                {
                    this.position++;
                }
                Object<name>Pair\<K> result = PrimitiveTuples.pair(Object<name>HashMapWithHashingStrategy.this.toNonSentinel(Object<name>HashMapWithHashingStrategy.this.keys[this.position]), Object<name>HashMapWithHashingStrategy.this.values[this.position]);
                this.count++;
                this.position++;
                return result;
            }

            @Override
            public void remove()
            {
                throw new UnsupportedOperationException("Cannot call remove() on " + this.getClass().getSimpleName());
            }

            @Override
            public boolean hasNext()
            {
                return this.count != Object<name>HashMapWithHashingStrategy.this.size();
            }
        }
    }
}

>>

procedureImport ::= [
    "int": "noImport",
    "default": "intImport"
    ]

intImport() ::= <<
import org.eclipse.collections.api.block.procedure.primitive.ObjectIntProcedure;
>>

noImport() ::= <<
>>
