KickJava   Java API By Example, From Geeks To Geeks.

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


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 IntegerValue represents a specific integer value.
25  *
26  * @author Eric Lafortune
27  */

28 class SpecificIntegerValue extends IntegerValue
29 {
30     private int value;
31
32
33     public SpecificIntegerValue(int value)
34     {
35         this.value = value;
36     }
37
38
39     // Implementations for IntegerValue.
40

41     public int value()
42     {
43         return value;
44     }
45
46
47     // Implementations of binary methods of IntegerValue.
48

49     // Perhaps the other value arguments are more specific than apparent
50
// in these methods, so delegate to them.
51

52     public IntegerValue generalize(IntegerValue other)
53     {
54         return other.generalize(this);
55     }
56
57     public IntegerValue add(IntegerValue other)
58     {
59         return other.add(this);
60     }
61
62     public IntegerValue subtract(IntegerValue other)
63     {
64         return other.subtractFrom(this);
65     }
66
67     public IntegerValue subtractFrom(IntegerValue other)
68     {
69         return other.subtract(this);
70     }
71
72     public IntegerValue multiply(IntegerValue other)
73     {
74         return other.multiply(this);
75     }
76
77     public IntegerValue divide(IntegerValue other)
78     throws ArithmeticException JavaDoc
79     {
80         return other.divideOf(this);
81     }
82
83     public IntegerValue divideOf(IntegerValue other)
84     throws ArithmeticException JavaDoc
85     {
86         return other.divide(this);
87     }
88
89     public IntegerValue remainder(IntegerValue other)
90     throws ArithmeticException JavaDoc
91     {
92         return other.remainderOf(this);
93     }
94
95     public IntegerValue remainderOf(IntegerValue other)
96     throws ArithmeticException JavaDoc
97     {
98         return other.remainder(this);
99     }
100
101     public IntegerValue shiftLeft(IntegerValue other)
102     {
103         return other.shiftLeftOf(this);
104     }
105
106     public IntegerValue shiftLeftOf(IntegerValue other)
107     {
108         return other.shiftLeft(this);
109     }
110
111     public IntegerValue shiftRight(IntegerValue other)
112     {
113         return other.shiftRightOf(this);
114     }
115
116     public IntegerValue shiftRightOf(IntegerValue other)
117     {
118         return other.shiftRight(this);
119     }
120
121     public IntegerValue unsignedShiftRight(IntegerValue other)
122     {
123         return other.unsignedShiftRightOf(this);
124     }
125
126     public IntegerValue unsignedShiftRightOf(IntegerValue other)
127     {
128         return other.unsignedShiftRight(this);
129     }
130
131     public LongValue shiftLeftOf(LongValue other)
132     {
133         return other.shiftLeft(this);
134     }
135
136     public LongValue shiftRightOf(LongValue other)
137     {
138         return other.shiftRight(this);
139     }
140
141     public LongValue unsignedShiftRightOf(LongValue other)
142     {
143         return other.unsignedShiftRight(this);
144     }
145
146     public IntegerValue and(IntegerValue other)
147     {
148         return other.and(this);
149     }
150
151     public IntegerValue or(IntegerValue other)
152     {
153         return other.or(this);
154     }
155
156     public IntegerValue xor(IntegerValue other)
157     {
158         return other.xor(this);
159     }
160
161     public int equal(IntegerValue other)
162     {
163         return other.equal(this);
164     }
165
166     public int lessThan(IntegerValue other)
167     {
168         return other.greaterThan(this);
169     }
170
171     public int lessThanOrEqual(IntegerValue other)
172     {
173         return other.greaterThanOrEqual(this);
174     }
175
176
177     // Implementations of unary methods of IntegerValue.
178

179     public IntegerValue negate()
180     {
181         return new SpecificIntegerValue(-value);
182     }
183
184     public IntegerValue convertToByte(ValueFactory valueFactory)
185     {
186         int byteValue = (byte)value;
187
188         return byteValue == value ?
189             this :
190             new SpecificIntegerValue(byteValue);
191     }
192
193     public IntegerValue convertToCharacter(ValueFactory valueFactory)
194     {
195         int charValue = (char)value;
196
197         return charValue == value ?
198             this :
199             new SpecificIntegerValue(charValue);
200     }
201
202     public IntegerValue convertToShort(ValueFactory valueFactory)
203     {
204         int shortValue = (short)value;
205
206         return shortValue == value ?
207             this :
208             new SpecificIntegerValue(shortValue);
209     }
210
211     public IntegerValue convertToInteger(ValueFactory valueFactory)
212     {
213         return this;
214     }
215
216     public LongValue convertToLong(ValueFactory valueFactory)
217     {
218         return valueFactory.createLongValue((long)value);
219     }
220
221     public FloatValue convertToFloat(ValueFactory valueFactory)
222     {
223         return valueFactory.createFloatValue((float)value);
224     }
225
226     public DoubleValue convertToDouble(ValueFactory valueFactory)
227     {
228         return valueFactory.createDoubleValue((double)value);
229     }
230
231
232     // Implementations of binary IntegerValue methods with SpecificIntegerValue
233
// arguments.
234

235     public IntegerValue generalize(SpecificIntegerValue other)
236     {
237         return this.value == other.value ? this : ValueFactory.INTEGER_VALUE;
238     }
239
240     public IntegerValue add(SpecificIntegerValue other)
241     {
242         return new SpecificIntegerValue(this.value + other.value);
243     }
244
245     public IntegerValue subtract(SpecificIntegerValue other)
246     {
247         return new SpecificIntegerValue(this.value - other.value);
248     }
249
250     public IntegerValue subtractFrom(SpecificIntegerValue other)
251     {
252         return new SpecificIntegerValue(other.value - this.value);
253     }
254
255     public IntegerValue multiply(SpecificIntegerValue other)
256     {
257         return new SpecificIntegerValue(this.value * other.value);
258     }
259
260     public IntegerValue divide(SpecificIntegerValue other)
261     throws ArithmeticException JavaDoc
262     {
263         return new SpecificIntegerValue(this.value / other.value);
264     }
265
266     public IntegerValue divideOf(SpecificIntegerValue other)
267     throws ArithmeticException JavaDoc
268     {
269         return new SpecificIntegerValue(other.value / this.value);
270     }
271
272     public IntegerValue remainder(SpecificIntegerValue other)
273     throws ArithmeticException JavaDoc
274     {
275         return new SpecificIntegerValue(this.value % other.value);
276     }
277
278     public IntegerValue remainderOf(SpecificIntegerValue other)
279     throws ArithmeticException JavaDoc
280     {
281         return new SpecificIntegerValue(other.value % this.value);
282     }
283
284     public IntegerValue shiftLeft(SpecificIntegerValue other)
285     {
286         return new SpecificIntegerValue(this.value << other.value);
287     }
288
289     public IntegerValue shiftLeftOf(SpecificIntegerValue other)
290     {
291         return new SpecificIntegerValue(other.value << this.value);
292     }
293
294     public IntegerValue shiftRight(SpecificIntegerValue other)
295     {
296         return new SpecificIntegerValue(this.value >> other.value);
297     }
298
299     public IntegerValue shiftRightOf(SpecificIntegerValue other)
300     {
301         return new SpecificIntegerValue(other.value >> this.value);
302     }
303
304     public IntegerValue unsignedShiftRight(SpecificIntegerValue other)
305     {
306         return new SpecificIntegerValue(this.value >>> other.value);
307     }
308
309     public IntegerValue unsignedShiftRightOf(SpecificIntegerValue other)
310     {
311         return new SpecificIntegerValue(other.value >>> this.value);
312     }
313
314     public LongValue shiftLeftOf(SpecificLongValue other, ValueFactory valueFactory)
315     {
316         return valueFactory.createLongValue(other.value() << this.value);
317     }
318
319     public LongValue shiftRightOf(SpecificLongValue other, ValueFactory valueFactory)
320     {
321         return valueFactory.createLongValue(other.value() >> this.value);
322     }
323
324     public LongValue unsignedShiftRightOf(SpecificLongValue other, ValueFactory valueFactory)
325     {
326         return valueFactory.createLongValue(other.value() >>> this.value);
327     }
328
329     public IntegerValue and(SpecificIntegerValue other)
330     {
331         return new SpecificIntegerValue(this.value & other.value);
332     }
333
334     public IntegerValue or(SpecificIntegerValue other)
335     {
336         return new SpecificIntegerValue(this.value | other.value);
337     }
338
339     public IntegerValue xor(SpecificIntegerValue other)
340     {
341         return new SpecificIntegerValue(this.value ^ other.value);
342     }
343
344     public int equal(SpecificIntegerValue other)
345     {
346         return this.value == other.value ? ALWAYS : NEVER;
347     }
348
349     public int lessThan(SpecificIntegerValue other)
350     {
351         return this.value < other.value ? ALWAYS : NEVER;
352     }
353
354     public int lessThanOrEqual(SpecificIntegerValue other)
355     {
356         return this.value <= other.value ? ALWAYS : NEVER;
357     }
358
359
360     // Implementations for Value.
361

362     public boolean isSpecific()
363     {
364         return true;
365     }
366
367
368     // Implementations for Object.
369

370     public boolean equals(Object JavaDoc object)
371     {
372         return object != null &&
373                this.getClass() == object.getClass() &&
374                this.value == ((SpecificIntegerValue)object).value;
375     }
376
377
378     public int hashCode()
379     {
380         return this.getClass().hashCode() ^ value;
381     }
382
383
384     public String JavaDoc toString()
385     {
386         return "i:"+value;
387     }
388 }
389
Popular Tags