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