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 double in the constant pool.
011 *
012 * @author Mathias Ricken
013 */
014 public class DoublePoolInfo extends APoolInfo {
015 /**
016 * Data.
017 */
018 private double _doubleValue;
019
020 /**
021 * Constructor.
022 *
023 * @param d data
024 */
025 public DoublePoolInfo(double d, ConstantPool cp) {
026 super(CONSTANT_Double, cp);
027 _doubleValue = d;
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 DoublePoolInfo(DataInputStream dis, ConstantPool cp) throws IOException {
039 super(CONSTANT_Double, cp);
040 _doubleValue = dis.readDouble();
041 }
042
043 /**
044 * Accessor for the data.
045 *
046 * @return data
047 */
048 public double getDoubleValue() {
049 return _doubleValue;
050 }
051
052 /**
053 * Mutator for the data.
054 *
055 * @param doubleValue new data
056 */
057 public void setDoubleValue(double doubleValue) {
058 _doubleValue = doubleValue;
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.writeDouble(_doubleValue);
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_Double: Value = ");
097 s.append(_doubleValue);
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 Double(_doubleValue).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 DoublePoolInfo) &&
129 (((DoublePoolInfo)obj)._doubleValue == _doubleValue);
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.doubleCase(this, data);
142 }
143 }