// // Returns false if array is full... // public class ArrayMemoDatabase implements MemoDatabase { private MemoAssociation[] pair; private int counter; public ArrayMemoDatabase() { pair = new MemoAssociation[10]; counter = 0; } public boolean insert( MemoAssociation m ) { if ( counter == pair.length ) return false; if ( containsKey(m.key()) ) return false; pair[counter] = m; counter++; return true; } public String find( String key ) { int location = slotFor( key ); if ( location == -1 ) return null; return pair[location].value(); } public boolean remove( String key ) { int location = slotFor( key ); if ( location == -1 ) return false; pair[location] = pair[counter-1]; counter--; return true; } public boolean containsKey( String key ) { return slotFor( key ) >= 0; } private int slotFor( String key ) { for (int i = 0; i < counter; i++) if (key.equals( pair[i].key() )) return i; return -1; } }