import java.util.List;

class FstGenerator {

    private StringBuffer strBuff;
    private List<State> fstStates;

    public FstGenerator(List<State> fstStates) {
        this.fstStates = fstStates;
        this.strBuff = new StringBuffer();
    }

    public StringBuffer compute() {
        append("class FstCompute {");
        generateMain();

        for ( State state : fstStates ) {
            generateStateCase(state);
        }

        append("}");

        return strBuff;
    }

    private void generateMain() {
        appendWithTab("public static float compute(int[] token) {", 1);

        appendWithTab("return node_0(token, 0, 0f);", 2);

        appendWithTab("}", 1);
    }

    private void generateStateCase(State state) {
        switch (state.getNumArcs()) {
            case 0:
                generateLastStateCase(state);
                break;
            case 1:
                generateStateWithOneArc(state);
                break;
            default:
                generateGeneralState(state);
                break;
        } 
    }

    private void generateLastStateCase(State state) {
        appendWithTab("private static float node_" + state.getId()
               + "(int[] token, int pos, float result) {", 1); 
        appendWithTab("return result;", 2);
        appendWithTab("}", 1);
    }

    private void generateStateWithOneArc(State state) {
        appendWithTab("private static float node_" + state.getId()
                + "(int[] token, int pos, float result) {", 1);

        appendWithTab("if(pos>=token.length || token[pos]!=" + 
                state.getArc(0).getIlabel() + ")",2);
        appendWithTab("return -1;", 3);
        appendWithTab("return node_" + state.getArc(0).getNextState().getId()
               + "(token, pos+1, result+" +
               state.getArc(0).getWeight() + ");", 2);

        appendWithTab("}", 1);
    }

    private void generateGeneralState(State state) {

    }

    private void append(String strToAppend) {
        strBuff.append(strToAppend);
        strBuff.append("\n");
    }

    private void appendWithTab(String strToAppend, int numberOfTab) {
        for (int i = 0; i < numberOfTab; i++) {
            strBuff.append("\t");
        }
        strBuff.append(strToAppend);
        strBuff.append("\n");
    }

}

@@ -1847,16 +1847,17 @@
 ht() + %22
+f
 );%22, 2);
@@ -1949,16 +1949,719 @@
 tate) %7B%0A
+        appendWithTab(%22private static float node_%22 + state.getId()%0A               + %22(int%5B%5D token, int pos, float result) %7B%22, 1); %0A        appendWithTab(%22if(pos%3E=token.length) %7Breturn -1;%7D%22, 2);%0A        appendWithTab(%22switch(token%5Bpos%5D) %7B%22, 2);%0A        for (int i = 0; i %3C state.getNumArcs(); i++) %7B%0A            appendWithTab(%22case %22 + state.getArc(i).getIlabel()  + %22:%22, 3); %0A        appendWithTab(%22return node_%22 + state.getArc(i).getNextState().getId()%0A               + %22(token, pos+1, result+%22 +%0A               state.getArc(i).getWeight() + %22f);%22, 4);%0A        %7D%0A        appendWithTab(%22default:%22, 3);%0A        appendWithTab(%22return -1;%22, 4);%0A        appendWithTab(%22%7D%22,2);%0A        appendWithTab(%22%7D%22, 1);
 %0A    %7D%0A%0A

Add general state case