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 an integer in the constant pool.
011     *
012     * @author Mathias Ricken
013     */
014    public class IntegerPoolInfo extends APoolInfo {
015        /**
016         * Data.
017         */
018        private int _intValue;
019    
020        /**
021         * Constructor.
022         *
023         * @param i data
024         */
025        public IntegerPoolInfo(int i, ConstantPool cp) {
026            super(CONSTANT_Integer, cp);
027            _intValue = i;
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 IntegerPoolInfo(DataInputStream dis, ConstantPool cp) throws IOException {
039            super(CONSTANT_Integer, cp);
040            _intValue = dis.readInt();
041        }
042    
043        /**
044         * Accessor for the data.
045         *
046         * @return data
047         */
048        public int getIntValue() {
049            return _intValue;
050        }
051    
052        /**
053         * Mutator for the data.
054         *
055         * @param intValue new data
056         */
057        public void setIntValue(int intValue) {
058            _intValue = intValue;
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.writeInt(_intValue);
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_Integer: Value = ");
097            s.append(_intValue);
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 _intValue;
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 IntegerPoolInfo) &&
129                (((IntegerPoolInfo)obj)._intValue == _intValue);
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.intCase(this, data);
142        }
143    }