001: /*
002: * ProGuard -- shrinking, optimization, obfuscation, and preverification
003: * of Java bytecode.
004: *
005: * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the Free
009: * Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful, but WITHOUT
013: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
015: * more details.
016: *
017: * You should have received a copy of the GNU General Public License afloat
018: * with this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: package proguard.evaluation.value;
022:
023: /**
024: * This FloatValue represents a specific float value.
025: *
026: * @author Eric Lafortune
027: */
028: final class SpecificFloatValue extends FloatValue {
029: private final float value;
030:
031: /**
032: * Creates a new specific float value.
033: */
034: public SpecificFloatValue(float value) {
035: this .value = value;
036: }
037:
038: // Implementations for FloatValue.
039:
040: public float value() {
041: return value;
042: }
043:
044: // Implementations of binary methods of FloatValue.
045:
046: // Perhaps the other value arguments are more specific than apparent
047: // in these methods, so delegate to them.
048:
049: public FloatValue generalize(FloatValue other) {
050: return other.generalize(this );
051: }
052:
053: public FloatValue add(FloatValue other) {
054: return other.add(this );
055: }
056:
057: public FloatValue subtract(FloatValue other) {
058: return other.subtractFrom(this );
059: }
060:
061: public FloatValue subtractFrom(FloatValue other) {
062: return other.subtract(this );
063: }
064:
065: public FloatValue multiply(FloatValue other) {
066: return other.multiply(this );
067: }
068:
069: public FloatValue divide(FloatValue other) {
070: return other.divideOf(this );
071: }
072:
073: public FloatValue divideOf(FloatValue other) {
074: return other.divide(this );
075: }
076:
077: public FloatValue remainder(FloatValue other) {
078: return other.remainderOf(this );
079: }
080:
081: public FloatValue remainderOf(FloatValue other) {
082: return other.remainder(this );
083: }
084:
085: public IntegerValue compare(FloatValue other,
086: ValueFactory valueFactory) {
087: return other.compareReverse(this , valueFactory);
088: }
089:
090: // Implementations of unary methods of FloatValue.
091:
092: public FloatValue negate() {
093: return new SpecificFloatValue(-value);
094: }
095:
096: public IntegerValue convertToInteger(ValueFactory valueFactory) {
097: return valueFactory.createIntegerValue((int) value);
098: }
099:
100: public LongValue convertToLong(ValueFactory valueFactory) {
101: return valueFactory.createLongValue((long) value);
102: }
103:
104: public DoubleValue convertToDouble(ValueFactory valueFactory) {
105: return valueFactory.createDoubleValue((double) value);
106: }
107:
108: // Implementations of binary FloatValue methods with SpecificFloatValue
109: // arguments.
110:
111: public FloatValue generalize(SpecificFloatValue other) {
112: return this .value == other.value ? this
113: : ValueFactory.FLOAT_VALUE;
114: }
115:
116: public FloatValue add(SpecificFloatValue other) {
117: return new SpecificFloatValue(this .value + other.value);
118: }
119:
120: public FloatValue subtract(SpecificFloatValue other) {
121: return new SpecificFloatValue(this .value - other.value);
122: }
123:
124: public FloatValue subtractFrom(SpecificFloatValue other) {
125: return new SpecificFloatValue(other.value - this .value);
126: }
127:
128: public FloatValue multiply(SpecificFloatValue other) {
129: return new SpecificFloatValue(this .value * other.value);
130: }
131:
132: public FloatValue divide(SpecificFloatValue other) {
133: return new SpecificFloatValue(this .value / other.value);
134: }
135:
136: public FloatValue divideOf(SpecificFloatValue other) {
137: return new SpecificFloatValue(other.value / this .value);
138: }
139:
140: public FloatValue remainder(SpecificFloatValue other) {
141: return new SpecificFloatValue(this .value % other.value);
142: }
143:
144: public FloatValue remainderOf(SpecificFloatValue other) {
145: return new SpecificFloatValue(other.value % this .value);
146: }
147:
148: public IntegerValue compare(SpecificFloatValue other,
149: ValueFactory valueFactory) {
150: return this .value < other.value ? valueFactory
151: .createIntegerValue(-1)
152: : this .value == other.value ? valueFactory
153: .createIntegerValue(0) : valueFactory
154: .createIntegerValue(1);
155: }
156:
157: // Implementations for Value.
158:
159: public boolean isSpecific() {
160: return true;
161: }
162:
163: // Implementations for Object.
164:
165: public boolean equals(Object object) {
166: return object != null && this .getClass() == object.getClass()
167: && this .value == ((SpecificFloatValue) object).value;
168: }
169:
170: public int hashCode() {
171: return this .getClass().hashCode() ^ Float.floatToIntBits(value);
172: }
173:
174: public String toString() {
175: return "f:" + value;
176: }
177: }
|