Examples of ArithmeticOperand


Examples of org.jboss.dna.graph.query.model.ArithmeticOperand

    public static DynamicOperand replaceViewReferences( QueryContext context,
                                                        DynamicOperand operand,
                                                        ColumnMapping mapping,
                                                        PlanNode node ) {
        if (operand instanceof ArithmeticOperand) {
            ArithmeticOperand arith = (ArithmeticOperand)operand;
            DynamicOperand newLeft = replaceViewReferences(context, arith.getLeft(), mapping, node);
            DynamicOperand newRight = replaceViewReferences(context, arith.getRight(), mapping, node);
            return new ArithmeticOperand(newLeft, arith.getOperator(), newRight);
        }
        if (operand instanceof FullTextSearchScore) {
            FullTextSearchScore score = (FullTextSearchScore)operand;
            if (!mapping.getOriginalName().equals(score.getSelectorName())) return score;
            if (mapping.isMappedToSingleSelector()) {
                return new FullTextSearchScore(mapping.getSingleMappedSelectorName());
            }
            // There are multiple mappings, so we have to create a composite score ...
            DynamicOperand composite = null;
            for (SelectorName name : mapping.getMappedSelectorNames()) {
                FullTextSearchScore mappedScore = new FullTextSearchScore(name);
                if (composite == null) {
                    composite = mappedScore;
                } else {
                    composite = new ArithmeticOperand(composite, ArithmeticOperator.ADD, mappedScore);
                }
            }
            return composite;
        }
        if (operand instanceof Length) {
View Full Code Here

Examples of org.jboss.dna.graph.query.model.ArithmeticOperand

        protected ComparisonBuilder comparisonBuilder( DynamicOperand right ) {
            DynamicOperand leftOperand = null;
            // If the left operand is an arithmetic operand, then we need to check the operator precedence ...
            if (left instanceof ArithmeticOperand) {
                ArithmeticOperand leftArith = (ArithmeticOperand)left;
                ArithmeticOperator operator = leftArith.getOperator();
                if (this.operator.precedes(operator)) {
                    // Need to do create an operand with leftArith.right and right
                    DynamicOperand inner = new ArithmeticOperand(leftArith.getRight(), this.operator, right);
                    leftOperand = new ArithmeticOperand(leftArith.getLeft(), operator, inner);
                } else {
                    // the left preceds this, so we can add the new operand on top ...
                    leftOperand = new ArithmeticOperand(leftArith, operator, right);
                }
            } else {
                // The left isn't an arith ...
                leftOperand = new ArithmeticOperand(left, operator, right);
            }
            return new ComparisonBuilder(comparisonBuilder.constraintBuilder, leftOperand);
        }
View Full Code Here

Examples of org.jboss.dna.graph.query.model.ArithmeticOperand

        }
        if (arithmeticOperator != null) {
            if (tokens.matches('(')) {
                // Don't use precendence, but instead use the next DynamicOperand as the RHS ...
                DynamicOperand right = parseDynamicOperand(tokens, typeSystem, source);
                result = new ArithmeticOperand(result, arithmeticOperator, right);
            } else {
                // There is no parenthesis, so use operator precedence ...
                DynamicOperand right = parseDynamicOperand(tokens, typeSystem, source);
                if (right instanceof ArithmeticOperand) {
                    // But the RHS is an arithmetic operand, so we need to use operator precedence ...
                    ArithmeticOperand arithRhs = (ArithmeticOperand)right;
                    ArithmeticOperator rhsOperator = arithRhs.getOperator();
                    if (arithmeticOperator.precedes(rhsOperator)) {
                        // This operand's operator does take precedence, so this must be computed before working with the RHS ...
                        DynamicOperand newRhs = arithRhs.getRight();
                        DynamicOperand newLhs = new ArithmeticOperand(result, arithmeticOperator, arithRhs.getLeft());
                        result = new ArithmeticOperand(newLhs, rhsOperator, newRhs);
                    } else {
                        result = new ArithmeticOperand(result, arithmeticOperator, right);
                    }
                } else {
                    // The RHS is just another DynamicOperand ...
                    result = new ArithmeticOperand(result, arithmeticOperator, right);
                }
            }
        }
        return result;
    }
View Full Code Here

