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_LessThan extends ExprNode implements Expr, ExprBoolean 28 { 29 Expr left ; 30 Expr right ; 31 32 private String printName = "lt" ; 33 private String opSymbol = "<" ; 34 35 Q_LessThan(int id) { super(id); } 36 37 Q_LessThan(RDQLParser p, int id) { super(p, id); } 38 39 public NodeValue eval(Query q, IndexValues env) 40 { 41 NodeValue x = left.eval(q, env) ; 42 NodeValue y = right.eval(q, env) ; 43 44 if ( ! x.isNumber() ) 45 throw new EvalTypeException("Q_LessThan: Wanted a numeric: "+x) ; 46 if ( ! y.isNumber() ) 47 throw new EvalTypeException("Q_LessThan: Wanted a numeric: "+y) ; 48 49 NodeValueSettable result ; 50 if ( x instanceof NodeValueSettable ) 51 result = (NodeValueSettable)x ; 52 else if ( y instanceof NodeValueSettable ) 53 result = (NodeValueSettable)y ; 54 else 55 result = new WorkingVar() ; 56 57 boolean b ; 58 59 if ( x.isInt() && y.isInt() ) 60 b = (x.getInt() < y.getInt()) ; 61 else 62 b = (x.getDouble() < y.getDouble()) ; 63 64 result.setBoolean(b) ; 65 return result ; 66 } 67 68 public void jjtClose() 69 { 70 int n = jjtGetNumChildren() ; 71 if ( n != 2 ) 72 throw new QueryException("Q_LessThan: Wrong number of children: "+n) ; 73 74 left = (Expr)jjtGetChild(0) ; 75 right = (Expr)jjtGetChild(1) ; 76 } 77 78 81 public boolean isApply() { return true ; } 82 public String getFun() { return super.constructURI(this.getClass().getName()) ; } 83 public int argCount() { return 2; } 84 public Expression getArg(int i) 85 { 86 if ( i == 0 && left instanceof Expression ) 87 return (Expression)left ; 88 if ( i == 1 && right instanceof Expression ) 89 return (Expression)right ; 90 return null; 91 } 92 93 public String asInfixString() 94 { 95 return QueryPrintUtils.asInfixString2(left, right, printName, opSymbol) ; 96 } 97 98 public String asPrefixString() 99 { 100 return QueryPrintUtils.asPrefixString(left, right, printName, opSymbol) ; 101 } 102 103 public void print(PrintWriter pw, int level) 104 { 105 QueryPrintUtils.print(pw, left, right, printName, opSymbol, level) ; 106 } 107 108 public String toString() 109 { 110 return asInfixString() ; 111 } 112 } 113 114 140 | Popular Tags |