001    package serp.bytecode.lowlevel;
002    
003    import java.io.*;
004    
005    import serp.bytecode.visitor.*;
006    import serp.util.*;
007    
008    /**
009     * A constant int value in the constant pool.
010     *
011     * @author Abe White
012     */
013    public class IntEntry extends Entry implements ConstantEntry {
014        private int _value = -1;
015    
016        /**
017         * Default constructor.
018         */
019        public IntEntry() {
020        }
021    
022        /**
023         * Constructor.
024         *
025         * @param value the constant int value of this entry
026         */
027        public IntEntry(int value) {
028            _value = value;
029        }
030    
031        public int getType() {
032            return Entry.INT;
033        }
034    
035        /**
036         * Return the value of this constant.
037         */
038        public int getValue() {
039            return _value;
040        }
041    
042        /**
043         * Set the value of this constant.
044         */
045        public void setValue(int value) {
046            Object key = beforeModify();
047            _value = value;
048            afterModify(key);
049        }
050    
051        public Object getConstant() {
052            return Numbers.valueOf(getValue());
053        }
054    
055        public void setConstant(Object value) {
056            setValue(((Number) value).intValue());
057        }
058    
059        protected void readData(DataInput in) throws IOException {
060            _value = in.readInt();
061        }
062    
063        protected void writeData(DataOutput out) throws IOException {
064            out.writeInt(_value);
065        }
066    
067        public void acceptVisit(BCVisitor visit) {
068            visit.enterIntEntry(this);
069            visit.exitIntEntry(this);
070        }
071    }