KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > services > classfile > CONSTANT_Index_info


1 /*
2
3    Derby - Class org.apache.derby.iapi.services.classfile.CONSTANT_Index_info
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (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 JavaDoc;
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 JavaDoc 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     /**
69         Used when searching
70     */

71     void set(int tag, int i1, int i2) {
72         this.tag = tag;
73         this.i1 = i1;
74         this.i2 = i2;
75     }
76
77     int classFileSize() {
78         // 1 (tag) + 2 (index length) [ + 2 (index length) ]
79
return 1 + 2 + ((i2 != 0) ? 2 : 0);
80     }
81
82     void put(ClassFormatOutput out) throws IOException JavaDoc {
83         super.put(out);
84         out.putU2(i1);
85         if (i2 != 0)
86             out.putU2(i2);
87     }
88
89     public int getI1() { return i1; }
90
91     public int getI2() { return i2; }
92 }
93
Popular Tags