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 {");
        emptyLine(); 
        generateMain();
        emptyLine();

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

        append("}");

        return strBuff;
    }

    private void generateStateCase(State state) {
        
    }

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

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

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

        appendWithTab("}", 1);
    }

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

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

}

@@ -330,63 +330,20 @@
     
-emptyLine(); %0A        generateMain();%0A        emptyLine
+generateMain
 ();%0A
@@ -516,161 +516,624 @@
 rate
-StateCase(State state) %7B%0A        %0A    %7D%0A%0A    private void append(String strToAppend) %7B%0A        strBuff.append(strToAppend);%0A        strBuff.append(%22%5Cn%22);
+Main() %7B%0A        appendWithTab(%22public static float compute(int%5B%5D token) %7B%22, 1);%0A%0A        appendWithTab(%22return node_0(token, 0, 0f);%22, 2);%0A%0A        appendWithTab(%22%7D%22, 1);%0A    %7D%0A%0A    private void generateStateCase(State state) %7B%0A        switch (state.getNumArcs()) %7B%0A            case 0:%0A                generateLastStateCase(state);%0A                break;%0A            case 1:%0A                generateStateWithOneArc(state);%0A                break;%0A            default:%0A                generateGeneralState(state);%0A                break;%0A        %7D %0A    %7D%0A%0A    private void generateLastStateCase(State state) %7B%0A        
 %0A   
@@ -1153,37 +1153,59 @@
 te void generate
-Main(
+StateWithOneArc(State state
 ) %7B%0A        appe
@@ -1216,29 +1216,30 @@
 thTab(%22p
-ublic
+rivate
  static 
 int comp
@@ -1234,42 +1234,260 @@
 tic 
-int compute(int%5B%5D token) %7B%22, 1
+float node_%22 + state.getId()%0A                + %22(int%5B%5D token, int pos, float result) %7B%22, 1);%0A%0A        appendWithTab(%22if(pos%3E=token.length %7C%7C token%5Bpos%5D!=%22 + %0A                state.getArc(0).getIlabel() + %22)%22,2);%0A        appendWithTab(%22return -1;%22, 3
 );%0A
-%0A
     
@@ -1521,59 +1521,360 @@
 ode_
-0(token, 0, 0);%22, 2);%0A%0A        appendWithTab(%22%7D%22, 1
+%22 + state.getArc(0).getNextState().getId()%0A               + %22(token, pos+1, result+%22 +%0A               state.getArc(0).getWeight() + %22);%22, 2);%0A%0A        appendWithTab(%22%7D%22, 1);%0A    %7D%0A%0A    private void generateGeneralState(State state) %7B%0A%0A    %7D%0A%0A    private void append(String strToAppend) %7B%0A        strBuff.append(strToAppend);%0A        strBuff.append(%22%5Cn%22
 );%0A 
@@ -2119,74 +2119,6 @@
  %7D%0A%0A
-    private void emptyLine() %7B%0A        strBuff.append(%22%5Cn%22);%0A    %7D%0A%0A
 %7D%0A

add case for state with only one arc