private int countMatches(String text, String token) {
        int lastIndex = 0;
        int count = 0;

        while (lastIndex != -1) {
            lastIndex = text.indexOf(token, lastIndex);
            if (lastIndex != -1) {
                count++;
                lastIndex += token.length();
            }
        }
        return count;
    }
Count the number of occurrences of a substring in a text.

@param text  the complete text
@param token the substring
@return number of occurrences
modules/siddhi-core/src/test/java/io/siddhi/core/debugger/TestDebuggerClient.java