KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > filter > etcl > NumberValue


1 package org.jacorb.notification.filter.etcl;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-2004 Gerald Brose
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */

23
24 import org.jacorb.notification.filter.EvaluationContext;
25 import org.jacorb.notification.filter.EvaluationResult;
26
27 import antlr.Token;
28
29 /**
30  * A simple node to represent a Number
31  *
32  * @version $Id: NumberValue.java,v 1.4 2005/02/14 00:07:08 alphonse.bendt Exp $
33  */

34
35 public class NumberValue extends AbstractTCLNode
36 {
37
38     private Double JavaDoc number_;
39
40     private EvaluationResult result_;
41
42     public Double JavaDoc getNumber()
43     {
44         return number_;
45     }
46
47     public NumberValue(Token tok)
48     {
49         super(tok);
50
51         setName("NumberValue");
52         
53         EvaluationResult _r = new EvaluationResult();
54         number_ = new Double JavaDoc(tok.getText());
55
56         int t = getType();
57
58         switch (t) {
59         case NUMBER:
60             _r.setLong(number_);
61             break;
62         case NUM_FLOAT:
63             _r.setFloat(number_);
64             break;
65         default:
66             throw new RuntimeException JavaDoc();
67         }
68
69         result_ = EvaluationResult.wrapImmutable(_r);
70     }
71
72     public EvaluationResult evaluate(EvaluationContext context)
73     {
74         return result_;
75     }
76
77     public String JavaDoc toString()
78     {
79         switch (getType()) {
80         case NUM_FLOAT:
81             return "" + number_.floatValue();
82         default:
83             return "" + number_.longValue();
84         }
85     }
86
87     public boolean isStatic()
88     {
89         return true;
90     }
91
92     public boolean isNumber()
93     {
94         return true;
95     }
96
97     public void acceptInOrder(AbstractTCLVisitor visitor) throws VisitorException
98     {
99         visitor.visitNumber(this);
100     }
101
102     public void acceptPostOrder(AbstractTCLVisitor visitor) throws VisitorException
103     {
104         visitor.visitNumber(this);
105     }
106
107     public void acceptPreOrder(AbstractTCLVisitor visitor) throws VisitorException
108     {
109         visitor.visitNumber(this);
110     }
111 }
Popular Tags