• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
3  *             of Java bytecode.
4  *
5  * Copyright (c) 2002-2009 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 particular long value.
25  *
26  * @author Eric Lafortune
27  */
28 final class ParticularLongValue extends SpecificLongValue
29 {
30     private final long value;
31 
32 
33     /**
34      * Creates a new particular long value.
35      */
ParticularLongValue(long value)36     public ParticularLongValue(long value)
37     {
38         this.value = value;
39     }
40 
41 
42     // Implementations for LongValue.
43 
value()44     public long value()
45     {
46         return value;
47     }
48 
49 
50     // Implementations of unary methods of LongValue.
51 
negate()52     public LongValue negate()
53     {
54         return new ParticularLongValue(-value);
55     }
56 
convertToInteger()57     public IntegerValue convertToInteger()
58     {
59         return new ParticularIntegerValue((int)value);
60     }
61 
convertToFloat()62     public FloatValue convertToFloat()
63     {
64         return new ParticularFloatValue((float)value);
65     }
66 
convertToDouble()67     public DoubleValue convertToDouble()
68     {
69         return new ParticularDoubleValue((double)value);
70     }
71 
72 
73     // Implementations of binary methods of LongValue.
74 
generalize(LongValue other)75     public LongValue generalize(LongValue other)
76     {
77         return other.generalize(this);
78     }
79 
add(LongValue other)80     public LongValue add(LongValue other)
81     {
82         return other.add(this);
83     }
84 
subtract(LongValue other)85     public LongValue subtract(LongValue other)
86     {
87         return other.subtractFrom(this);
88     }
89 
subtractFrom(LongValue other)90     public LongValue subtractFrom(LongValue other)
91     {
92         return other.subtract(this);
93     }
94 
multiply(LongValue other)95     public LongValue multiply(LongValue other)
96     {
97         return other.multiply(this);
98     }
99 
divide(LongValue other)100     public LongValue divide(LongValue other)
101     throws ArithmeticException
102     {
103         return other.divideOf(this);
104     }
105 
divideOf(LongValue other)106     public LongValue divideOf(LongValue other)
107     throws ArithmeticException
108     {
109         return other.divide(this);
110     }
111 
remainder(LongValue other)112     public LongValue remainder(LongValue other)
113     throws ArithmeticException
114     {
115         return other.remainderOf(this);
116     }
117 
remainderOf(LongValue other)118     public LongValue remainderOf(LongValue other)
119     throws ArithmeticException
120     {
121         return other.remainder(this);
122     }
123 
shiftLeft(IntegerValue other)124     public LongValue shiftLeft(IntegerValue other)
125     {
126         return other.shiftLeftOf(this);
127     }
128 
shiftRight(IntegerValue other)129     public LongValue shiftRight(IntegerValue other)
130     {
131         return other.shiftRightOf(this);
132     }
133 
unsignedShiftRight(IntegerValue other)134     public LongValue unsignedShiftRight(IntegerValue other)
135     {
136         return other.unsignedShiftRightOf(this);
137     }
138 
and(LongValue other)139     public LongValue and(LongValue other)
140     {
141         return other.and(this);
142     }
143 
or(LongValue other)144     public LongValue or(LongValue other)
145     {
146         return other.or(this);
147     }
148 
xor(LongValue other)149     public LongValue xor(LongValue other)
150     {
151         return other.xor(this);
152     }
153 
compare(LongValue other)154     public IntegerValue compare(LongValue other)
155     {
156         return other.compareReverse(this);
157     }
158 
159 
160     // Implementations of binary LongValue methods with ParticularLongValue
161     // arguments.
162 
generalize(ParticularLongValue other)163     public LongValue generalize(ParticularLongValue other)
164     {
165         return generalize((SpecificLongValue)other);
166     }
167 
add(ParticularLongValue other)168     public LongValue add(ParticularLongValue other)
169     {
170         return new ParticularLongValue(this.value + other.value);
171     }
172 
subtract(ParticularLongValue other)173     public LongValue subtract(ParticularLongValue other)
174     {
175         return new ParticularLongValue(this.value - other.value);
176     }
177 
subtractFrom(ParticularLongValue other)178     public LongValue subtractFrom(ParticularLongValue other)
179     {
180         return new ParticularLongValue(other.value - this.value);
181     }
182 
multiply(ParticularLongValue other)183     public LongValue multiply(ParticularLongValue other)
184     {
185         return new ParticularLongValue(this.value * other.value);
186     }
187 
divide(ParticularLongValue other)188     public LongValue divide(ParticularLongValue other)
189     throws ArithmeticException
190     {
191         return new ParticularLongValue(this.value / other.value);
192     }
193 
divideOf(ParticularLongValue other)194     public LongValue divideOf(ParticularLongValue other)
195     throws ArithmeticException
196     {
197         return new ParticularLongValue(other.value / this.value);
198     }
199 
remainder(ParticularLongValue other)200     public LongValue remainder(ParticularLongValue other)
201     throws ArithmeticException
202     {
203         return new ParticularLongValue(this.value % other.value);
204     }
205 
remainderOf(ParticularLongValue other)206     public LongValue remainderOf(ParticularLongValue other)
207     throws ArithmeticException
208     {
209         return new ParticularLongValue(other.value % this.value);
210     }
211 
shiftLeft(ParticularIntegerValue other)212     public LongValue shiftLeft(ParticularIntegerValue other)
213     {
214         return new ParticularLongValue(this.value << other.value());
215     }
216 
shiftRight(ParticularIntegerValue other)217     public LongValue shiftRight(ParticularIntegerValue other)
218     {
219         return new ParticularLongValue(this.value >> other.value());
220     }
221 
unsignedShiftRight(ParticularIntegerValue other)222     public LongValue unsignedShiftRight(ParticularIntegerValue other)
223     {
224         return new ParticularLongValue(this.value >>> other.value());
225     }
226 
and(ParticularLongValue other)227     public LongValue and(ParticularLongValue other)
228     {
229         return new ParticularLongValue(this.value & other.value);
230     }
231 
or(ParticularLongValue other)232     public LongValue or(ParticularLongValue other)
233     {
234         return new ParticularLongValue(this.value | other.value);
235     }
236 
xor(ParticularLongValue other)237     public LongValue xor(ParticularLongValue other)
238     {
239         return new ParticularLongValue(this.value ^ other.value);
240     }
241 
242 
243     // Implementations for Value.
244 
isParticular()245     public boolean isParticular()
246     {
247         return true;
248     }
249 
250 
251     // Implementations for Object.
252 
equals(Object object)253     public boolean equals(Object object)
254     {
255         return super.equals(object) &&
256                this.value == ((ParticularLongValue)object).value;
257     }
258 
259 
hashCode()260     public int hashCode()
261     {
262         return this.getClass().hashCode() ^
263                (int)value;
264     }
265 
266 
toString()267     public String toString()
268     {
269         return value+"L";
270     }
271 }