KickJava   Java API By Example, From Geeks To Geeks.

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


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

5
6 /* Generated By:JJTree: Do not edit this line. Q_UnaryMinus.java */
7
8 package com.hp.hpl.jena.rdql.parser;
9
10
11 import java.io.PrintWriter JavaDoc ;
12 import com.hp.hpl.jena.graph.query.IndexValues;
13 import com.hp.hpl.jena.graph.query.Expression ;
14 import com.hp.hpl.jena.rdql.*;
15
16 public class Q_UnaryMinus extends ExprNode implements ExprNumeric
17 {
18     Expr expr ;
19     private String JavaDoc printName = "unaryminus" ;
20     private String JavaDoc opSymbol = "-" ;
21
22     Q_UnaryMinus(int id) { super(id); }
23
24     Q_UnaryMinus(RDQLParser p, int id) { super(p, id); }
25
26     public NodeValue eval(Query q, IndexValues env)
27     {
28         NodeValue v = expr.eval(q, env) ;
29
30         if ( ! v.isNumber() )
31             throw new EvalTypeException("Q_UnaryMinus: Wanted a number: got "+expr) ;
32
33         NodeValueSettable result ;
34         /* Further work needed : what is a variable name
35          * bound to so that it does not get over written?
36         if ( v instanceof Settable )
37             result = (Settable)v ;
38         else
39         */

40             result = new WorkingVar() ;
41
42         if ( v.isInt() )
43             result.setInt( - v.getInt() ) ;
44         else
45             result.setDouble( - v.getDouble() ) ;
46
47         return result ;
48     }
49
50     public void jjtClose()
51     {
52         int n = jjtGetNumChildren() ;
53         if ( n != 1 )
54             throw new QueryException("Q_UnaryMinus: Wrong number of children: "+n) ;
55         expr = (Expr)jjtGetChild(0) ;
56     }
57
58     // -----------
59
// graph.query.Expression
60

61     public boolean isApply() { return true ; }
62     public String JavaDoc getFun() { return super.constructURI(this.getClass().getName()) ; }
63     public int argCount() { return 1; }
64     public Expression getArg(int i)
65     {
66         if ( i == 0 && expr instanceof Expression )
67             return (Expression)expr ;
68         return null;
69     }
70
71     public String JavaDoc asInfixString() { return QueryPrintUtils.asInfixString1(expr, printName, opSymbol) ; }
72
73     public String JavaDoc asPrefixString() { return QueryPrintUtils.asPrefixString(expr, null, printName, opSymbol) ; }
74
75     public void print(PrintWriter JavaDoc pw, int level) { QueryPrintUtils.print(pw, expr, null, printName, opSymbol, level) ; }
76
77     public String JavaDoc toString() { return asInfixString() ; }
78 }
79
80 /*
81  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
82  * All rights reserved.
83  *
84  * Redistribution and use in source and binary forms, with or without
85  * modification, are permitted provided that the following conditions
86  * are met:
87  * 1. Redistributions of source code must retain the above copyright
88  * notice, this list of conditions and the following disclaimer.
89  * 2. Redistributions in binary form must reproduce the above copyright
90  * notice, this list of conditions and the following disclaimer in the
91  * documentation and/or other materials provided with the distribution.
92  * 3. The name of the author may not be used to endorse or promote products
93  * derived from this software without specific prior written permission.
94  *
95  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
96  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
97  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
98  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
99  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
100  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
101  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
102  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
103  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
104  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
105  */

106
Popular Tags