import org.junit.Test;

import java.util.ArrayList;

import static org.assertj.core.api.Assertions.assertThat;


class HEntry<T, K> {
    private T key;
    private K value;

    HEntry(T key, K value) {
        this.key = key;
        this.setValue(value);
    }

    T getKey() {
        return key;
    }

    K getValue() {
        return value;
    }

    void setValue(K value) {
        this.value = value;
    }
}

//TODO: resize
class Hashtbl<T, K> {
    private ArrayList<ArrayList<HEntry<T, K>>> table;
    private int size;

    Hashtbl() {
        this(20);
    }

    private Hashtbl(int size) {
        this.size = size;
        table = new ArrayList<>(this.size);

        for (int i = 0; i < this.size; i++) {
            table.add(new ArrayList<>());
        }
    }

    private int indexOf(T key) {
        return key.hashCode() % this.table.size();
    }

    void put(T key, K value) throws Exception {
        int idx = indexOf(key);
        ArrayList<HEntry<T, K>> bucket = table.get(idx);

        for (HEntry<T, K> item : bucket) {
            if (item.getKey().equals(key)) {
                item.setValue(value);
                return;
            }
        }

        bucket.add(new HEntry<>(key, value));
    }

    K get(T key) throws Exception {
        int idx = indexOf(key);
        ArrayList<HEntry<T, K>> bucket = table.get(idx);

        for (HEntry<T, K> item : bucket) {
            if (item.getKey().equals(key)) return item.getValue();
        }

        throw new Exception("key not found!");
    }

    void remove(T key) throws Exception {
        int idx = indexOf(key);
        ArrayList<HEntry<T, K>> bucket = table.get(idx);
        if (bucket != null) {
            for (int i = 0; i < bucket.size(); i++) {
                if (bucket.get(i).getKey().equals(key)) {
                    bucket.remove(i);
                    break;
                }
            }
        }

        throw new Exception("key not found!");
    }
}

public class HastblTest {

    @Test
    public void bidi_Test() {

        Hashtbl<String, Integer> hashtbl = new Hashtbl<>();
        try {
            hashtbl.put("A", 1);
            hashtbl.put("B", 2);
            hashtbl.put("C", 3);

            System.out.println(hashtbl.get("B"));

            hashtbl.remove("B");

            System.out.println(hashtbl.get("B"));

        } catch (Exception e) {
            e.printStackTrace();
        }

        assertThat(true).isEqualTo(true);
    }
}

@@ -1672,49 +1672,17 @@
 x);%0A
-        if (bucket != null) %7B%0A   
+%0A
         
  for
@@ -1673,25 +1673,24 @@
 );%0A%0A        
- 
 for (int i =
@@ -1711,36 +1711,32 @@
 .size(); i++) %7B%0A
-    
             if (
@@ -1785,28 +1785,24 @@
             
-   
- 
 bucket.remov
@@ -1827,37 +1827,15 @@
     
-    
 break;%0A
-                %7D%0A
     
@@ -1911,16 +1911,16 @@
    %7D%0A%7D%0A%0A
-
 public c
@@ -1927,16 +1927,17 @@
 lass Has
+h
 tblTest 

update hashtbl remove bidi