001 package edu.rice.cs.cunit.classFile.constantPool;
002
003 import edu.rice.cs.cunit.classFile.constantPool.visitors.IPoolInfoVisitor;
004
005 import java.io.DataInputStream;
006 import java.io.DataOutputStream;
007 import java.io.IOException;
008 import java.util.ArrayList;
009
010 /**
011 * Represents an integer in the constant pool.
012 *
013 * @author Mathias Ricken
014 */
015 public class IntegerPoolInfo extends APoolInfo {
016 /**
017 * Data.
018 */
019 private int _intValue;
020
021 /**
022 * Constructor.
023 *
024 * @param i data
025 */
026 public IntegerPoolInfo(int i, ConstantPool cp) {
027 super(CONSTANT_Integer, cp);
028 _intValue = i;
029 }
030
031 /**
032 * Constructor reading from a stream.
033 *
034 * @param dis input stream
035 * @param cp constant pool
036 *
037 * @throws IOException
038 */
039 public IntegerPoolInfo(DataInputStream dis, ConstantPool cp) throws IOException {
040 super(CONSTANT_Integer, cp);
041 _intValue = dis.readInt();
042 }
043
044 /**
045 * Accessor for the data.
046 *
047 * @return data
048 */
049 public int getIntValue() {
050 return _intValue;
051 }
052
053 /**
054 * Mutator for the data.
055 *
056 * @param intValue new data
057 */
058 public void setIntValue(int intValue) {
059 _intValue = intValue;
060 }
061
062 /**
063 * Write this constant pool object into the stream, including the type byte.
064 *
065 * @param dos stream
066 *
067 * @throws java.io.IOException
068 */
069 public void write(DataOutputStream dos) throws IOException {
070 dos.writeByte(_type);
071 dos.writeInt(_intValue);
072 }
073
074 /**
075 * Resolve constant pool objects. This makes sure that the object links match the index links.
076 */
077 public void resolve() {
078 // do nothing
079 }
080
081 /**
082 * Reindex constant pool indices. This makes sure the index links match the object links.
083 */
084 public void reindex() {
085 // do nothing
086 }
087
088 /**
089 * Return a human-readable version of this constant pool object.
090 *
091 * @return string
092 */
093 public String toStringVerbose() {
094 StringBuilder s = new StringBuilder();
095 s.append("CONSTANT_Integer: Value = ");
096 s.append(toString());
097
098 return s.toString();
099 }
100
101 /**
102 * Return a human-readable version of this constant pool object.
103 *
104 * @return string
105 */
106 public String toString() {
107 return String.valueOf(_intValue);
108 }
109
110 /**
111 * Return a hash code.
112 *
113 * @return hash code
114 */
115 public int hashCode() {
116 return _intValue;
117 }
118
119 /**
120 * Compare this object and another one.
121 *
122 * @param obj other object
123 *
124 * @return true if the same
125 */
126 public boolean equals(Object obj) {
127 return (obj instanceof IntegerPoolInfo) &&
128 (((IntegerPoolInfo)obj)._intValue == _intValue);
129 }
130
131 /**
132 * Execute a visitor.
133 *
134 * @param visitor visitor
135 * @param data visitor-specific parameter
136 *
137 * @return visitor-specific return value
138 */
139 public <R, D> R execute(IPoolInfoVisitor<R, D> visitor, D data) {
140 return visitor.intCase(this, data);
141 }
142 }