import java.util.*;

public class MathsParser
{
    public MathsParser (boolean debug)
    {
        _debug = debug;
    }

    /**
     * All numbers within expressions are single digit so we can continue to use them as
     * characters.
     * 
     * Handle different precedence  to part 1.
     */

    public long parse (Vector<String> data)
    {
        long finalResult = 0L;

        for (int i = 0; i < data.size(); i++)
        {
            String currentLine = data.elementAt(i);
            long currentResult = 0L;
            Stack<Character> operators = new Stack<Character>();
            Stack<Long> values = new Stack<Long>();
            char[] lineArray = currentLine.trim().replaceAll("\\s", "").toCharArray(); // remove all spaces
            char operator = Tokens.SPACE;

            for (int j = 0; j < lineArray.length; j++)
            {
                switch (lineArray[j])
                {
                    case Tokens.PLUS:
                    case Tokens.MULTIPLY:
                    {
                        operator = lineArray[j];
                    }
                    break;
                    case Tokens.OPEN_BRACE:
                    {
                        operators.push(operator);
                        operator = Tokens.SPACE;

                        values.push(currentResult);
                        currentResult = 0L;

                        if (_debug)
                            System.out.println("1 currentResult "+currentResult);
                    }
                    break;
                    case Tokens.CLOSE_BRACE:
                    {
                        switch (operators.pop())
                        {
                            case Tokens.PLUS:
                            {
                                currentResult += values.pop();

                                if (_debug)
                                    System.out.println("2 currentResult "+currentResult);
                            }
                            break;
                            case Tokens.MULTIPLY:
                            {
                                currentResult *= values.pop();

                                if (_debug)
                                    System.out.println("3 currentResult "+currentResult);
                            }
                            break;
                            default:
                            {
                                values.pop();

                                if (_debug)
                                    System.out.println("4 currentResult "+currentResult);
                            }
                            break;
                        }
                    }
                    break;
                    default:
                    {
                        switch (operator)
                        {
                            case Tokens.PLUS:
                            {
                                currentResult += Character.getNumericValue(lineArray[j]);

                                if (_debug)
                                    System.out.println("5 currentResult "+currentResult);
                            }
                            break;
                            case Tokens.MULTIPLY:
                            {
                                currentResult *= Character.getNumericValue(lineArray[j]);

                                if (_debug)
                                    System.out.println("6 currentResult "+currentResult);
                            }
                            break;
                            default:
                            {
                                currentResult = Character.getNumericValue(lineArray[j]);

                                if (_debug)
                                    System.out.println("7 currentResult "+currentResult);
                            }
                            break;
                        }
                    }
                }
            }

            finalResult += currentResult;
        }

        return finalResult;
    }

    private boolean _debug;
}
@@ -503,3601 +503,103 @@
     
-long currentResult = 0L;%0A            Stack%3CCharacter%3E operators = new Stack%3CCharacter%3E();%0A            Stack%3CLong%3E values = new Stack%3CLong%3E();%0A            char%5B%5D lineArray = currentLine.trim().replaceAll(%22%5C%5Cs%22, %22%22).toCharArray(); // remove all spaces%0A            char operator = Tokens.SPACE;%0A%0A            for (int j = 0; j %3C lineArray.length; j++)%0A            %7B%0A                switch (lineArray%5Bj%5D)%0A                %7B%0A                    case Tokens.PLUS:%0A                    case Tokens.MULTIPLY:%0A                    %7B%0A                        operator = lineArray%5Bj%5D;%0A                    %7D%0A                    break;%0A                    case Tokens.OPEN_BRACE:%0A                    %7B%0A                        operators.push(operator);%0A                        operator = Tokens.SPACE;%0A%0A                        values.push(currentResult);%0A                        currentResult = 0L;%0A%0A                        if (_debug)%0A                            System.out.println(%221 currentResult %22+currentResult);%0A                    %7D%0A                    break;%0A                    case Tokens.CLOSE_BRACE:%0A                    %7B%0A                        switch (operators.pop())%0A                        %7B%0A                            case Tokens.PLUS:%0A                            %7B%0A                                currentResult += values.pop();%0A%0A                                if (_debug)%0A                                    System.out.println(%222 currentResult %22+currentResult);%0A                            %7D%0A                            break;%0A                            case Tokens.MULTIPLY:%0A                            %7B%0A                                currentResult *= values.pop();%0A%0A                                if (_debug)%0A                                    System.out.println(%223 currentResult %22+currentResult);%0A                            %7D%0A                            break;%0A                            default:%0A                            %7B%0A                                values.pop();%0A%0A                                if (_debug)%0A                                    System.out.println(%224 currentResult %22+currentResult);%0A                            %7D%0A                            break;%0A                        %7D%0A                    %7D%0A                    break;%0A                    default:%0A                    %7B%0A                        switch (operator)%0A                        %7B%0A                            case Tokens.PLUS:%0A                            %7B%0A                                currentResult += Character.getNumericValue(lineArray%5Bj%5D);%0A%0A                                if (_debug)%0A                                    System.out.println(%225 currentResult %22+currentResult);%0A                            %7D%0A                            break;%0A                            case Tokens.MULTIPLY:%0A                            %7B%0A                                currentResult *= Character.getNumericValue(lineArray%5Bj%5D);%0A%0A                                if (_debug)%0A                                    System.out.println(%226 currentResult %22+currentResult);%0A                            %7D%0A                            break;%0A                            default:%0A                            %7B%0A                                currentResult = Character.getNumericValue(lineArray%5Bj%5D);%0A%0A                                if (_debug)%0A                                    System.out.println(%227 currentResult %22+currentResult);%0A                            %7D%0A                            break;%0A                        %7D%0A                    %7D%0A                %7D%0A            %7D%0A%0A            finalResult += currentResult;
+char%5B%5D lineArray = currentLine.trim().replaceAll(%22%5C%5Cs%22, %22%22).toCharArray(); // remove all spaces
 %0A   

Update MathsParser.java