KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > bytecode > CpoolString


1 // Copyright (c) 1997 Per M.A. Bothner.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.bytecode;
5 import java.io.*;
6
7 /** A CONSTANT_String entry in the constant pool. */
8
9 public class CpoolString extends CpoolEntry
10 {
11   CpoolUtf8 str;
12
13   CpoolString() { }
14
15   CpoolString (ConstantPool cpool, int hash, CpoolUtf8 str)
16   {
17     super (cpool, hash);
18     this.str = str;
19   }
20
21   public int getTag() { return ConstantPool.STRING; }
22
23   public final CpoolUtf8 getString()
24   {
25     return str;
26   }
27
28   final static int hashCode (CpoolUtf8 str) { return str.hashCode() ^ 0xF30F; }
29
30   public int hashCode ()
31   {
32     if (hash == 0)
33       hash = hashCode(str);
34     return hash;
35   }
36
37   void write (DataOutputStream dstr) throws java.io.IOException JavaDoc
38   {
39     dstr.writeByte (ConstantPool.STRING);
40     dstr.writeShort (str.index);
41   }
42
43   public void print (ClassTypeWriter dst, int verbosity)
44   {
45     if (verbosity > 0)
46       {
47     dst.print("String ");
48     if (verbosity == 2)
49       dst.printOptionalIndex(str);
50       }
51     dst.printConstantTersely(str.index, 1);
52   }
53 }
54
Popular Tags