Route route() {
        Route route = new Route();
        for (int from = 0, at = 0, depth = 0; at <= routeText.length(); ++at) {
            if (at == routeText.length() || ((depth == 0) && Character.isWhitespace(routeText.charAt(at)))) {
                if (from < at) {
                    Hop hop = createHop(routeText.substring(from, at));
                    if (hop.hasDirectives() && hop.getDirective(0) instanceof ErrorDirective) {
                        return new Route().addHop(new Hop().addDirective(hop.getDirective(0)));
                    }
                    route.addHop(hop);
                }
                from = at + 1;
            } else if ((routeText.charAt(at) == '(') || (routeText.charAt(at) == '[') ) {
                ++depth;
            } else if ((routeText.charAt(at) == ')') || (routeText.charAt(at) == ']')) {
                --depth;
            }
        }
        return route;
    }
This replaces the incredibly slow javacc RouteParser.jj. It is a has its c++ sibling and
the implementation is a a copy of the C++ version.
@author baldersheim
@since 5.2
messagebus/src/main/java/com/yahoo/messagebus/routing/RouteParser.java