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 a float in the constant pool.
012     *
013     * @author Mathias Ricken
014     */
015    public class FloatPoolInfo extends APoolInfo {
016        /**
017         * Data.
018         */
019        private float _floatValue;
020    
021        /**
022         * Constructor.
023         *
024         * @param f data
025         */
026        public FloatPoolInfo(float f, ConstantPool cp) {
027            super(CONSTANT_Float, cp);
028            _floatValue = f;
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 FloatPoolInfo(DataInputStream dis, ConstantPool cp) throws IOException {
040            super(CONSTANT_Float, cp);
041            _floatValue = dis.readFloat();
042        }
043    
044        /**
045         * Accessor for the data.
046         *
047         * @return data
048         */
049        public float getFloatValue() {
050            return _floatValue;
051        }
052    
053        /**
054         * Mutator for the data.
055         *
056         * @param floatValue new data
057         */
058        public void setFloatValue(float floatValue) {
059            _floatValue = floatValue;
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.writeFloat(_floatValue);
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_Float: 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(_floatValue);
108        }
109    
110        /**
111         * Return a hash code.
112         *
113         * @return hash code
114         */
115        public int hashCode() {
116            return new Float(_floatValue).hashCode();
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 FloatPoolInfo) &&
128                (((FloatPoolInfo)obj)._floatValue == _floatValue);
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.floatCase(this, data);
141        }
142    }