public class MTDict {
  static final int MAXSIZE= 100;

  String[] keys= new String[MAXSIZE], defs= new String[MAXSIZE];
  int size= 0;

  public String query(String key) {
    for (int i= 0; i<size; i++)
      if (keys[i].equals(key))
        return defs[i];
    return null;
  }

  public int getSize() {
    return size;
  }

  public synchronized void addDef(String key, String def) {
    int pos= size++;
    if (size>MAXSIZE)
      throw new Error("Dictionary overflow");
    defs[pos]= def;
    keys[pos]= key;
  }

  // End of class MTDict

  // The following code is there just to test MTDict

  public static void main(String[] args) throws Exception {
    String[] keys= new String[MAXSIZE];
    for (int i= 0; i<MAXSIZE; i++)
      keys[i]= ""+i;

    for (int k=0; ; k++) {
      MTDict dict= new MTDict();
      QueryThread t= new QueryThread(dict);
      for (int i= 0; i<MAXSIZE; i++)
        dict.addDef(keys[i], "hello");
      t.join();
      if (k%100==0)
        System.out.print(".");
    }
  }

  static class QueryThread extends Thread {
    MTDict dict;
    QueryThread(MTDict dict) {
      this.dict= dict;
      start();
    }
    public void run() {
      while(dict.getSize()<MAXSIZE)
        if (dict.query("none")!=null)
          throw new Error("Inconsistent query answer");
    }
  }
}
