1 /* 2 * ModeShape (http://www.modeshape.org) 3 * See the COPYRIGHT.txt file distributed with this work for information 4 * regarding copyright ownership. Some portions may be licensed 5 * to Red Hat, Inc. under one or more contributor license agreements. 6 * See the AUTHORS.txt file in the distribution for a full listing of 7 * individual contributors. 8 * 9 * ModeShape is free software. Unless otherwise indicated, all code in ModeShape 10 * is licensed to you under the terms of the GNU Lesser General Public License as 11 * published by the Free Software Foundation; either version 2.1 of 12 * the License, or (at your option) any later version. 13 * 14 * ModeShape is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with this software; if not, write to the Free 21 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 22 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 23 */ 24 package org.modeshape.jcr.query.qom; 25 26 import javax.jcr.query.qom.DynamicOperand; 27 import org.modeshape.graph.query.model.ArithmeticOperand; 28 import org.modeshape.graph.query.model.ArithmeticOperator; 29 import org.modeshape.jcr.api.query.qom.QueryObjectModelConstants; 30 31 /** 32 * 33 */ 34 public class JcrArithmeticOperand extends ArithmeticOperand 35 implements org.modeshape.jcr.api.query.qom.ArithmeticOperand, JcrDynamicOperand { 36 37 private static final long serialVersionUID = 1L; 38 39 /** 40 * Create a arithmetic dynamic operand that operates upon the supplied operand(s). 41 * 42 * @param left the left-hand-side operand 43 * @param operator the arithmetic operator; may not be null 44 * @param right the right-hand-side operand 45 * @throws IllegalArgumentException if any of the arguments is null 46 */ 47 public JcrArithmeticOperand( JcrDynamicOperand left, 48 ArithmeticOperator operator, 49 JcrDynamicOperand right ) { 50 super(left, operator, right); 51 52 } 53 54 /** 55 * {@inheritDoc} 56 * 57 * @see org.modeshape.graph.query.model.ArithmeticOperand#left() 58 */ 59 @Override 60 public JcrDynamicOperand left() { 61 return (JcrDynamicOperand)super.left(); 62 } 63 64 /** 65 * {@inheritDoc} 66 * 67 * @see org.modeshape.graph.query.model.ArithmeticOperand#right() 68 */ 69 @Override 70 public JcrDynamicOperand right() { 71 return (JcrDynamicOperand)super.right(); 72 } 73 74 /** 75 * {@inheritDoc} 76 * 77 * @see org.modeshape.jcr.api.query.qom.ArithmeticOperand#getLeft() 78 */ 79 @Override 80 public DynamicOperand getLeft() { 81 return left(); 82 } 83 84 /** 85 * {@inheritDoc} 86 * 87 * @see org.modeshape.jcr.api.query.qom.ArithmeticOperand#getRight() 88 */ 89 @Override 90 public DynamicOperand getRight() { 91 return right(); 92 } 93 94 /** 95 * {@inheritDoc} 96 * 97 * @see org.modeshape.jcr.api.query.qom.ArithmeticOperand#getOperator() 98 */ 99 @Override 100 public String getOperator() { 101 switch (operator()) { 102 case ADD: 103 return QueryObjectModelConstants.JCR_ARITHMETIC_OPERATOR_ADD; 104 case DIVIDE: 105 return QueryObjectModelConstants.JCR_ARITHMETIC_OPERATOR_DIVIDE; 106 case MULTIPLY: 107 return QueryObjectModelConstants.JCR_ARITHMETIC_OPERATOR_MULTIPLY; 108 case SUBTRACT: 109 return QueryObjectModelConstants.JCR_ARITHMETIC_OPERATOR_SUBTRACT; 110 } 111 assert false; 112 return null; 113 } 114 115 }