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
23import proguard.classfile.Clazz;
24
25/**
26 * This LongValue represents a reference value that is identified by a unique ID.
27 *
28 * @author Eric Lafortune
29 */
30final class IdentifiedReferenceValue extends ReferenceValue
31{
32    private final ValueFactory valuefactory;
33    private final int          id;
34
35
36    /**
37     * Creates a new long value with the given ID.
38     */
39    public IdentifiedReferenceValue(String       type,
40                                    Clazz        referencedClass,
41                                    boolean      mayBeNull,
42                                    ValueFactory valuefactory,
43                                    int          id)
44    {
45        super(type, referencedClass, mayBeNull);
46
47        this.valuefactory = valuefactory;
48        this.id           = id;
49    }
50
51
52    // Implementations for ReferenceValue.
53
54    public int equal(ReferenceValue other)
55    {
56        return this.equals(other) ? ALWAYS : MAYBE;
57    }
58
59
60    // Implementations for Value.
61
62    public boolean isSpecific()
63    {
64        return true;
65    }
66
67
68    // Implementations for Object.
69
70    public boolean equals(Object object)
71    {
72        return this == object ||
73               super.equals(object) &&
74               this.valuefactory.equals(((IdentifiedReferenceValue)object).valuefactory) &&
75               this.id == ((IdentifiedReferenceValue)object).id;
76    }
77
78
79    public int hashCode()
80    {
81        return super.hashCode() ^
82               valuefactory.hashCode() ^
83               id;
84    }
85
86
87    public String toString()
88    {
89        return super.toString()+'#'+id;
90    }
91}