KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > store > IntegerLiteral


1 /*
2  * Copyright 2002 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: IntegerLiteral.java,v 1.3 2003/08/04 16:40:35 pierreg0 Exp $
9  */

10
11 package com.triactive.jdo.store;
12
13 import java.math.BigInteger JavaDoc;
14
15
16 class IntegerLiteral extends NumericExpression
17 {
18     private final BigInteger JavaDoc value;
19
20     public IntegerLiteral(QueryStatement qs, BigInteger JavaDoc value)
21     {
22         super(qs);
23
24         this.value = value;
25         st.append(value);
26     }
27
28     public BigInteger JavaDoc getValue()
29     {
30         return value;
31     }
32
33     public BooleanExpression eq(SQLExpression expr)
34     {
35         if (expr instanceof IntegerLiteral)
36             return new BooleanLiteral(qs, value.compareTo(((IntegerLiteral)expr).value) == 0);
37         else
38             return super.eq(expr);
39     }
40
41     public BooleanExpression noteq(SQLExpression expr)
42     {
43         if (expr instanceof IntegerLiteral)
44             return new BooleanLiteral(qs, value.compareTo(((IntegerLiteral)expr).value) != 0);
45         else
46             return super.noteq(expr);
47     }
48
49     public BooleanExpression lt(SQLExpression expr)
50     {
51         if (expr instanceof IntegerLiteral)
52             return new BooleanLiteral(qs, value.compareTo(((IntegerLiteral)expr).value) < 0);
53         else
54             return super.lt(expr);
55     }
56
57     public BooleanExpression lteq(SQLExpression expr)
58     {
59         if (expr instanceof IntegerLiteral)
60             return new BooleanLiteral(qs, value.compareTo(((IntegerLiteral)expr).value) <= 0);
61         else if (expr instanceof IndexOfExpression)
62             return expr.gteq(this);
63         else
64             return super.lteq(expr);
65     }
66
67     public BooleanExpression gt(SQLExpression expr)
68     {
69         if (expr instanceof IntegerLiteral)
70             return new BooleanLiteral(qs, value.compareTo(((IntegerLiteral)expr).value) > 0);
71         else
72             return super.gt(expr);
73     }
74
75     public BooleanExpression gteq(SQLExpression expr)
76     {
77         if (expr instanceof IntegerLiteral)
78             return new BooleanLiteral(qs, value.compareTo(((IntegerLiteral)expr).value) >= 0);
79         else
80             return super.gteq(expr);
81     }
82
83     public SQLExpression add(SQLExpression expr)
84     {
85         if (expr instanceof IntegerLiteral)
86             return new IntegerLiteral(qs, value.add(((IntegerLiteral)expr).value));
87         else
88             return super.add(expr);
89     }
90
91     public SQLExpression sub(SQLExpression expr)
92     {
93         if (expr instanceof IntegerLiteral)
94             return new IntegerLiteral(qs, value.subtract(((IntegerLiteral)expr).value));
95         else
96             return super.sub(expr);
97     }
98
99     public SQLExpression mul(SQLExpression expr)
100     {
101         if (expr instanceof IntegerLiteral)
102             return new IntegerLiteral(qs, value.multiply(((IntegerLiteral)expr).value));
103         else
104             return super.mul(expr);
105     }
106
107     public SQLExpression div(SQLExpression expr)
108     {
109         if (expr instanceof IntegerLiteral)
110             return new IntegerLiteral(qs, value.divide(((IntegerLiteral)expr).value));
111         else
112             return super.div(expr);
113     }
114
115     public SQLExpression mod(SQLExpression expr)
116     {
117         if (expr instanceof IntegerLiteral)
118             return new IntegerLiteral(qs, value.mod(((IntegerLiteral)expr).value));
119         else
120             return super.mod(expr);
121     }
122
123     public SQLExpression neg()
124     {
125         return new IntegerLiteral(qs, value.negate());
126     }
127 }
128
Popular Tags