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