KickJava   Java API By Example, From Geeks To Geeks.

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


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

28 class SpecificFloatValue extends FloatValue
29 {
30     private float value;
31
32
33     /**
34      * Creates a new specific float value.
35      */

36     public SpecificFloatValue(float value)
37     {
38         this.value = value;
39     }
40
41
42     // Implementations for FloatValue.
43

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

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

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

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

132     public FloatValue generalize(SpecificFloatValue other)
133     {
134         return this.value == other.value ? this : ValueFactory.FLOAT_VALUE;
135     }
136
137     public FloatValue add(SpecificFloatValue other)
138     {
139         return new SpecificFloatValue(this.value + other.value);
140     }
141
142     public FloatValue subtract(SpecificFloatValue other)
143     {
144         return new SpecificFloatValue(this.value - other.value);
145     }
146
147     public FloatValue subtractFrom(SpecificFloatValue other)
148     {
149         return new SpecificFloatValue(other.value - this.value);
150     }
151
152     public FloatValue multiply(SpecificFloatValue other)
153     {
154         return new SpecificFloatValue(this.value * other.value);
155     }
156
157     public FloatValue divide(SpecificFloatValue other)
158     {
159         return new SpecificFloatValue(this.value / other.value);
160     }
161
162     public FloatValue divideOf(SpecificFloatValue other)
163     {
164         return new SpecificFloatValue(other.value / this.value);
165     }
166
167     public FloatValue remainder(SpecificFloatValue other)
168     {
169         return new SpecificFloatValue(this.value % other.value);
170     }
171
172     public FloatValue remainderOf(SpecificFloatValue other)
173     {
174         return new SpecificFloatValue(other.value % this.value);
175     }
176
177     public IntegerValue compare(SpecificFloatValue other, ValueFactory valueFactory)
178     {
179         return this.value < other.value ? valueFactory.createIntegerValue(-1) :
180                this.value == other.value ? valueFactory.createIntegerValue(0) :
181                                            valueFactory.createIntegerValue(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 == ((SpecificFloatValue)object).value;
200     }
201
202
203     public int hashCode()
204     {
205         return this.getClass().hashCode() ^ Float.floatToIntBits(value);
206     }
207
208
209     public String JavaDoc toString()
210     {
211         return "f:"+value;
212     }
213 }
214
Popular Tags