CpoolValue1.java 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (c) 1997 Per M.A. Bothner.
  2. // This is free software; for terms and warranty disclaimer see ./COPYING.
  3. package gnu.bytecode;
  4. import java.io.*;
  5. /** A CONSTANT_Integer or CONSTANT_Float entry in the constant pool. */
  6. public class CpoolValue1 extends CpoolEntry
  7. {
  8. int tag;
  9. int value;
  10. CpoolValue1 (int tag) { this.tag = tag; }
  11. CpoolValue1 (ConstantPool cpool, int tag, int hash, int value)
  12. {
  13. super (cpool, hash);
  14. this.tag = tag;
  15. this.value = value;
  16. }
  17. public int getTag() { return tag; }
  18. public final int getValue()
  19. {
  20. return value;
  21. }
  22. static int hashCode (int val) { return val; }
  23. public int hashCode ()
  24. {
  25. if (hash == 0)
  26. hash = value;
  27. return hash;
  28. }
  29. void write (DataOutputStream dstr) throws java.io.IOException
  30. {
  31. dstr.writeByte (tag);
  32. dstr.writeInt (value);
  33. }
  34. public void print (ClassTypeWriter dst, int verbosity)
  35. {
  36. if (tag == ConstantPool.INTEGER)
  37. {
  38. if (verbosity > 0)
  39. dst.print("Integer ");
  40. dst.print(value);
  41. if (verbosity > 1 && value != 0)
  42. {
  43. dst.print("=0x");
  44. dst.print(Integer.toHexString(value));
  45. }
  46. }
  47. else // tag == ConstantPool.FLOAT
  48. {
  49. if (verbosity > 0)
  50. dst.print("Float ");
  51. dst.print(Float.intBitsToFloat(value));
  52. if (verbosity > 1)
  53. {
  54. dst.print("=0x");
  55. dst.print(Integer.toHexString(value));
  56. }
  57. }
  58. }
  59. }