1/*
2 * ProGuard -- shrinking, optimization, obfuscation, and preverification
3 *             of Java bytecode.
4 *
5 * Copyright (c) 2002-2013 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 FloatValue represents the result of a binary operation on two float
25 * values.
26 *
27 * @author Eric Lafortune
28 */
29final class CompositeFloatValue extends SpecificFloatValue
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 FloatValue floatValue1;
39    private final byte       operation;
40    private final FloatValue floatValue2;
41
42
43    /**
44     * Creates a new composite float value of the two given float values
45     * and the given operation.
46     */
47    public CompositeFloatValue(FloatValue floatValue1,
48                               byte       operation,
49                               FloatValue floatValue2)
50    {
51        this.floatValue1 = floatValue1;
52        this.operation   = operation;
53        this.floatValue2 = floatValue2;
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.floatValue1.equals(((CompositeFloatValue)object).floatValue1) &&
64               this.operation       == ((CompositeFloatValue)object).operation    &&
65               this.floatValue2.equals(((CompositeFloatValue)object).floatValue2);
66    }
67
68
69    public int hashCode()
70    {
71        return super.hashCode() ^
72               floatValue1.hashCode() ^
73               floatValue2.hashCode();
74    }
75
76
77    public String toString()
78    {
79        return "("+floatValue1+((char)operation)+floatValue2+")";
80    }
81}