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 adouble
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 DoubleValue represents a specific double value.
025: *
026: * @author Eric Lafortune
027: */
028: final class SpecificDoubleValue extends DoubleValue {
029: private final double value;
030:
031: /**
032: * Creates a new specific double value.
033: */
034: public SpecificDoubleValue(double value) {
035: this .value = value;
036: }
037:
038: // Implementations for DoubleValue.
039:
040: public double value() {
041: return value;
042: }
043:
044: // Implementations of binary methods of DoubleValue.
045:
046: // Perhaps the other value arguments are more specific than apparent
047: // in these methods, so delegate to them.
048:
049: public DoubleValue generalize(DoubleValue other) {
050: return other.generalize(this );
051: }
052:
053: public DoubleValue add(DoubleValue other) {
054: return other.add(this );
055: }
056:
057: public DoubleValue subtract(DoubleValue other) {
058: return other.subtractFrom(this );
059: }
060:
061: public DoubleValue subtractFrom(DoubleValue other) {
062: return other.subtract(this );
063: }
064:
065: public DoubleValue multiply(DoubleValue other) {
066: return other.multiply(this );
067: }
068:
069: public DoubleValue divide(DoubleValue other) {
070: return other.divideOf(this );
071: }
072:
073: public DoubleValue divideOf(DoubleValue other) {
074: return other.divide(this );
075: }
076:
077: public DoubleValue remainder(DoubleValue other) {
078: return other.remainderOf(this );
079: }
080:
081: public DoubleValue remainderOf(DoubleValue other) {
082: return other.remainder(this );
083: }
084:
085: public IntegerValue compare(DoubleValue other,
086: ValueFactory valueFactory) {
087: return other.compareReverse(this , valueFactory);
088: }
089:
090: // Implementations of unary methods of DoubleValue.
091:
092: public DoubleValue negate() {
093: return new SpecificDoubleValue(-value);
094: }
095:
096: public IntegerValue convertToInteger(ValueFactory valueFactory) {
097: return new SpecificIntegerValue((int) value);
098: }
099:
100: public LongValue convertToLong(ValueFactory valueFactory) {
101: return new SpecificLongValue((long) value);
102: }
103:
104: public FloatValue convertToFloat(ValueFactory valueFactory) {
105: return new SpecificFloatValue((float) value);
106: }
107:
108: // Implementations of binary DoubleValue methods with SpecificDoubleValue
109: // arguments.
110:
111: public DoubleValue generalize(SpecificDoubleValue other) {
112: return this .value == other.value ? this
113: : ValueFactory.DOUBLE_VALUE;
114: }
115:
116: public DoubleValue add(SpecificDoubleValue other) {
117: return new SpecificDoubleValue(this .value + other.value);
118: }
119:
120: public DoubleValue subtract(SpecificDoubleValue other) {
121: return new SpecificDoubleValue(this .value - other.value);
122: }
123:
124: public DoubleValue subtractFrom(SpecificDoubleValue other) {
125: return new SpecificDoubleValue(other.value - this .value);
126: }
127:
128: public DoubleValue multiply(SpecificDoubleValue other) {
129: return new SpecificDoubleValue(this .value * other.value);
130: }
131:
132: public DoubleValue divide(SpecificDoubleValue other) {
133: return new SpecificDoubleValue(this .value / other.value);
134: }
135:
136: public DoubleValue divideOf(SpecificDoubleValue other) {
137: return new SpecificDoubleValue(other.value / this .value);
138: }
139:
140: public DoubleValue remainder(SpecificDoubleValue other) {
141: return new SpecificDoubleValue(this .value % other.value);
142: }
143:
144: public DoubleValue remainderOf(SpecificDoubleValue other) {
145: return new SpecificDoubleValue(other.value % this .value);
146: }
147:
148: public IntegerValue compare(SpecificDoubleValue other,
149: ValueFactory valueFactory) {
150: return this .value < other.value ? SpecificValueFactory.INTEGER_VALUE_M1
151: : this .value == other.value ? SpecificValueFactory.INTEGER_VALUE_0
152: : SpecificValueFactory.INTEGER_VALUE_1;
153: }
154:
155: // Implementations for Value.
156:
157: public boolean isSpecific() {
158: return true;
159: }
160:
161: // Implementations for Object.
162:
163: public boolean equals(Object object) {
164: return object != null && this .getClass() == object.getClass()
165: && this .value == ((SpecificDoubleValue) object).value;
166: }
167:
168: public int hashCode() {
169: return this .getClass().hashCode()
170: ^ (int) Double.doubleToLongBits(value);
171: }
172:
173: public String toString() {
174: return "d:" + value;
175: }
176: }
|