package ru.job4j.map;
public class Map<K, V> {

    public Entry[] container = new Entry[2];
    private int capacity = 10;
    private int index = 0;

    public Entry[] ensureCapacity(int length) {
        capacity = capacity + length;
        Entry[] array = new Entry[capacity];
        for (int i = 0; i < container.length; i++) {
            if (container[i]!=null) {
                addEntry(array, (K) container[i].key, (V) container[i].value);
            }
        }
        return array;
    }

    public int getCell(K key) {
        return Math.abs(key.hashCode() % container.length);
    }

    public boolean addEntry(Entry[] array, K key, V value) {
        int cell = getCell(key);
        if (array[cell] == null) {
            array[cell] = new Entry(key, value);
            index++;
            return true;
        } else {
            return false;
        }
    }

    public boolean insert(K key, V value) {
        if (index > container.length - 1) {
            container = ensureCapacity(index + 10);
        }
        return addEntry(container, key, value);
    }

    public V get(K key) {
        int cell = getCell(key);
        return (V) container[cell];
    }

    public boolean delete(K key) {
        int cell = getCell(key);
        if (container[cell] != null) {
            container[cell] = null;
            return true;
        } else {
            return false;
        }
    }

}
@@ -522,16 +522,31 @@
 getCell(
+Entry%5B%5D array, 
 K key) %7B
@@ -587,25 +587,21 @@
 ode() %25 
-container
+array
 .length)
@@ -689,32 +689,39 @@
  cell = getCell(
+array, 
 key);%0A        if
@@ -1150,32 +1150,43 @@
  cell = getCell(
+container, 
 key);%0A        re
@@ -1280,16 +1280,27 @@
 getCell(
+container, 
 key);%0A  
@@ -1450,16 +1450,15 @@
       %7D%0A
+
     %7D%0A
-%0A
 %7D

task #1008