public List<Predicate> parsePredicates(String input) throws ParseException {
        List<Predicate> predicates = new ArrayList<Predicate>();

        int numberOfBrackets = 0;

        int start = 0;
        for (int end = 0; end < input.length(); ++end) {
            char currentChar = input.charAt(end);
            switch (currentChar) {
                case '(':
                    numberOfBrackets++;
                    break;

                case ')':
                    numberOfBrackets--;
                    break;

                case ',':
                    if (numberOfBrackets == 0) {
                        String predicate = input.substring(start, end);
                        predicates.add(parsePredicate(predicate.trim()));

                        // Skip the current character for the next search (hence the +1)
                        // and start looking for more predicates from this position
                        // onwards.
                        start = end + 1;
                    }
                    break;
            }
        }

        String lastPredicate = input.substring(start);
        predicates.add(parsePredicate(lastPredicate.trim()));

        return predicates;
    }