KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > proguard > evaluation > value > SpecificLongValue


1 /*
2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
3  * of Java bytecode.
4  *
5  * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the Free
9  * Software Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15  * more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21 package proguard.evaluation.value;
22
23 /**
24  * This LongValue represents a specific long value.
25  *
26  * @author Eric Lafortune
27  */

28 class SpecificLongValue extends LongValue
29 {
30     private long value;
31
32
33     /**
34      * Creates a new specific long value.
35      */

36     public SpecificLongValue(long value)
37     {
38         this.value = value;
39     }
40
41
42     // Implementations for LongValue.
43

44     public long value()
45     {
46         return value;
47     }
48
49
50     // Implementations of binary methods of LongValue.
51

52     // Perhaps the other value arguments are more specific than apparent
53
// in these methods, so delegate to them.
54

55     public LongValue generalize(LongValue other)
56     {
57         return other.generalize(this);
58     }
59
60     public LongValue add(LongValue other)
61     {
62         return other.add(this);
63     }
64
65     public LongValue subtract(LongValue other)
66     {
67         return other.subtractFrom(this);
68     }
69
70     public LongValue subtractFrom(LongValue other)
71     {
72         return other.subtract(this);
73     }
74
75     public LongValue multiply(LongValue other)
76     {
77         return other.multiply(this);
78     }
79
80     public LongValue divide(LongValue other)
81     {
82         return other.divideOf(this);
83     }
84
85     public LongValue divideOf(LongValue other)
86     {
87         return other.divide(this);
88     }
89
90     public LongValue remainder(LongValue other)
91     {
92         return other.remainderOf(this);
93     }
94
95     public LongValue remainderOf(LongValue other)
96     {
97         return other.remainder(this);
98     }
99
100     public LongValue shiftLeft(IntegerValue other)
101     {
102         return other.shiftLeftOf(this);
103     }
104
105     public LongValue shiftRight(IntegerValue other)
106     {
107         return other.shiftRightOf(this);
108     }
109
110     public LongValue unsignedShiftRight(IntegerValue other)
111     {
112         return other.unsignedShiftRightOf(this);
113     }
114
115     public LongValue and(LongValue other)
116     {
117         return other.and(this);
118     }
119
120     public LongValue or(LongValue other)
121     {
122         return other.or(this);
123     }
124
125     public LongValue xor(LongValue other)
126     {
127         return other.xor(this);
128     }
129
130     public IntegerValue compare(LongValue other, ValueFactory valueFactory)
131     {
132         return other.compareReverse(this, valueFactory);
133     }
134
135
136     // Implementations of unary methods of LongValue.
137

138     public LongValue negate()
139     {
140         return new SpecificLongValue(-value);
141     }
142
143     public IntegerValue convertToInteger(ValueFactory valueFactory)
144     {
145         return valueFactory.createIntegerValue((int)value);
146     }
147
148     public FloatValue convertToFloat(ValueFactory valueFactory)
149     {
150         return valueFactory.createFloatValue((float)value);
151     }
152
153     public DoubleValue convertToDouble(ValueFactory valueFactory)
154     {
155         return valueFactory.createDoubleValue((double)value);
156     }
157
158
159     // Implementations of binary LongValue methods with SpecificLongValue
160
// arguments.
161

162     public LongValue generalize(SpecificLongValue other)
163     {
164         return this.value == other.value ? this : ValueFactory.LONG_VALUE;
165     }
166
167     public LongValue add(SpecificLongValue other)
168     {
169         return new SpecificLongValue(this.value + other.value);
170     }
171
172     public LongValue subtract(SpecificLongValue other)
173     {
174         return new SpecificLongValue(this.value - other.value);
175     }
176
177     public LongValue subtractFrom(SpecificLongValue other)
178     {
179         return new SpecificLongValue(other.value - this.value);
180     }
181
182     public LongValue multiply(SpecificLongValue other)
183     {
184         return new SpecificLongValue(this.value * other.value);
185     }
186
187     public LongValue divide(SpecificLongValue other)
188     {
189         return new SpecificLongValue(this.value / other.value);
190     }
191
192     public LongValue divideOf(SpecificLongValue other)
193     {
194         return new SpecificLongValue(other.value / this.value);
195     }
196
197     public LongValue remainder(SpecificLongValue other)
198     {
199         return new SpecificLongValue(this.value % other.value);
200     }
201
202     public LongValue remainderOf(SpecificLongValue other)
203     {
204         return new SpecificLongValue(other.value % this.value);
205     }
206
207     public LongValue shiftLeft(SpecificIntegerValue other)
208     {
209         return new SpecificLongValue(this.value << other.value());
210     }
211
212     public LongValue shiftRight(SpecificIntegerValue other)
213     {
214         return new SpecificLongValue(this.value >> other.value());
215     }
216
217     public LongValue unsignedShiftRight(SpecificIntegerValue other)
218     {
219         return new SpecificLongValue(this.value >>> other.value());
220     }
221
222     public LongValue and(SpecificLongValue other)
223     {
224         return new SpecificLongValue(this.value & other.value);
225     }
226
227     public LongValue or(SpecificLongValue other)
228     {
229         return new SpecificLongValue(this.value | other.value);
230     }
231
232     public LongValue xor(SpecificLongValue other)
233     {
234         return new SpecificLongValue(this.value ^ other.value);
235     }
236
237     public IntegerValue compare(SpecificLongValue other, ValueFactory valueFactory)
238     {
239         return this.value < other.value ? valueFactory.createIntegerValue(-1) :
240                this.value == other.value ? valueFactory.createIntegerValue(0) :
241                                            valueFactory.createIntegerValue(1);
242     }
243
244
245     // Implementations for Value.
246

247     public boolean isSpecific()
248     {
249         return true;
250     }
251
252
253     // Implementations for Object.
254

255     public boolean equals(Object JavaDoc object)
256     {
257         return object != null &&
258                this.getClass() == object.getClass() &&
259                this.value == ((SpecificLongValue)object).value;
260     }
261
262
263     public int hashCode()
264     {
265         return this.getClass().hashCode() ^ (int)value;
266     }
267
268
269     public String JavaDoc toString()
270     {
271         return "l:"+value;
272     }
273 }
274
Popular Tags