public boolean contains()

in phoenix-core-client/src/main/java/org/apache/phoenix/expression/ComparisonExpression.java [361:485]


    public boolean contains(Expression other) {
        if (!(other instanceof ComparisonExpression || other instanceof IsNullExpression)) {
            return false;
        }
        if (other instanceof IsNullExpression) {
            return !((IsNullExpression) other).isNegate();
        }

        BaseTerminalExpression lhsA =
                WhereCompiler.getBaseTerminalExpression(this.getChildren().get(0));
        BaseTerminalExpression lhsB =
                WhereCompiler.getBaseTerminalExpression(other.getChildren().get(0));
        if (!lhsA.equals(lhsB)) {
            return false;
        }
        CompareOperator opA = this.getFilterOp();
        CompareOperator opB = ((ComparisonExpression) other).getFilterOp();
        BaseTerminalExpression rhs = WhereCompiler.getBaseTerminalExpression(
                this.getChildren().get(1));
        if (rhs instanceof ColumnExpression) {
            BaseTerminalExpression rhsB = WhereCompiler.getBaseTerminalExpression(
                    other.getChildren().get(1));
            if (!rhs.equals(rhsB)) {
                return false;
            }
            switch (opA) {
                case LESS_OR_EQUAL:
                    if (opB == LESS || opB == LESS_OR_EQUAL || opB == EQUAL) {
                        return true;
                    }
                    return false;
                case LESS:
                case EQUAL:
                case NOT_EQUAL:
                case GREATER:
                    if (opA == opB) {
                        return true;
                    }
                    return false;
                case GREATER_OR_EQUAL:
                    if (opB == GREATER || opB == GREATER_OR_EQUAL || opB == EQUAL) {
                        return true;
                    }
                    return false;
                default:
                    throw new IllegalArgumentException("Unexpected CompareOp " + opA);
            }
        }
        LiteralExpression rhsA = WhereCompiler.getLiteralExpression(this.getChildren().get(1));
        LiteralExpression rhsB = WhereCompiler.getLiteralExpression(other.getChildren().get(1));
        Object valA = rhsA.getValue();
        Object valB = rhsB.getValue();

        PDataType typeA = rhsA.getDataType();
        PDataType typeB = rhsB.getDataType();
        switch (opA){
        case LESS:
            if (opB == GREATER_OR_EQUAL || opB == GREATER || opB == NOT_EQUAL) {
                return false;
            }
            if (opB == LESS) {
                if (typeA.compareTo(valA, valB, typeB) >= 0) {
                    return true;
                }
                return false;
            }
            if (opB == LESS_OR_EQUAL || opB == EQUAL) {
                if (typeA.compareTo(valA, valB, typeB) > 0) {
                    return true;
                }
                return false;
            }
            return false;
        case LESS_OR_EQUAL:
            if (opB == GREATER_OR_EQUAL || opB == GREATER || opB ==NOT_EQUAL) {
                return false;
            }
            if (opB == LESS_OR_EQUAL || opB == LESS || opB == EQUAL) {
                if (typeA.compareTo(valA, valB, typeB) >= 0) {
                    return true;
                }
                return false;
            }
            return false;
        case EQUAL:
        case NOT_EQUAL:
            if (opA != opB) {
                return false;
            }
            if (typeA.compareTo(valA, valB, typeB) == 0) {
                return true;
            }
            return false;
        case GREATER_OR_EQUAL:
            if (opB == LESS_OR_EQUAL || opB == LESS || opB ==NOT_EQUAL) {
                return false;
            }
            if (opB == GREATER_OR_EQUAL || opB == GREATER || opB == EQUAL) {
                if (typeA.compareTo(valA, valB, typeB) <= 0) {
                    return true;
                }
                return false;
            }
            return false;
        case GREATER:
            if (opB == LESS_OR_EQUAL || opB == LESS || opB ==NOT_EQUAL) {
                return false;
            }
            if (opB == GREATER) {
                if (typeA.compareTo(valA, valB, typeB) <= 0) {
                    return true;
                }
                return false;
            }
            if (opB == GREATER_OR_EQUAL || opB == EQUAL) {
                if (typeA.compareTo(valA, valB, typeB) < 0) {
                    return true;
                }
                return false;
            }
            return false;
        default:
            throw new IllegalArgumentException("Unexpected CompareOp of " + opA);
        }
    }