KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdql > parser > Q_LessThanOrEqual


1 /*
2  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6 package com.hp.hpl.jena.rdql.parser;
7
8
9 import java.io.PrintWriter JavaDoc;
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 /* This file is automatically generated - do not edit.
15  * Arguments:
16  * Name = LessThanOrEqual
17  * Operator = <=
18  * Print Name = le
19  * Template = ExprBooleanNumericBLANK2.java
20  */

21
22 /**
23  * @author Automatically generated class: Operator: LessThanOrEqual
24  * @version $Id: Q_LessThanOrEqual.java,v 1.8 2005/02/21 12:15:44 andy_seaborne Exp $
25  */

26
27 public class Q_LessThanOrEqual extends ExprNode implements Expr, ExprBoolean
28 {
29     Expr left ;
30     Expr right ;
31
32     private String JavaDoc printName = "le" ;
33     private String JavaDoc opSymbol = "<=" ;
34
35     Q_LessThanOrEqual(int id) { super(id); }
36
37     Q_LessThanOrEqual(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_LessThanOrEqual: Wanted a numeric: "+x) ;
46         if ( ! y.isNumber() )
47             throw new EvalTypeException("Q_LessThanOrEqual: 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_LessThanOrEqual: Wrong number of children: "+n) ;
73         
74         left = (Expr)jjtGetChild(0) ;
75         right = (Expr)jjtGetChild(1) ;
76     }
77
78     // -----------
79
// graph.query.Expression
80

81     public boolean isApply() { return true ; }
82     public String JavaDoc 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 JavaDoc asInfixString()
94     {
95         return QueryPrintUtils.asInfixString2(left, right, printName, opSymbol) ;
96     }
97
98     public String JavaDoc asPrefixString()
99     {
100         return QueryPrintUtils.asPrefixString(left, right, printName, opSymbol) ;
101     }
102
103     public void print(PrintWriter JavaDoc pw, int level)
104     {
105         QueryPrintUtils.print(pw, left, right, printName, opSymbol, level) ;
106     }
107
108     public String JavaDoc toString()
109     {
110         return asInfixString() ;
111     }
112 }
113
114 /*
115  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
116  * All rights reserved.
117  *
118  * Redistribution and use in source and binary forms, with or without
119  * modification, are permitted provided that the following conditions
120  * are met:
121  * 1. Redistributions of source code must retain the above copyright
122  * notice, this list of conditions and the following disclaimer.
123  * 2. Redistributions in binary form must reproduce the above copyright
124  * notice, this list of conditions and the following disclaimer in the
125  * documentation and/or other materials provided with the distribution.
126  * 3. The name of the author may not be used to endorse or promote products
127  * derived from this software without specific prior written permission.
128  *
129  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
130  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
131  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
132  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
133  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
134  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
135  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
136  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
137  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
138  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
139  */

140
Popular Tags