KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > bytecode > CpoolValue1


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_Integer or CONSTANT_Float entry in the constant pool. */
8
9 public class CpoolValue1 extends CpoolEntry
10 {
11   int tag;
12   int value;
13
14   CpoolValue1 (int tag) { this.tag = tag; }
15
16   CpoolValue1 (ConstantPool cpool, int tag, int hash, int value)
17   {
18     super (cpool, hash);
19     this.tag = tag;
20     this.value = value;
21   }
22
23   public int getTag() { return tag; }
24
25   public final int getValue()
26   {
27     return value;
28   }
29
30   static int hashCode (int val) { return val; }
31
32   public int hashCode ()
33   {
34     if (hash == 0)
35       hash = value;
36     return hash;
37   }
38
39   void write (DataOutputStream dstr) throws java.io.IOException JavaDoc
40   {
41     dstr.writeByte (tag);
42     dstr.writeInt (value);
43   }
44
45   public void print (ClassTypeWriter dst, int verbosity)
46   {
47     if (tag == ConstantPool.INTEGER)
48       {
49     if (verbosity > 0)
50       dst.print("Integer ");
51     dst.print(value);
52     if (verbosity > 1 && value != 0)
53       {
54         dst.print("=0x");
55         dst.print(Integer.toHexString(value));
56       }
57       }
58     else // tag == ConstantPool.FLOAT
59
{
60     if (verbosity > 0)
61       dst.print("Float ");
62     dst.print(Float.intBitsToFloat(value));
63     if (verbosity > 1)
64       {
65         dst.print("=0x");
66         dst.print(Integer.toHexString(value));
67       }
68       }
69   }
70 }
71
Popular Tags