Search in sources :

Example 1 with LogicalExpr

use of org.jaxen.expr.LogicalExpr in project webservices-axiom by apache.

the class ExprComparator method compare.

public int compare(Object o1, Object o2) {
    int type1 = getType(o1);
    int type2 = getType(o2);
    int cmp;
    if (type1 == type2) {
        switch(type1) {
            case TYPE_ADDITIVE_EXPR:
                AdditiveExpr additiveExpr1 = (AdditiveExpr) o1;
                AdditiveExpr additiveExpr2 = (AdditiveExpr) o2;
                cmp = additiveExpr1.getOperator().compareTo(additiveExpr2.getOperator());
                if (cmp == 0) {
                    cmp = compare(additiveExpr1.getLHS(), additiveExpr2.getLHS());
                    if (cmp == 0) {
                        cmp = compare(additiveExpr1.getRHS(), additiveExpr2.getRHS());
                    }
                }
                break;
            case TYPE_ALL_NODE_STEP:
                AllNodeStep allNodeStep1 = (AllNodeStep) o1;
                AllNodeStep allNodeStep2 = (AllNodeStep) o2;
                cmp = allNodeStep1.getAxis() - allNodeStep2.getAxis();
                if (cmp == 0) {
                    cmp = compareLists(allNodeStep1.getPredicates(), allNodeStep2.getPredicates());
                }
                break;
            case TYPE_COMMENT_NODE_STEP:
                CommentNodeStep commentNodeStep1 = (CommentNodeStep) o1;
                CommentNodeStep commentNodeStep2 = (CommentNodeStep) o2;
                cmp = commentNodeStep1.getAxis() - commentNodeStep2.getAxis();
                if (cmp == 0) {
                    cmp = compareLists(commentNodeStep1.getPredicates(), commentNodeStep2.getPredicates());
                }
                break;
            case TYPE_EQUALITY_EXPR:
                EqualityExpr equalityExpr1 = (EqualityExpr) o1;
                EqualityExpr equalityExpr2 = (EqualityExpr) o2;
                cmp = equalityExpr1.getOperator().compareTo(equalityExpr2.getOperator());
                if (cmp == 0) {
                    cmp = compare(equalityExpr1.getLHS(), equalityExpr1.getLHS());
                    if (cmp == 0) {
                        cmp = compare(equalityExpr1.getRHS(), equalityExpr1.getRHS());
                    }
                }
                break;
            case TYPE_FILTER_EXPR:
                if (true)
                    throw new RuntimeException("Not yet implemented!");
                break;
            case TYPE_FUNCTION_CALL_EXPR:
                FunctionCallExpr functionCallExpr1 = (FunctionCallExpr) o1;
                FunctionCallExpr functionCallExpr2 = (FunctionCallExpr) o2;
                cmp = compareStrings(functionCallExpr1.getPrefix(), functionCallExpr2.getPrefix());
                if (cmp == 0) {
                    cmp = functionCallExpr1.getFunctionName().compareTo(functionCallExpr2.getFunctionName());
                    if (cmp == 0) {
                        cmp = compareLists(functionCallExpr1.getParameters(), functionCallExpr2.getParameters());
                    }
                }
                break;
            case TYPE_LITERAL_EXPR:
                LiteralExpr literalExpr1 = (LiteralExpr) o1;
                LiteralExpr literalExpr2 = (LiteralExpr) o2;
                cmp = literalExpr1.getLiteral().compareTo(literalExpr2.getLiteral());
                break;
            case TYPE_LOCATION_PATH:
                LocationPath locationPath1 = (LocationPath) o1;
                LocationPath locationPath2 = (LocationPath) o2;
                if (locationPath1.isAbsolute() == locationPath2.isAbsolute()) {
                    cmp = compareLists(locationPath1.getSteps(), locationPath2.getSteps());
                } else if (locationPath1.isAbsolute()) {
                    cmp = 1;
                } else {
                    cmp = -1;
                }
                break;
            case TYPE_LOGICAL_EXP:
                LogicalExpr logicalExpr1 = (LogicalExpr) o1;
                LogicalExpr logicalExpr2 = (LogicalExpr) o2;
                cmp = logicalExpr1.getOperator().compareTo(logicalExpr2.getOperator());
                if (cmp == 0) {
                    cmp = compare(logicalExpr1.getLHS(), logicalExpr2.getLHS());
                    if (cmp == 0) {
                        cmp = compare(logicalExpr1.getRHS(), logicalExpr2.getRHS());
                    }
                }
                break;
            case TYPE_MULTIPLICATIVE_EXPR:
                MultiplicativeExpr multiplicativeExpr1 = (MultiplicativeExpr) o1;
                MultiplicativeExpr multiplicativeExpr2 = (MultiplicativeExpr) o2;
                cmp = multiplicativeExpr1.getOperator().compareTo(multiplicativeExpr2.getOperator());
                if (cmp == 0) {
                    cmp = compare(multiplicativeExpr1.getLHS(), multiplicativeExpr2.getLHS());
                    if (cmp == 0) {
                        cmp = compare(multiplicativeExpr1.getRHS(), multiplicativeExpr2.getRHS());
                    }
                }
                break;
            case TYPE_NAME_STEP:
                NameStep nameStep1 = (NameStep) o1;
                NameStep nameStep2 = (NameStep) o2;
                cmp = nameStep1.getAxis() - nameStep2.getAxis();
                if (cmp == 0) {
                    cmp = compareStrings(nameStep1.getPrefix(), nameStep2.getPrefix());
                    if (cmp == 0) {
                        cmp = nameStep1.getLocalName().compareTo(nameStep2.getLocalName());
                        if (cmp == 0) {
                            cmp = compareLists(nameStep1.getPredicates(), nameStep2.getPredicates());
                        }
                    }
                }
                break;
            case TYPE_NUMBER_EXPR:
                NumberExpr numberExpr1 = (NumberExpr) o1;
                NumberExpr numberExpr2 = (NumberExpr) o2;
                cmp = new Double(numberExpr1.getNumber().doubleValue()).compareTo(new Double(numberExpr2.getNumber().doubleValue()));
                break;
            case TYPE_PATH_EXPR:
                PathExpr pathExpr1 = (PathExpr) o1;
                PathExpr pathExpr2 = (PathExpr) o2;
                cmp = compare(pathExpr1.getLocationPath(), pathExpr2.getLocationPath());
                if (cmp == 0) {
                    cmp = compare(pathExpr1.getFilterExpr(), pathExpr2.getFilterExpr());
                }
                break;
            case TYPE_PREDICATE:
                Predicate predicate1 = (Predicate) o1;
                Predicate predicate2 = (Predicate) o2;
                cmp = compare(predicate1.getExpr(), predicate2.getExpr());
                break;
            case TYPE_PROCESSING_INSTRUCTION_NODE_STEP:
                ProcessingInstructionNodeStep processingInstructionNodeStep1 = (ProcessingInstructionNodeStep) o1;
                ProcessingInstructionNodeStep processingInstructionNodeStep2 = (ProcessingInstructionNodeStep) o2;
                cmp = processingInstructionNodeStep1.getAxis() - processingInstructionNodeStep2.getAxis();
                if (cmp == 0) {
                    cmp = compareStrings(processingInstructionNodeStep1.getName(), processingInstructionNodeStep2.getName());
                    if (cmp == 0) {
                        cmp = compareLists(processingInstructionNodeStep1.getPredicates(), processingInstructionNodeStep2.getPredicates());
                    }
                }
                break;
            case TYPE_RELATIONAL_EXPR:
                RelationalExpr relationalExpr1 = (RelationalExpr) o1;
                RelationalExpr relationalExpr2 = (RelationalExpr) o2;
                cmp = relationalExpr1.getOperator().compareTo(relationalExpr2.getOperator());
                if (cmp == 0) {
                    cmp = compare(relationalExpr1.getLHS(), relationalExpr2.getLHS());
                    if (cmp == 0) {
                        cmp = compare(relationalExpr1.getRHS(), relationalExpr2.getRHS());
                    }
                }
                break;
            case TYPE_TEXT_NODE_STEP:
                TextNodeStep textNodeStep1 = (TextNodeStep) o1;
                TextNodeStep textNodeStep2 = (TextNodeStep) o2;
                cmp = textNodeStep1.getAxis() - textNodeStep2.getAxis();
                if (cmp == 0) {
                    cmp = compareLists(textNodeStep1.getPredicates(), textNodeStep2.getPredicates());
                }
                break;
            case TYPE_UNARY_EXPR:
                UnaryExpr unaryExpr1 = (UnaryExpr) o1;
                UnaryExpr unaryExpr2 = (UnaryExpr) o2;
                cmp = compare(unaryExpr1.getExpr(), unaryExpr2.getExpr());
                break;
            case TYPE_UNION_EXPR:
                if (true)
                    throw new RuntimeException("Not yet implemented!");
                break;
            case TYPE_VARIABLE_REFERENCE_EXPR:
                VariableReferenceExpr variableReferenceExpr1 = (VariableReferenceExpr) o1;
                VariableReferenceExpr variableReferenceExpr2 = (VariableReferenceExpr) o2;
                cmp = compareStrings(variableReferenceExpr1.getPrefix(), variableReferenceExpr2.getPrefix());
                if (cmp == 0) {
                    cmp = variableReferenceExpr1.getVariableName().compareTo(variableReferenceExpr2.getVariableName());
                }
                break;
            default:
                throw new IllegalArgumentException("Unhandled type: " + type1);
        }
    } else {
        cmp = type1 - type2;
    }
    return cmp;
}
Also used : TextNodeStep(org.jaxen.expr.TextNodeStep) RelationalExpr(org.jaxen.expr.RelationalExpr) UnaryExpr(org.jaxen.expr.UnaryExpr) Predicate(org.jaxen.expr.Predicate) VariableReferenceExpr(org.jaxen.expr.VariableReferenceExpr) MultiplicativeExpr(org.jaxen.expr.MultiplicativeExpr) ProcessingInstructionNodeStep(org.jaxen.expr.ProcessingInstructionNodeStep) EqualityExpr(org.jaxen.expr.EqualityExpr) FunctionCallExpr(org.jaxen.expr.FunctionCallExpr) AdditiveExpr(org.jaxen.expr.AdditiveExpr) LocationPath(org.jaxen.expr.LocationPath) NumberExpr(org.jaxen.expr.NumberExpr) CommentNodeStep(org.jaxen.expr.CommentNodeStep) NameStep(org.jaxen.expr.NameStep) AllNodeStep(org.jaxen.expr.AllNodeStep) LiteralExpr(org.jaxen.expr.LiteralExpr) LogicalExpr(org.jaxen.expr.LogicalExpr) PathExpr(org.jaxen.expr.PathExpr)

