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.rdql.*; 12 13 20 21 25 26 public class Q_GreaterThanOrEqual extends ExprNode implements Expr, ExprBoolean 27 { 28 Expr left ; 29 Expr right ; 30 31 private String printName = "ge" ; 32 private String opSymbol = ">=" ; 33 34 Q_GreaterThanOrEqual(int id) { super(id); } 35 36 Q_GreaterThanOrEqual(RDQLParser p, int id) { super(p, id); } 37 38 public NodeValue eval(Query q, IndexValues env) 39 { 40 NodeValue x = left.eval(q, env) ; 41 NodeValue y = right.eval(q, env) ; 42 43 if ( ! x.isNumber() ) 44 throw new EvalTypeException("Q_GreaterThanOrEqual: Wanted a numeric: "+x) ; 45 if ( ! y.isNumber() ) 46 throw new EvalTypeException("Q_GreaterThanOrEqual: Wanted a numeric: "+y) ; 47 48 NodeValueSettable result ; 49 if ( x instanceof NodeValueSettable ) 50 result = (NodeValueSettable)x ; 51 else if ( y instanceof NodeValueSettable ) 52 result = (NodeValueSettable)y ; 53 else 54 result = new WorkingVar() ; 55 56 boolean b ; 57 58 if ( x.isInt() && y.isInt() ) 59 b = (x.getInt() >= y.getInt()) ; 60 else 61 b = (x.getDouble() >= y.getDouble()) ; 62 63 result.setBoolean(b) ; 64 return result ; 65 } 66 67 public void jjtClose() 68 { 69 int n = jjtGetNumChildren() ; 70 if ( n != 2 ) 71 throw new QueryException("Q_GreaterThanOrEqual: Wrong number of children: "+n) ; 72 73 left = (Expr)jjtGetChild(0) ; 74 right = (Expr)jjtGetChild(1) ; 75 } 76 77 public String asInfixString() 78 { 79 return QueryPrintUtils.asInfixString2(left, right, printName, opSymbol) ; 80 } 81 82 public String asPrefixString() 83 { 84 return QueryPrintUtils.asPrefixString(left, right, printName, opSymbol) ; 85 } 86 87 public void print(PrintWriter pw, int level) 88 { 89 QueryPrintUtils.print(pw, left, right, printName, opSymbol, level) ; 90 } 91 92 public String toString() 93 { 94 return asInfixString() ; 95 } 96 } 97 98 124 | Popular Tags |