All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javax.slee.profile.query.Not Maven / Gradle / Ivy

The newest version!
package javax.slee.profile.query;

/**
 * The Not class is a composite dynamic query expression that
 * inverts the match result of its nested query expression.
 */
public final class Not extends QueryExpression {
    /**
     * Create a Not query expression.
     * @param expr the query expression who's match result will be inverted
     *        by this Not expression.
     * @throws NullPointerException if expr is null.
     */
    public Not(QueryExpression expr) {
        if (expr == null) throw new NullPointerException("expr is null");
        this.expr = expr;
    }

    /**
     * Get the query expression who's match result will be inverted by this Not
     * query expression.
     * @return the nested query expression.
     */
    public QueryExpression getExpression() { return expr; }


    // protected

    // javadoc copied from parent
    protected void toString(StringBuffer buf) {
        buf.append("!(");
        expr.toString(buf);
        buf.append(')');
    }


    // package

    /**
     * Check whether the specified expression contains a reference, either direct
     * or indirect, to this expression.
     * @param expr the expression to check and possibly recurse through.
     * @throws IllegalArgumentException if a cyclic expression is detected.
     */
    void checkForCycles(QueryExpression expr) throws IllegalArgumentException {
        // is the expression argument equal to this?
        if (expr == this) throw new IllegalArgumentException("Cyclic expression detected");

        // recurse through nested expression if it's a composite expression
        QueryExpression nested = this.expr;
        if (nested instanceof CompositeQueryExpression) {
            ((CompositeQueryExpression)nested).checkForCycles(expr);
        }
        else if (nested instanceof Not) {
            ((Not)nested).checkForCycles(expr);
        }
    }


    private final QueryExpression expr;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy