src/main/java/utils/Common.java
/**
     * Process all keywords and give the final result if text matches keywords or not.<br>
     * Keywords need to be asserted for the right syntax.
     * <ul>
     *     <li>Replace all OR with a white space</li>
     *     <li>Add spaces before and after braces</li>
     *     <li>Trim the string</li>
     *     <li>Remove duplicate spaces</li>
     *     <li>Remove empty groups if there are any</li>
     *     <li>Assert for the right syntax</li>
     * </ul>
     * List of unacceptable combinations:
     * <ul>
     *     <li>AND, OR, NOT on it's own</li>
     *     <li>AND OR, NOT NOT, NOT AND, NOT OR, AND AND, OR OR, OR AND</li>
     *     <li>Can't start with OR or AND</li>
     *     <li>Can't end with OR or AND</li>
     *     <li>NOT { }, { } AND, AND { }</li>
     * </ul>
     * @param text search this text for matching keywords
     * @param keywords reference to {@link KeywordCollection} that has a string of keywords that need to be processed
     *                 and bool to store final result.
     * @return false when processing is done and no more keywords left to process.
     */
Process all keywords and give the final result if text matches keywords or not.
Keywords need to be asserted for the right syntax.

Replace all OR with a white space
Add spaces before and after braces
Trim the string
Remove duplicate spaces
Remove empty groups if there are any
Assert for the right syntax

List of unacceptable combinations:

AND, OR, NOT on it's own
AND OR, NOT NOT, NOT AND, NOT OR, AND AND, OR OR, OR AND
Can't start with OR or AND
Can't end with OR or AND
NOT { }, { } AND, AND { }

@param text search this text for matching keywords
@param keywords reference to  KeywordCollection that has a string of keywords that need to be processed
and bool to store final result.
@return false when processing is done and no more keywords left to process.
Process all keywords and give the final result if text matches keywords or not . Keywords need to be asserted for the right syntax . Replace all OR with a white space Add spaces before and after braces Trim the string Remove duplicate spaces Remove empty groups if there are any Assert for the right syntax List of unacceptable combinations : AND OR NOT on it ' s own AND OR NOT NOT NOT AND NOT OR AND AND OR OR OR AND Can ' t start with OR or AND Can ' t end with OR or AND NOT { } { } AND AND { } @param text search this text for matching keywords @param keywords reference to KeywordCollection that has a string of keywords that need to be processed and bool to store final result . @return false when processing is done and no more keywords left to process .
private static boolean processRecursiveAllKeywords(String text, KeywordCollection keywords) {
        String tempKeyword;
        KeywordCollection tempKeywordCollection;
        int firstSpace;
        boolean isMoreToProcess;
        firstSpace = keywords.getKeywords().indexOf(" ");
        if (firstSpace == -1) {
            keywords.setResult(keywords.getResult() || processSingleKeyword(text, keywords.getKeywords()));
            return false;
        } else {
            if (firstSpace == 3) {
                if (keywords.getKeywords().charAt(0) == 'A' && keywords.getKeywords().charAt(1) == 'N' && keywords.getKeywords().charAt(2) == 'D') {
                    if (keywords.getKeywords().length() > 6) {
                        if (keywords.getKeywords().charAt(4) == 'N' && keywords.getKeywords().charAt(5) == 'O' && keywords.getKeywords().charAt(6) == 'T') {
                            tempKeyword = keywords.getKeywords().substring(4);
                            tempKeywordCollection = new KeywordCollection(tempKeyword);
                            isMoreToProcess = processNOT(text, tempKeywordCollection);
                            keywords.setKeywords(tempKeywordCollection.getKeywords());
                            keywords.setResult(keywords.getResult() && !tempKeywordCollection.getResult());
                            return isMoreToProcess;
                        }
                    }
                    tempKeyword = keywords.getKeywords().substring(4);
                    if (tempKeyword.charAt(0) == '{') {
                        tempKeywordCollection = new KeywordCollection(tempKeyword);
                        isMoreToProcess = processGroup(text, tempKeywordCollection);
                        keywords.setResult(keywords.getResult() && tempKeywordCollection.getResult());
                        keywords.setKeywords(tempKeywordCollection.getKeywords());
                        return isMoreToProcess;
                    }
                    firstSpace = tempKeyword.indexOf(" ");
                    if (firstSpace == -1) {
                        keywords.setResult(keywords.getResult() && processSingleKeyword(text, tempKeyword));
                        return false;
                    } else {
                        tempKeyword = tempKeyword.substring(0, firstSpace);
                        keywords.setResult(keywords.getResult() && processSingleKeyword(text, tempKeyword));
                        keywords.setKeywords(keywords.getKeywords().substring(firstSpace + 5));
                        return true;
                    }
                } else if (keywords.getKeywords().charAt(0) == 'N' && keywords.getKeywords().charAt(1) == 'O' && keywords.getKeywords().charAt(2) == 'T') {
                    tempKeywordCollection = keywords;
                    isMoreToProcess = processNOT(text, tempKeywordCollection);
                    keywords.setKeywords(tempKeywordCollection.getKeywords());
                    keywords.setResult(keywords.getResult() || tempKeywordCollection.getResult());
                    return isMoreToProcess;
                }
            }
            if (keywords.getKeywords().charAt(0) == '{') {
                tempKeywordCollection = keywords;
                isMoreToProcess = processGroup(text, tempKeywordCollection);
                keywords.setResult(keywords.getResult() || tempKeywordCollection.getResult());
                keywords.setKeywords(tempKeywordCollection.getKeywords());
                return isMoreToProcess;
            }
            tempKeyword = keywords.getKeywords().substring(0, firstSpace);
            keywords.setResult(keywords.getResult() || processSingleKeyword(text, tempKeyword));
            keywords.setKeywords(keywords.getKeywords().substring(firstSpace + 1));
            return true;
        }
    }
