KickJava   Java API By Example, From Geeks To Geeks.

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


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 = Subtract
17  * Operator = -
18  * Print Name = sub
19  * Template = ExprNumericBLANK2.java
20  */

21
22 /**
23  * @author Automatically generated class: Operator: Subtract
24  * @version $Id: Q_Subtract.java,v 1.9 2005/02/21 12:15:51 andy_seaborne Exp $
25  */

26
27 public class Q_Subtract extends ExprNode implements Expr, ExprNumeric
28 {
29     Expr left ;
30     Expr right ;
31
32     private String JavaDoc printName = "sub" ;
33     private String JavaDoc opSymbol = "-" ;
34
35     Q_Subtract(int id) { super(id); }
36
37     Q_Subtract(RDQLParser p, int id) { super(p, id); }
38
39     public NodeValue eval(Query q, IndexValues env)
40     {
41         //int n = jjtGetNumChildren() ;
42

43         NodeValue x = left.eval(q, env) ;
44         NodeValue y = right.eval(q, env) ;
45
46         if ( ! x.isNumber() )
47             throw new EvalTypeException("Q_Subtract: Wanted a number: "+x) ;
48         if ( ! y.isNumber() )
49             throw new EvalTypeException("Q_Subtract: 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             result.setDouble(x.getDouble() - y.getDouble()) ;
63
64         return result ;
65     }
66
67     // Could do some checking that children are numeric
68
// Could collapse constant expressions
69

70     public void jjtClose()
71     {
72         int n = jjtGetNumChildren() ;
73         if ( n != 2 )
74             throw new QueryException("Q_Subtract: Wrong number of children: "+n) ;
75         
76         left = (Expr)jjtGetChild(0) ;
77         right = (Expr)jjtGetChild(1) ;
78     }
79
80     // -----------
81
// graph.query.Expression
82

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

142
Popular Tags