import java.util.Set; /** * This class contains a set of methods that are useful for testing * Java disassemblers and control-flow graph generators. * * @author Matthias.Hauswirth@usi.ch */ public class ExampleClass { public void emptyMethod() { return; } //--- conditionals public int ifMethod(int i) { int j = 0; if (i<0) { j = 1; } return j; } public int ifElseMethod(int i) { int j = 0; if (i>0) { j = 0; } else { j = i; } return j; } public int switchMethod(int i) { int j = 0; switch (i) { case 0: j = 0; break; case 1: j = 1; break; case 2: j = 2; break; default: j = -1; } return j; } public int switchMethod2(int i) { int j = 0; switch (i) { case 0: j = 0; break; case 1000: j = 1; break; case 2000: j = 2; break; default: j = -1; } return j; } //--- loops public int forMethod(int i) { int sum = 0; for (int j=0; j0) { sum +=i; i--; } return sum; } public int doWhileMethod(int i) { int sum = 0; do { sum += i; i--; } while (i>0); return sum; } public int forEachArrayMethod(String[] a) { int sum = 0; for (String s : a) { sum++; } return sum; } public int forEachCollectionMethod(Set a) { int sum = 0; for (String s : a) { sum++; } return sum; } public int forWithBreakMethod(int n) { int sum = 0; for (int i=0; ib?a:b; } public int shortCircuitMethod(int i, int j, int k) { if (i>j && ij & i