01: /*
02:
03: Derby - Class org.apache.derby.iapi.services.classfile.CONSTANT_Index_info
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (the "License"); you may not use this file except in compliance with
10: the License. You may obtain a copy of the License at
11:
12: http://www.apache.org/licenses/LICENSE-2.0
13:
14: Unless required by applicable law or agreed to in writing, software
15: distributed under the License is distributed on an "AS IS" BASIS,
16: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: See the License for the specific language governing permissions and
18: limitations under the License.
19:
20: */
21:
22: package org.apache.derby.iapi.services.classfile;
23:
24: import org.apache.derby.iapi.services.classfile.VMDescriptor;
25:
26: import java.io.IOException;
27:
28: /**
29:
30: A generic constant pool entry for entries that simply hold indexes
31: into other entries.
32:
33: <BR>
34: Ref Constant Pool Entry - page 94 - Section 4.4.2 - Two indexes
35: <BR>
36: NameAndType Constant Pool Entry - page 99 - Section 4.4.6 - Two indexes
37: <BR>
38: String Constant Pool Entry - page 96 - Section 4.4.3 - One index
39: <BR>
40: Class Reference Constant Pool Entry - page 93 - Section 4.4.1 - One index
41:
42: */
43: public final class CONSTANT_Index_info extends ConstantPoolEntry {
44:
45: private int i1;
46: private int i2;
47:
48: CONSTANT_Index_info(int tag, int i1, int i2) {
49: super (tag);
50: this .i1 = i1;
51: this .i2 = i2;
52: }
53:
54: public int hashCode() {
55: return (tag << 16) | ((i1 << 8) ^ i2);
56: }
57:
58: public boolean equals(Object other) {
59: if (other instanceof CONSTANT_Index_info) {
60: CONSTANT_Index_info o = (CONSTANT_Index_info) other;
61:
62: return (tag == o.tag) && (i1 == o.i1) && (i2 == o.i2);
63: }
64: return false;
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() {
89: return i1;
90: }
91:
92: public int getI2() {
93: return i2;
94: }
95: }
|