CompositeDoubleValue.java revision db267bc191f906f55eaef21a27110cce2ec57fdf
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 */
21package proguard.evaluation.value;
22
23/**
24 * This DoubleValue represents the result of a binary operation on two double
25 * values.
26 *
27 * @author Eric Lafortune
28 */
29final class CompositeDoubleValue extends SpecificDoubleValue
30{
31    public static final byte ADD       = '+';
32    public static final byte SUBTRACT  = '-';
33    public static final byte MULTIPLY  = '*';
34    public static final byte DIVIDE    = '/';
35    public static final byte REMAINDER = '%';
36
37
38    private final DoubleValue doubleValue1;
39    private final byte        operation;
40    private final DoubleValue doubleValue2;
41
42
43    /**
44     * Creates a new composite double value of the two given double values
45     * and the given operation.
46     */
47    public CompositeDoubleValue(DoubleValue doubleValue1,
48                                byte        operation,
49                                DoubleValue doubleValue2)
50    {
51        this.doubleValue1 = doubleValue1;
52        this.operation    = operation;
53        this.doubleValue2 = doubleValue2;
54    }
55
56
57    // Implementations for Object.
58
59    public boolean equals(Object object)
60    {
61        return this == object ||
62               super.equals(object) &&
63               this.doubleValue1.equals(((CompositeDoubleValue)object).doubleValue1) &&
64               this.operation        == ((CompositeDoubleValue)object).operation     &&
65               this.doubleValue2.equals(((CompositeDoubleValue)object).doubleValue2);
66    }
67
68
69    public int hashCode()
70    {
71        return super.hashCode() ^
72               doubleValue1.hashCode() ^
73               doubleValue2.hashCode();
74    }
75
76
77    public String toString()
78    {
79        return "("+doubleValue1+((char)operation)+doubleValue2+")";
80    }
81}