private boolean attemptDateRangeOptimization(And and, Retrieve retrieve, String alias) {
        if (retrieve.getDateProperty() != null || retrieve.getDateRange() != null) {
            return false;
        }

        for (int i = 0; i < and.getOperand().size(); i++) {
            Expression operand = and.getOperand().get(i);
            if ((operand instanceof IncludedIn || operand instanceof In) && attemptDateRangeOptimization((BinaryExpression) operand, retrieve, alias)) {
                // Replace optimized part in And with true -- to be optimized out later
                and.getOperand().set(i, libraryBuilder.createLiteral(true));
                return true;
            } else if (operand instanceof And && attemptDateRangeOptimization((And) operand, retrieve, alias)) {
                return true;
            }
        }

        return false;
    }
private boolean attemptDateRangeOptimization ( And and , Retrieve retrieve , String alias ) { if ( retrieve . getDateProperty ( ) != null || retrieve . getDateRange ( ) != null ) { return false ; } for ( int i = 0 ; i < and . getOperand ( ) . size ( ) ; i ++ ) { Expression operand = and . getOperand ( ) . get ( i ) ; if ( ( operand instanceof IncludedIn || operand instanceof In ) && attemptDateRangeOptimization ( ( BinaryExpression ) operand , retrieve , alias ) ) { and . getOperand ( ) . set ( i , libraryBuilder . createLiteral ( true ) ) ; return true ; } else if ( operand instanceof And && attemptDateRangeOptimization ( ( And ) operand , retrieve , alias ) ) { return true ; } } return false ; }
Test an <code>And</code> expression and determine if it contains any operands (first-level or nested deeper)
than are <code>IncludedIn</code> expressions that can be refactored into a <code>Retrieve</code>.  If so,
adjust the <code>Retrieve</code> accordingly and reset the corresponding operand to a literal
<code>true</code>.  This <code>and</code> branch containing a <code>true</code> can be further consolidated
later.

@param and      the <code>And</code> expression containing operands to potentially refactor into the
<code>Retrieve</code>
@param retrieve the <code>Retrieve</code> to add qualifying date ranges to (if applicable)
@param alias    the alias of the <code>Retrieve</code> in the query.
@return <code>true</code> if the date range was set in the <code>Retrieve</code> and the <code>And</code>
operands (or sub-operands) were modified; <code>false</code> otherwise.