package rebelsky.generics; public class ArrayBasedNewDict implements NewDict { Pair[] contents; int len; public ArrayBasedNewDict() { this.contents = new Pair[16]; this.len = 0; } public void put(I index, V value) { // Step through all the positions in the array to see // if I have a matching index. for (int i = 0; i < len; i++) { if (this.contents[i].index.equals(index)) { // If so, update the corresponding value and stop this.contents[i].value = value; return; } // if } // for // If I've gotten this far, it's not there so add it this.contents[len] = new Pair(index, value); len++; } // put(I, V) public V get(I index) { // Step through all the positions in the array to see // if I have a matching index. for (int i = 0; i < len; i++) { if (this.contents[i].index.equals(index)) { // If so, return the corresponding value return this.contents[i].value; } // if } // for } // get(I) } // ArrayBasedNewDict