private static Hop createHop(String s) {
        final int len = s.length();
        if (len == 0) {
            return new Hop().addDirective(createErrorDirective("Failed to parse empty string."));
        } else if (len > 1 && (s.charAt(0) == '?')) {
            return createHop(s.substring(1, len)).setIgnoreResult(true);
        } else if (len > 4 && s.charAt(0) == 't' && s.charAt(1) == 'c' && s.charAt(2) == 'p' && s.charAt(3) == '/') {
            HopDirective directive = createTcpDirective(s.substring(4, len));
            if (directive != null) {
                return new Hop().addDirective(directive);
            }
        } else if (len > 6 && s.charAt(0) == 'r' && s.charAt(1) == 'o' && s.charAt(2) == 'u'
                           && s.charAt(3) == 't' && s.charAt(4) == 'e' && s.charAt(5) == ':') {
            return new Hop().addDirective(createRouteDirective(s.substring(6, len)));
        }
        Hop hop = new Hop();
        for (int from = 0, at = 0, depth = 0; at <= len; ++at) {
            if (at == len) {
                if (depth > 0) {
                    return new Hop().addDirective(createErrorDirective("Unterminated '[' in '" + s + "'"));
                }
                hop.addDirective(createDirective(s.substring(from, at)));
                from = at + 1;
            } else {
                char c = s.charAt(at);
                if (Character.isWhitespace(c) && depth == 0) {
                    return new Hop().addDirective(createErrorDirective("Failed to completely parse '" + s + "'."));
                } else if ((depth == 0 && c == '/')) {
                    hop.addDirective(createDirective(s.substring(from, at)));
                    from = at + 1;
                } else if (c == '[') {
                    ++depth;
                } else if (c == ']') {
                    if (depth == 0) {
                        return new Hop().addDirective(createErrorDirective("Unexpected token ']' in '" + s + "'"));
                    }
                    --depth;
                }
            }
        }
        return hop;
    }
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