/*
 * StringSwitch shows how to build a class that
 * uses switch based on strings.
 * @author Tom Roland and Douglas A. Lyon
 * @version  Oct 16, 2002.11:39:30 AM
 */
package utils;

import java.util.HashMap;


public class StringSwitch {
  private static final int QUIT = 0;
  private static final int DIR = 1;

  private StringSwitch() {
    add("quit", QUIT);
    add("dir", DIR);
  }

  private HashMap hm = new HashMap();


  private final void add(String s, int id) {
    hm.put(s, new Integer(id));
  }

  public static void main(String[] args) {
    StringSwitch fs = new StringSwitch();
    fs.doSwitch("quit");
    fs.doSwitch("dir");
  }

  public final void doSwitch(String s) {
    switch (getIdForString(s)) {
      case QUIT:
        System.out.println("QUIT=" + QUIT);
        break;
      case DIR:
        System.out.println("DIR=" + DIR);
        break;
    }
  }


  private int getIdForString(String s) {
    return ((Integer) hm.get(s)).intValue();
  }
}