home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 July / Chip_1998-07_cd.bin / zkuste / JBuilder / BDK / Win / bdk_sep97.exe / _SETUP.1 / UTF8Constant.java < prev    next >
Encoding:
Java Source  |  1997-09-10  |  2.3 KB  |  109 lines

  1. /*
  2.  *
  3.  * @(#) UTF8Constant.java 1.4@(#)
  4.  *
  5.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  6.  * 
  7.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  8.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  9.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  10.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  11.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  12.  * THIS SOFTWARE OR ITS DERIVATIVES.
  13.  * 
  14.  */
  15.  
  16. /**
  17.  * <p>
  18.  * sunw.demo.classfile.UTF8Constant
  19.  * </p> 
  20.  *
  21.  * @version 1.0
  22.  * @author Laurence P. G. Cable
  23.  */
  24.  
  25.  
  26. package sunw.demo.classfile;
  27.  
  28. import java.io.DataOutputStream;
  29. import java.io.IOException;
  30.  
  31. import sunw.demo.classfile.ClassFile;
  32. import sunw.demo.classfile.ConstantPoolEntry;
  33.  
  34. /**
  35.  * <p> this class provides minimal support for CONSTANT_UTF8 CPE's </p>
  36.  */
  37.  
  38. class UTF8Constant extends ConstantPoolEntry {
  39.  
  40.     private String string;
  41.  
  42.     /**
  43.      * <p> construct a CONSTANT_UTF8 CPE </p>
  44.      *
  45.      * @param s     the string
  46.      * @param cf    the class file
  47.      */
  48.  
  49.     UTF8Constant(String s, ClassFile cf) {
  50.         super(CONSTANT_UTF8, cf);
  51.     
  52.         string = s;
  53.  
  54.         addToConstantPool();
  55.     }
  56.  
  57.     /**
  58.      * <p> construct a CONSTANT_UTF8 CPE </p>
  59.      * This variant is used when the ClassFile is doing the "new"
  60.      * and already knows the intended index.
  61.      *
  62.      * @param s     the string
  63.      * @param cf    the class file
  64.      * @param index    the constant pool index.
  65.      */
  66.     UTF8Constant(String s, ClassFile cf, short index) {
  67.         super(CONSTANT_UTF8, cf, index);
  68.         string = s;
  69.     }
  70.  
  71.     /**
  72.      * <p> write the CPE to the output stream </p>
  73.      *
  74.      * @param dos the output stream
  75.      *
  76.      * @throws IOException
  77.      */
  78.  
  79.     void write(DataOutputStream dos) throws IOException {
  80.         dos.writeByte(getTag());
  81.         dos.writeUTF(string);
  82.     }
  83.  
  84.     /**
  85.      * @return the string constant
  86.      */
  87.  
  88.     String getString() { return string; }
  89.  
  90.     /**
  91.      * @return object equality
  92.      */
  93.  
  94.     public boolean equals(Object o) {
  95.         if (o instanceof UTF8Constant) {
  96.             return string.equals(((UTF8Constant)o).getString());
  97.         }
  98.  
  99.         return false;
  100.     }
  101.  
  102.     /**
  103.      * @return a hashcode for the object.
  104.      */
  105.     public int hashCode() {
  106.     return string.hashCode();    
  107.     }
  108. }
  109.