KickJava   Java API By Example, From Geeks To Geeks.

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


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

28 class SpecificDoubleValue extends DoubleValue
29 {
30     private double value;
31
32
33     /**
34      * Creates a new specific double value.
35      */

36     public SpecificDoubleValue(double value)
37     {
38         this.value = value;
39     }
40
41
42     // Implementations for DoubleValue.
43

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

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

55     public DoubleValue generalize(DoubleValue other)
56     {
57         return other.generalize(this);
58     }
59
60     public DoubleValue add(DoubleValue other)
61     {
62         return other.add(this);
63     }
64
65     public DoubleValue subtract(DoubleValue other)
66     {
67         return other.subtractFrom(this);
68     }
69
70     public DoubleValue subtractFrom(DoubleValue other)
71     {
72         return other.subtract(this);
73     }
74
75     public DoubleValue multiply(DoubleValue other)
76     {
77         return other.multiply(this);
78     }
79
80     public DoubleValue divide(DoubleValue other)
81     {
82         return other.divideOf(this);
83     }
84
85     public DoubleValue divideOf(DoubleValue other)
86     {
87         return other.divide(this);
88     }
89
90     public DoubleValue remainder(DoubleValue other)
91     {
92         return other.remainderOf(this);
93     }
94
95     public DoubleValue remainderOf(DoubleValue other)
96     {
97         return other.remainder(this);
98     }
99
100     public IntegerValue compare(DoubleValue other, ValueFactory valueFactory)
101     {
102         return other.compareReverse(this, valueFactory);
103     }
104
105
106     // Implementations of unary methods of DoubleValue.
107

108     public DoubleValue negate()
109     {
110         return new SpecificDoubleValue(-value);
111     }
112
113     public IntegerValue convertToInteger(ValueFactory valueFactory)
114     {
115         return new SpecificIntegerValue((int)value);
116     }
117
118     public LongValue convertToLong(ValueFactory valueFactory)
119     {
120         return new SpecificLongValue((long)value);
121     }
122
123     public FloatValue convertToFloat(ValueFactory valueFactory)
124     {
125         return new SpecificFloatValue((float)value);
126     }
127
128
129     // Implementations of binary DoubleValue methods with SpecificDoubleValue
130
// arguments.
131

132     public DoubleValue generalize(SpecificDoubleValue other)
133     {
134         return this.value == other.value ? this : ValueFactory.DOUBLE_VALUE;
135     }
136
137     public DoubleValue add(SpecificDoubleValue other)
138     {
139         return new SpecificDoubleValue(this.value + other.value);
140     }
141
142     public DoubleValue subtract(SpecificDoubleValue other)
143     {
144         return new SpecificDoubleValue(this.value - other.value);
145     }
146
147     public DoubleValue subtractFrom(SpecificDoubleValue other)
148     {
149         return new SpecificDoubleValue(other.value - this.value);
150     }
151
152     public DoubleValue multiply(SpecificDoubleValue other)
153     {
154         return new SpecificDoubleValue(this.value * other.value);
155     }
156
157     public DoubleValue divide(SpecificDoubleValue other)
158     {
159         return new SpecificDoubleValue(this.value / other.value);
160     }
161
162     public DoubleValue divideOf(SpecificDoubleValue other)
163     {
164         return new SpecificDoubleValue(other.value / this.value);
165     }
166
167     public DoubleValue remainder(SpecificDoubleValue other)
168     {
169         return new SpecificDoubleValue(this.value % other.value);
170     }
171
172     public DoubleValue remainderOf(SpecificDoubleValue other)
173     {
174         return new SpecificDoubleValue(other.value % this.value);
175     }
176
177     public IntegerValue compare(SpecificDoubleValue other, ValueFactory valueFactory)
178     {
179         return this.value < other.value ? SpecificValueFactory.INTEGER_VALUE_M1 :
180                this.value == other.value ? SpecificValueFactory.INTEGER_VALUE_0 :
181                                            SpecificValueFactory.INTEGER_VALUE_1;
182     }
183
184
185     // Implementations for Value.
186

187     public boolean isSpecific()
188     {
189         return true;
190     }
191
192
193     // Implementations for Object.
194

195     public boolean equals(Object JavaDoc object)
196     {
197         return object != null &&
198                this.getClass() == object.getClass() &&
199                this.value == ((SpecificDoubleValue)object).value;
200     }
201
202
203     public int hashCode()
204     {
205         return this.getClass().hashCode() ^ (int)Double.doubleToLongBits(value);
206     }
207
208
209     public String JavaDoc toString()
210     {
211         return "d:"+value;
212     }
213 }
214
Popular Tags