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

  1. /*
  2.  *
  3.  * @(#) FloatConstant.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.FloatConstant
  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> provides minimal support for FLOAT_CONSTANT CPE </p>
  36.   */
  37.  
  38. class FloatConstant extends ConstantPoolEntry {
  39.  
  40.     private float    floating;
  41.  
  42.     /**
  43.      * <p> construct a CONSTANT_FLOAT </p>
  44.      *
  45.      * @param f        the float value
  46.      * @param cf    the class file
  47.      */
  48.  
  49.     FloatConstant(float f, ClassFile cf) {
  50.         super(CONSTANT_FLOAT, cf);
  51.     
  52.         floating = f;
  53.  
  54.         addToConstantPool();
  55.     }
  56.  
  57.     /**
  58.      * <p> write the CONSTANT_FLOAT to the stream </p>
  59.      *
  60.      * @param dos     the output stream
  61.      *
  62.      * @throws    IOException
  63.      */
  64.  
  65.     void write(DataOutputStream dos) throws IOException {
  66.         dos.writeByte(getTag());
  67.         dos.writeFloat(floating);
  68.     }
  69.  
  70.     /**
  71.      * <p> return the value of the constant </p>
  72.      *
  73.      * @return the value of the CONSTANT_FLOAT
  74.      */
  75.  
  76.     float getValue() { return floating; }
  77.  
  78.     /**
  79.      * @return object equality
  80.      */
  81.  
  82.     public boolean equals(Object o) {
  83.         if (o instanceof Float) {
  84.             return floating == ((Float)o).floatValue();
  85.         } else if (o instanceof FloatConstant) {
  86.             FloatConstant fc = (FloatConstant)o;
  87.  
  88.             return floating == fc.getValue();
  89.         }
  90.  
  91.         return false;
  92.     }
  93.  
  94.     /**
  95.      * @return a hashcode for the object.
  96.      */
  97.     public int hashCode() {
  98.     return (int)floating;    
  99.     }
  100. }
  101.