Aggregations

AdditiveExpr (org.jaxen.expr.AdditiveExpr)1 AllNodeStep (org.jaxen.expr.AllNodeStep)1 CommentNodeStep (org.jaxen.expr.CommentNodeStep)1 EqualityExpr (org.jaxen.expr.EqualityExpr)1 FunctionCallExpr (org.jaxen.expr.FunctionCallExpr)1 LiteralExpr (org.jaxen.expr.LiteralExpr)1 LocationPath (org.jaxen.expr.LocationPath)1 LogicalExpr (org.jaxen.expr.LogicalExpr)1 MultiplicativeExpr (org.jaxen.expr.MultiplicativeExpr)1 NameStep (org.jaxen.expr.NameStep)1 NumberExpr (org.jaxen.expr.NumberExpr)1 PathExpr (org.jaxen.expr.PathExpr)1 Predicate (org.jaxen.expr.Predicate)1 ProcessingInstructionNodeStep (org.jaxen.expr.ProcessingInstructionNodeStep)1 RelationalExpr (org.jaxen.expr.RelationalExpr)1 TextNodeStep (org.jaxen.expr.TextNodeStep)1 UnaryExpr (org.jaxen.expr.UnaryExpr)1 VariableReferenceExpr (org.jaxen.expr.VariableReferenceExpr)1