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