KickJava   Java API By Example, From Geeks To Geeks.

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


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     Base class for numeric constant pool data structures.
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 abstract class ConstantNumeric extends CPInfo {
22
23     /** Length of the constant pool data structure in bytes. */
24     public static final int SIZE = 4;
25     
26     /** <tt>bytes</tt> field. */
27     protected int bytes;
28     
29     /**
30         Get the <tt>bytes</tt> field of this constant pool entry.
31         @return the <tt>bytes</tt> field
32      */

33     public int getBytes() {
34         return bytes;
35     }
36
37     /**
38         Set the <tt>bytes</tt> field of this constant pool entry.
39         @param bytes the <tt>bytes</tt> field
40      */

41     public void setBytes(int bytes) {
42         this.bytes = bytes;
43     }
44
45     /**
46         Get the the <tt>bytes</tt> field of this constant pool
47         entry as a hex string.
48         @return the hex string
49      */

50     public String JavaDoc getFormattedBytes() {
51         return printBytes(bytes);
52     }
53
54     public void read(DataInput in)
55         throws InvalidByteCodeException, IOException {
56             
57         bytes = in.readInt();
58     }
59     
60     public void write(DataOutput out)
61         throws InvalidByteCodeException, IOException {
62         
63         out.writeInt(bytes);
64     }
65     
66     public boolean equals(Object JavaDoc object) {
67         if (!(object instanceof ConstantNumeric)) {
68             return false;
69         }
70         ConstantNumeric constantNumeric = (ConstantNumeric)object;
71         return super.equals(object) && constantNumeric.bytes == bytes;
72     }
73
74     public int hashCode() {
75         return super.hashCode() ^ bytes;
76     }
77     
78 }
79
Popular Tags