1 5 6 package com.hp.hpl.jena.rdql.parser; 7 8 9 import java.io.PrintWriter ; 10 import com.hp.hpl.jena.graph.query.IndexValues; 11 import com.hp.hpl.jena.graph.query.Expression ; 12 import com.hp.hpl.jena.rdql.*; 13 14 21 22 26 27 public class Q_RightUnsignedShift extends ExprNode implements Expr, ExprNumeric 28 { 29 Expr left ; 30 Expr right ; 31 32 private String printName = "rshiftz" ; 33 private String opSymbol = ">>>" ; 34 35 Q_RightUnsignedShift(int id) { super(id); } 36 37 Q_RightUnsignedShift(RDQLParser p, int id) { super(p, id); } 38 39 public NodeValue eval(Query q, IndexValues env) 40 { 41 43 NodeValue x = left.eval(q, env) ; 44 NodeValue y = right.eval(q, env) ; 45 46 if ( ! x.isNumber() ) 47 throw new EvalTypeException("Q_RightUnsignedShift: Wanted a number: "+x) ; 48 if ( ! y.isNumber() ) 49 throw new EvalTypeException("Q_RightUnsignedShift: Wanted a number: "+y) ; 50 51 NodeValueSettable result ; 52 if ( x instanceof NodeValueSettable ) 53 result = (NodeValueSettable)x ; 54 else if ( y instanceof NodeValueSettable ) 55 result = (NodeValueSettable)y ; 56 else 57 result = new WorkingVar() ; 58 59 if ( x.isInt() && y.isInt() ) 60 result.setInt(x.getInt() >>> y.getInt()) ; 61 else 62 throw new EvalTypeException("Q_RightUnsignedShift: one or both operands are doubles: "+x+" >>> "+y) ; 63 64 return result ; 65 } 66 67 70 public void jjtClose() 71 { 72 int n = jjtGetNumChildren() ; 73 if ( n != 2 ) 74 throw new QueryException("Q_RightUnsignedShift: Wrong number of children: "+n) ; 75 76 left = (Expr)jjtGetChild(0) ; 77 right = (Expr)jjtGetChild(1) ; 78 } 79 80 83 public boolean isApply() { return true ; } 84 public String getFun() { return super.constructURI(this.getClass().getName()) ; } 85 public int argCount() { return 2; } 86 public Expression getArg(int i) 87 { 88 if ( i == 0 && left instanceof Expression ) 89 return (Expression)left ; 90 if ( i == 1 && right instanceof Expression ) 91 return (Expression)right ; 92 return null; 93 } 94 95 public String asInfixString() 96 { 97 return QueryPrintUtils.asInfixString2(left, right, printName, opSymbol) ; 98 } 99 100 public String asPrefixString() 101 { 102 return QueryPrintUtils.asPrefixString(left, right, printName, opSymbol) ; 103 } 104 105 public void print(PrintWriter pw, int level) 106 { 107 QueryPrintUtils.print(pw, left, right, printName, opSymbol, level) ; 108 } 109 110 public String toString() 111 { 112 return asInfixString() ; 113 } 114 } 115 116 142 | Popular Tags |