KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > structures > constants > ConstantStringInfo


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.structures.constants;
9
10 import org.gjt.jclasslib.structures.CPInfo;
11 import org.gjt.jclasslib.structures.InvalidByteCodeException;
12
13 import java.io.*;
14
15 /**
16     Describes a <tt>CONSTANT_String_info</tt> constant pool data structure.
17
18     @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
19     @version $Revision: 1.5 $ $Date: 2003/08/18 07:51:44 $
20 */

21 public class ConstantStringInfo extends CPInfo {
22
23     /** Length of the constant pool data structure in bytes. */
24     public static final int SIZE = 2;
25     
26     private int stringIndex;
27     
28     public byte getTag() {
29         return CONSTANT_STRING;
30     }
31
32     public String JavaDoc getTagVerbose() {
33         return CONSTANT_STRING_VERBOSE;
34     }
35     
36     public String JavaDoc getVerbose() throws InvalidByteCodeException {
37         return classFile.getConstantPoolEntryName(stringIndex);
38     }
39
40     /**
41         Get the index of the constant pool entry containing the
42         string of this entry.
43         @return the index
44      */

45     public int getStringIndex() {
46         return stringIndex;
47     }
48
49     /**
50         Set the index of the constant pool entry containing the
51         string of this entry.
52         @param stringIndex the index
53      */

54     public void setStringIndex(int stringIndex) {
55         this.stringIndex = stringIndex;
56     }
57
58     public void read(DataInput in)
59         throws InvalidByteCodeException, IOException {
60             
61         stringIndex = in.readUnsignedShort();
62         if (debug) debug("read ");
63     }
64     
65     public void write(DataOutput out)
66         throws InvalidByteCodeException, IOException {
67
68         out.writeByte(CONSTANT_STRING);
69         out.writeShort(stringIndex);
70         if (debug) debug("wrote ");
71     }
72
73     protected void debug(String JavaDoc message) {
74         super.debug(message + getTagVerbose() + " with string_index " + stringIndex);
75     }
76
77     public boolean equals(Object JavaDoc object) {
78         if (!(object instanceof ConstantStringInfo)) {
79             return false;
80         }
81         ConstantStringInfo constantStringInfo = (ConstantStringInfo)object;
82         return super.equals(object) && constantStringInfo.stringIndex == stringIndex;
83     }
84
85     public int hashCode() {
86         return super.hashCode() ^ stringIndex;
87     }
88     
89 }
90
Popular Tags