private static boolean processRecursiveAllKeywords ( String text , KeywordCollection keywords ) { String tempKeyword ; KeywordCollection tempKeywordCollection ; int firstSpace ; boolean isMoreToProcess ; firstSpace = keywords . getKeywords ( ) . indexOf ( " " ) ; if ( firstSpace == - 1 ) { keywords . setResult ( keywords . getResult ( ) || processSingleKeyword ( text , keywords . getKeywords ( ) ) ) ; return false ; } else { if ( firstSpace == 3 ) { if ( keywords . getKeywords ( ) . charAt ( 0 ) == 'A' && keywords . getKeywords ( ) . charAt ( 1 ) == 'N' && keywords . getKeywords ( ) . charAt ( 2 ) == 'D' ) { if ( keywords . getKeywords ( ) . length ( ) > 6 ) { if ( keywords . getKeywords ( ) . charAt ( 4 ) == 'N' && keywords . getKeywords ( ) . charAt ( 5 ) == 'O' && keywords . getKeywords ( ) . charAt ( 6 ) == 'T' ) { tempKeyword = keywords . getKeywords ( ) . substring ( 4 ) ; tempKeywordCollection = new KeywordCollection ( tempKeyword ) ; isMoreToProcess = processNOT ( text , tempKeywordCollection ) ; keywords . setKeywords ( tempKeywordCollection . getKeywords ( ) ) ; keywords . setResult ( keywords . getResult ( ) && ! tempKeywordCollection . getResult ( ) ) ; return isMoreToProcess ; } } tempKeyword = keywords . getKeywords ( ) . substring ( 4 ) ; if ( tempKeyword . charAt ( 0 ) == '{' ) { tempKeywordCollection = new KeywordCollection ( tempKeyword ) ; isMoreToProcess = processGroup ( text , tempKeywordCollection ) ; keywords . setResult ( keywords . getResult ( ) && tempKeywordCollection . getResult ( ) ) ; keywords . setKeywords ( tempKeywordCollection . getKeywords ( ) ) ; return isMoreToProcess ; } firstSpace = tempKeyword . indexOf ( " " ) ; if ( firstSpace == - 1 ) { keywords . setResult ( keywords . getResult ( ) && processSingleKeyword ( text , tempKeyword ) ) ; return false ; } else { tempKeyword = tempKeyword . substring ( 0 , firstSpace ) ; keywords . setResult ( keywords . getResult ( ) && processSingleKeyword ( text , tempKeyword ) ) ; keywords . setKeywords ( keywords . getKeywords ( ) . substring ( firstSpace + 5 ) ) ; return true ; } } else if ( keywords . getKeywords ( ) . charAt ( 0 ) == 'N' && keywords . getKeywords ( ) . charAt ( 1 ) == 'O' && keywords . getKeywords ( ) . charAt ( 2 ) == 'T' ) { tempKeywordCollection = keywords ; isMoreToProcess = processNOT ( text , tempKeywordCollection ) ; keywords . setKeywords ( tempKeywordCollection . getKeywords ( ) ) ; keywords . setResult ( keywords . getResult ( ) || tempKeywordCollection . getResult ( ) ) ; return isMoreToProcess ; } } if ( keywords . getKeywords ( ) . charAt ( 0 ) == '{' ) { tempKeywordCollection = keywords ; isMoreToProcess = processGroup ( text , tempKeywordCollection ) ; keywords . setResult ( keywords . getResult ( ) || tempKeywordCollection . getResult ( ) ) ; keywords . setKeywords ( tempKeywordCollection . getKeywords ( ) ) ; return isMoreToProcess ; } tempKeyword = keywords . getKeywords ( ) . substring ( 0 , firstSpace ) ; keywords . setResult ( keywords . getResult ( ) || processSingleKeyword ( text , tempKeyword ) ) ; keywords . setKeywords ( keywords . getKeywords ( ) . substring ( firstSpace + 1 ) ) ; return true ; } }
Process all keywords and give the final result if text matches keywords or not.<br>
 Keywords need to be asserted for the right syntax.
Process all keywords and give the final result if text matches keywords or not . <br > Keywords need to be asserted for the right syntax .
// Find next space. If there's none then  no more keywords left to process // This is the last keyword. Process and terminate recursion // If there's a space at index '3' then it's may be a NOT, or an AND // check if it's AND ------------------------------------- // Check if there's NOT after AND // There are no operators before the keywords. Process as AND keyword //'NOT keyword(firstSpace)' // Check if it's NOT ------------------------------------- // Process as OR NOT // There's no AND or NOT ---------------------------------------------------------------------- // There are no operators before the keywords. Process as OR keyword