1 | /* |
2 | |
3 | Derby - Class org.apache.derby.iapi.services.classfile.CONSTANT_Index_info |
4 | |
5 | Copyright 2000, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.iapi.services.classfile; |
22 | |
23 | import org.apache.derby.iapi.services.classfile.VMDescriptor; |
24 | |
25 | import java.io.IOException; |
26 | |
27 | /** |
28 | |
29 | A generic constant pool entry for entries that simply hold indexes |
30 | into other entries. |
31 | |
32 | <BR> |
33 | Ref Constant Pool Entry - page 94 - Section 4.4.2 - Two indexes |
34 | <BR> |
35 | NameAndType Constant Pool Entry - page 99 - Section 4.4.6 - Two indexes |
36 | <BR> |
37 | String Constant Pool Entry - page 96 - Section 4.4.3 - One index |
38 | <BR> |
39 | Class Reference Constant Pool Entry - page 93 - Section 4.4.1 - One index |
40 | |
41 | */ |
42 | public final class CONSTANT_Index_info extends ConstantPoolEntry { |
43 | |
44 | private int i1; |
45 | private int i2; |
46 | |
47 | CONSTANT_Index_info(int tag, int i1, int i2) { |
48 | super(tag); |
49 | this.i1 = i1; |
50 | this.i2 = i2; |
51 | } |
52 | |
53 | public int hashCode() { |
54 | return (tag << 16) | ((i1 << 8) ^ i2); |
55 | } |
56 | |
57 | public boolean equals(Object other) { |
58 | if (other instanceof CONSTANT_Index_info) { |
59 | CONSTANT_Index_info o = (CONSTANT_Index_info) other; |
60 | |
61 | return (tag == o.tag) && (i1 == o.i1) && (i2 == o.i2); |
62 | } |
63 | return false; |
64 | } |
65 | |
66 | |
67 | /** |
68 | Used when searching |
69 | */ |
70 | void set(int tag, int i1, int i2) { |
71 | this.tag = tag; |
72 | this.i1 = i1; |
73 | this.i2 = i2; |
74 | } |
75 | |
76 | int classFileSize() { |
77 | // 1 (tag) + 2 (index length) [ + 2 (index length) ] |
78 | return 1 + 2 + ((i2 != 0) ? 2 : 0); |
79 | } |
80 | |
81 | void put(ClassFormatOutput out) throws IOException { |
82 | super.put(out); |
83 | out.putU2(i1); |
84 | if (i2 != 0) |
85 | out.putU2(i2); |
86 | } |
87 | |
88 | public int getI1() { return i1; } |
89 | |
90 | public int getI2() { return i2; } |
91 | } |