Examples of org.jboss.dna.graph.query.model.ArithmeticOperand

                    return tuple[index];
                }
            };
        }
        if (operand instanceof ArithmeticOperand) {
            ArithmeticOperand arith = (ArithmeticOperand)operand;
            final DynamicOperation leftOp = createDynamicOperation(typeSystem, schemata, columns, arith.getLeft());
            final DynamicOperation rightOp = createDynamicOperation(typeSystem, schemata, columns, arith.getRight());
            // compute the expected (common) type ...
            String leftType = leftOp.getExpectedType();
            String rightType = rightOp.getExpectedType();
            final String commonType = typeSystem.getCompatibleType(leftType, rightType);
            if (typeSystem.getDoubleFactory().getTypeName().equals(commonType)) {
                final TypeFactory<Double> commonTypeFactory = typeSystem.getDoubleFactory();
                switch (arith.getOperator()) {
                    case ADD:
                        return new DynamicOperation() {
                            public String getExpectedType() {
                                return commonType;
                            }

                            public Object evaluate( Object[] tuple ) {
                                Double right = commonTypeFactory.create(rightOp.evaluate(tuple));
                                Double left = commonTypeFactory.create(leftOp.evaluate(tuple));
                                if (right == null) return left;
                                if (left == null) return right;
                                return left.doubleValue() / right.doubleValue();
                            }
                        };
                    case SUBTRACT:
                        return new DynamicOperation() {
                            public String getExpectedType() {
                                return commonType;
                            }

                            public Object evaluate( Object[] tuple ) {
                                Double right = commonTypeFactory.create(rightOp.evaluate(tuple));
                                Double left = commonTypeFactory.create(leftOp.evaluate(tuple));
                                if (right == null) return left;
                                if (left == null) left = 0.0d;
                                return left.doubleValue() * right.doubleValue();
                            }
                        };
                    case MULTIPLY:
                        return new DynamicOperation() {
                            public String getExpectedType() {
                                return commonType;
                            }

                            public Object evaluate( Object[] tuple ) {
                                Double right = commonTypeFactory.create(rightOp.evaluate(tuple));
                                Double left = commonTypeFactory.create(leftOp.evaluate(tuple));
                                if (right == null || left == null) return null;
                                return left.doubleValue() * right.doubleValue();
                            }
                        };
                    case DIVIDE:
                        return new DynamicOperation() {
                            public String getExpectedType() {
                                return commonType;
                            }

                            public Object evaluate( Object[] tuple ) {
                                Double right = commonTypeFactory.create(rightOp.evaluate(tuple));
                                Double left = commonTypeFactory.create(leftOp.evaluate(tuple));
                                if (right == null || left == null) return null;
                                return left.doubleValue() / right.doubleValue();
                            }
                        };
                }
            } else if (typeSystem.getLongFactory().getTypeName().equals(commonType)) {
                final TypeFactory<Long> commonTypeFactory = typeSystem.getLongFactory();
                switch (arith.getOperator()) {
                    case ADD:
                        return new DynamicOperation() {
                            public String getExpectedType() {
                                return commonType;
                            }
View Full Code Here

Examples of org.modeshape.jcr.query.model.ArithmeticOperand

    protected DynamicOperand score( String... tableNames ) {
        DynamicOperand operand = null;
        for (String tableName : tableNames) {
            DynamicOperand right = new FullTextSearchScore(new SelectorName(tableName));
            if (operand == null) operand = right;
            else operand = new ArithmeticOperand(operand, ArithmeticOperator.ADD, right);
        }
        assert operand != null;
        return operand;
    }
View Full Code Here

Examples of org.modeshape.jcr.query.model.ArithmeticOperand

            } else {
                // There is no parenthesis, so use operator precedence ...
                DynamicOperand right = parseDynamicOperand(tokens, typeSystem, source);
                if (right instanceof ArithmeticOperand) {
                    // But the RHS is an arithmetic operand, so we need to use operator precedence ...
                    ArithmeticOperand arithRhs = (ArithmeticOperand)right;
                    ArithmeticOperator rhsOperator = arithRhs.operator();
                    if (arithmeticOperator.precedes(rhsOperator)) {
                        // This operand's operator does take precedence, so this must be computed before working with the RHS ...
                        DynamicOperand newRhs = arithRhs.getRight();
                        DynamicOperand newLhs = new ArithmeticOperand(result, arithmeticOperator, arithRhs.getLeft());
                        result = arithmeticOperand(newLhs, rhsOperator, newRhs);
                    } else {
                        result = arithmeticOperand(result, arithmeticOperator, right);
                    }
                } else {
View Full Code Here

Examples of org.modeshape.jcr.query.model.ArithmeticOperand

    }

    protected ArithmeticOperand arithmeticOperand( DynamicOperand leftOperand,
                                                   ArithmeticOperator operator,
                                                   DynamicOperand rightOperand ) {
        return new ArithmeticOperand(leftOperand, operator, rightOperand);
    }
View Full Code Here

Examples of org.modeshape.jcr.query.model.ArithmeticOperand

        }
        if (operand instanceof ReferenceValue) {
            return types.getStringFactory();
        }
        if (operand instanceof ArithmeticOperand) {
            ArithmeticOperand arith = (ArithmeticOperand)operand;
            TypeFactory<?> leftType = determineType(arith.getLeft(), context, columns);
            TypeFactory<?> rightType = determineType(arith.getRight(), context, columns);
            return types.getCompatibleType(leftType, rightType);
        }
        return types.getStringFactory();
    }
View Full Code Here

Examples of org.modeshape.jcr.query.model.ArithmeticOperand

                }
            };
        }
        if (operand instanceof ArithmeticOperand) {
            // This works on single-valued properties only ...
            ArithmeticOperand arith = (ArithmeticOperand)operand;
            final ExtractFromRow leftOp = createExtractFromRow(arith.getLeft(), context, columns, sources, defaultType, false,
                                                               false);
            final ExtractFromRow rightOp = createExtractFromRow(arith.getRight(), context, columns, sources, defaultType, false,
                                                                false);
            // compute the expected (common) type ...
            TypeFactory<?> leftType = leftOp.getType();
            TypeFactory<?> rightType = rightOp.getType();
            final TypeSystem typeSystem = context.getTypeSystem();
            final String commonType = typeSystem.getCompatibleType(leftType.getTypeName(), rightType.getTypeName());
            if (typeSystem.getDoubleFactory().getTypeName().equals(commonType)) {
                final TypeFactory<Double> commonTypeFactory = typeSystem.getDoubleFactory();
                switch (arith.operator()) {
                    case ADD:
                        return new ExtractFromRow() {
                            @Override
                            public TypeFactory<?> getType() {
                                return commonTypeFactory;
                            }

                            @Override
                            public Object getValueInRow( RowAccessor row ) {
                                Double right = commonTypeFactory.create(rightOp.getValueInRow(row));
                                Double left = commonTypeFactory.create(leftOp.getValueInRow(row));
                                if (right == null) return left;
                                if (left == null) return right;
                                return left.doubleValue() / right.doubleValue();
                            }

                            @Override
                            public String toString() {
                                return "(double + " + leftOp + "," + rightOp + ")";
                            }
                        };
                    case SUBTRACT:
                        return new ExtractFromRow() {
                            @Override
                            public TypeFactory<?> getType() {
                                return commonTypeFactory;
                            }

                            @Override
                            public Object getValueInRow( RowAccessor row ) {
                                Double right = commonTypeFactory.create(rightOp.getValueInRow(row));
                                Double left = commonTypeFactory.create(leftOp.getValueInRow(row));
                                if (right == null) return left;
                                if (left == null) left = 0.0d;
                                return left.doubleValue() * right.doubleValue();
                            }

                            @Override
                            public String toString() {
                                return "(double - " + leftOp + "," + rightOp + ")";
                            }
                        };
                    case MULTIPLY:
                        return new ExtractFromRow() {
                            @Override
                            public TypeFactory<?> getType() {
                                return commonTypeFactory;
                            }

                            @Override
                            public Object getValueInRow( RowAccessor row ) {
                                Double right = commonTypeFactory.create(rightOp.getValueInRow(row));
                                Double left = commonTypeFactory.create(leftOp.getValueInRow(row));
                                if (right == null || left == null) return null;
                                return left.doubleValue() * right.doubleValue();
                            }

                            @Override
                            public String toString() {
                                return "(double x " + leftOp + "," + rightOp + ")";
                            }
                        };
                    case DIVIDE:
                        return new ExtractFromRow() {
                            @Override
                            public TypeFactory<?> getType() {
                                return commonTypeFactory;
                            }

                            @Override
                            public Object getValueInRow( RowAccessor row ) {
                                Double right = commonTypeFactory.create(rightOp.getValueInRow(row));
                                Double left = commonTypeFactory.create(leftOp.getValueInRow(row));
                                if (right == null || left == null) return null;
                                return left.doubleValue() / right.doubleValue();
                            }

                            @Override
                            public String toString() {
                                return "(double / " + leftOp + "," + rightOp + ")";
                            }
                        };
                }
            } else if (typeSystem.getLongFactory().getTypeName().equals(commonType)) {
                final TypeFactory<Long> commonTypeFactory = typeSystem.getLongFactory();
                switch (arith.operator()) {
                    case ADD:
                        return new ExtractFromRow() {
                            @Override
                            public TypeFactory<?> getType() {
                                return commonTypeFactory;
View Full Code Here

Examples of org.modeshape.jcr.query.model.ArithmeticOperand

    public static DynamicOperand replaceViewReferences( QueryContext context,
                                                        DynamicOperand operand,
                                                        ColumnMapping mapping,
                                                        PlanNode node ) {
        if (operand instanceof ArithmeticOperand) {
            ArithmeticOperand arith = (ArithmeticOperand)operand;
            DynamicOperand newLeft = replaceViewReferences(context, arith.getLeft(), mapping, node);
            DynamicOperand newRight = replaceViewReferences(context, arith.getRight(), mapping, node);
            return new ArithmeticOperand(newLeft, arith.operator(), newRight);
        }
        if (operand instanceof FullTextSearchScore) {
            FullTextSearchScore score = (FullTextSearchScore)operand;
            if (!mapping.getOriginalName().equals(score.selectorName())) return score;
            if (mapping.isMappedToSingleSelector()) {
                return new FullTextSearchScore(mapping.getSingleMappedSelectorName());
            }
            // There are multiple mappings, so we have to create a composite score ...
            DynamicOperand composite = null;
            for (SelectorName name : mapping.getMappedSelectorNames()) {
                FullTextSearchScore mappedScore = new FullTextSearchScore(name);
                if (composite == null) {
                    composite = mappedScore;
                } else {
                    composite = new ArithmeticOperand(composite, ArithmeticOperator.ADD, mappedScore);
                }
            }
            return composite;
        }
        if (operand instanceof Length) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.