package collections.stringswitch;
import utils.Timer;
public class SwitchTest extends StringSwitch {
static SwitchTest st;
static Timer timer;
static int COUNT;
static final int ITER = 20;
public final int QUIT = 0;
public final int DIR = 1;
public final int RUN = 2;
public final int STOP = 3;
public final int DEBUG = 4;
public final int FWD = 5;
public static final int REV = 6;
public SwitchTest() {
add("quit", 0);
add("dir", 1);
add("run", 2);
add("stop", 3);
add("debug", 4);
add("forward", 5);
add("reverse", 6);
}
public static void main(String[] args) {
if (args.length < 1) {
System.err.println("Usage: stringswitch.SwitchTest [COUNT]");
System.exit(0);
}
COUNT = Integer.parseInt(args[0]);
System.out.println("COUNT = " + COUNT + "\n");
SwitchTest switchtest = new SwitchTest();
timer = new Timer();
switchtest.runIfThen("reverse");
switchtest.runIfThen("quit");
switchtest.runStringSwitch("reverse");
switchtest.runIntSwitch(REV);
}
private void doStringSwitch(String s) {
switch (getIdForString(s)) {
case QUIT:
break;
case DIR:
break;
case RUN:
break;
case STOP:
break;
case DEBUG:
break;
case FWD:
break;
case REV:
break;
}
}
private void doIntSwitch(int i) {
switch (i) {
case QUIT:
break;
case DIR:
break;
case RUN:
break;
case STOP:
break;
case DEBUG:
break;
case FWD:
break;
case REV:
break;
}
}
private void doIf(String s) {
if (s.equals("quit")) {
} else if (s.equals("dir")) {
} else if (s.equals("run")) {
} else if (s.equals("stop")) {
} else if (s.equals("debug")) {
} else if (s.equals("forward")) {
} else if (s.equals("reverse")) {
}
}
private void runIfThen(String svalue) {
System.out.println("\nTesting if-then with a String (Bottom)");
for (int i = 0; i < ITER; i++) {
timer.clear();
timer.mark();
for (int j = 0; j < COUNT; j++) {
st.doIf(svalue);
}
timer.record();
System.out.println(timer.elapsed());
}
}
private void runIntSwitch(int ivalue) {
System.out.println("\nTesting Switch with an int");
for (int i = 0; i < ITER; i++) {
timer.clear();
timer.mark();
for (int j = 0; j < COUNT; j++) {
st.doIntSwitch(ivalue);
}
timer.record();
System.out.println(timer.elapsed());
}
}
private void runStringSwitch(String svalue) {
System.out.println("\nTesting Switch with a String");
for (int i = 0; i < ITER; i++) {
timer.clear();
timer.mark();
for (int j = 0; j < COUNT; j++) {
st.doStringSwitch(svalue);
}
timer.record();
System.out.println(timer.elapsed());
}
}
}