1 16 17 package org.cojen.classfile.constant; 18 19 import java.io.DataOutput ; 20 import java.io.IOException ; 21 import org.cojen.classfile.ConstantInfo; 22 import org.cojen.classfile.ConstantPool; 23 24 30 public class ConstantStringInfo extends ConstantInfo { 31 private final ConstantUTFInfo mStringConstant; 32 33 public ConstantStringInfo(ConstantUTFInfo constant) { 34 super(TAG_STRING); 35 mStringConstant = constant; 36 } 37 38 public ConstantStringInfo(ConstantPool cp, String str) { 39 super(TAG_STRING); 40 mStringConstant = cp.addConstantUTF(str); 41 } 42 43 public String getValue() { 44 return mStringConstant.getValue(); 45 } 46 47 public int hashCode() { 48 return mStringConstant.hashCode(); 49 } 50 51 public boolean equals(Object obj) { 52 if (this == obj) { 53 return true; 54 } 55 if (obj instanceof ConstantStringInfo) { 56 ConstantStringInfo other = (ConstantStringInfo)obj; 57 return mStringConstant.equals(other.mStringConstant); 58 } 59 return false; 60 } 61 62 protected boolean hasPriority() { 63 return true; 64 } 65 66 public void writeTo(DataOutput dout) throws IOException { 67 super.writeTo(dout); 68 dout.writeShort(mStringConstant.getIndex()); 69 } 70 71 public String toString() { 72 return "CONSTANT_String_info: " + getValue(); 73 } 74 } 75 | Popular Tags |