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

  1. /*
  2.  *
  3.  * @(#) LongConstant.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.LongConstant
  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_LONG CPE's </p>
  36.  */
  37.  
  38. class LongConstant extends ConstantPoolEntry {
  39.  
  40.     private long    longish;
  41.  
  42.     /**
  43.      * <p> construct a CONSTANT_LONG </p>
  44.      *
  45.      * @param l        the long constant
  46.      * @param cf    the class file
  47.      */
  48.  
  49.     LongConstant(long l, ClassFile cf) {
  50.         super(CONSTANT_LONG, cf);
  51.     
  52.         longish = l;
  53.  
  54.         addToConstantPool();
  55.     }
  56.  
  57.     /**
  58.      * <p> write the CONSTANT_LONG 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.writeLong(longish);
  68.     }
  69.  
  70.     /**
  71.      * @return the long constant value
  72.      */
  73.  
  74.     long getValue() { return longish; }
  75.  
  76.     /**
  77.      * @return object equality
  78.      */
  79.  
  80.     public boolean equals(Object o) {
  81.         if (o instanceof Long) {
  82.             return longish == ((Long)o).longValue();
  83.         } else if (o instanceof LongConstant) {
  84.             LongConstant lc = (LongConstant)o;
  85.  
  86.             return longish == lc.getValue();
  87.         }
  88.  
  89.         return false;
  90.     }
  91.  
  92.     /**
  93.      * @return a hashcode for the object.
  94.      */
  95.     public int hashCode() {
  96.     return (int)longish;    
  97.     }
  98. }
  99.