jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/ConstantFloat.java
changeset 46174 5611d2529b49
parent 45853 bfa06be36a17
equal deleted inserted replaced
46173:5546b5710844 46174:5611d2529b49
    18  * limitations under the License.
    18  * limitations under the License.
    19  */
    19  */
    20 
    20 
    21 package com.sun.org.apache.bcel.internal.classfile;
    21 package com.sun.org.apache.bcel.internal.classfile;
    22 
    22 
       
    23 import java.io.DataInput;
       
    24 import java.io.DataOutputStream;
       
    25 import java.io.IOException;
    23 
    26 
    24 import com.sun.org.apache.bcel.internal.Constants;
    27 import com.sun.org.apache.bcel.internal.Const;
    25 import java.io.*;
       
    26 
    28 
    27 /**
    29 /**
    28  * This class is derived from the abstract
    30  * This class is derived from the abstract {@link Constant}
    29  * <A HREF="com.sun.org.apache.bcel.internal.classfile.Constant.html">Constant</A> class
       
    30  * and represents a reference to a float object.
    31  * and represents a reference to a float object.
    31  *
    32  *
    32  * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
    33  * @version $Id: ConstantFloat.java 1747278 2016-06-07 17:28:43Z britter $
    33  * @see     Constant
    34  * @see     Constant
    34  */
    35  */
    35 public final class ConstantFloat extends Constant implements ConstantObject {
    36 public final class ConstantFloat extends Constant implements ConstantObject {
    36   private float bytes;
       
    37 
    37 
    38   /**
    38     private float bytes;
    39    * @param bytes Data
       
    40    */
       
    41   public ConstantFloat(float bytes)
       
    42   {
       
    43     super(Constants.CONSTANT_Float);
       
    44     this.bytes = bytes;
       
    45   }
       
    46   /**
       
    47    * Initialize from another object. Note that both objects use the same
       
    48    * references (shallow copy). Use clone() for a physical copy.
       
    49    */
       
    50   public ConstantFloat(ConstantFloat c) {
       
    51     this(c.getBytes());
       
    52   }
       
    53   /**
       
    54    * Initialize instance from file data.
       
    55    *
       
    56    * @param file Input stream
       
    57    * @throws IOException
       
    58    */
       
    59   ConstantFloat(DataInputStream file) throws IOException
       
    60   {
       
    61     this(file.readFloat());
       
    62   }
       
    63   /**
       
    64    * Called by objects that are traversing the nodes of the tree implicitely
       
    65    * defined by the contents of a Java class. I.e., the hierarchy of methods,
       
    66    * fields, attributes, etc. spawns a tree of objects.
       
    67    *
       
    68    * @param v Visitor object
       
    69    */
       
    70   public void accept(Visitor v) {
       
    71     v.visitConstantFloat(this);
       
    72   }
       
    73   /**
       
    74    * Dump constant float to file stream in binary format.
       
    75    *
       
    76    * @param file Output file stream
       
    77    * @throws IOException
       
    78    */
       
    79   public final void dump(DataOutputStream file) throws IOException
       
    80   {
       
    81     file.writeByte(tag);
       
    82     file.writeFloat(bytes);
       
    83   }
       
    84   /**
       
    85    * @return data, i.e., 4 bytes.
       
    86    */
       
    87   public final float getBytes() { return bytes; }
       
    88   /**
       
    89    * @param bytes.
       
    90    */
       
    91   public final void setBytes(float bytes) {
       
    92     this.bytes = bytes;
       
    93   }
       
    94 
    39 
    95   /**
       
    96    * @return String representation.
       
    97    */
       
    98   public final String toString() {
       
    99     return super.toString() + "(bytes = " + bytes + ")";
       
   100   }
       
   101 
    40 
   102   /** @return Float object
    41     /**
   103    */
    42      * @param bytes Data
   104   public Object getConstantValue(ConstantPool cp) {
    43      */
   105     return bytes;
    44     public ConstantFloat(final float bytes) {
   106   }
    45         super(Const.CONSTANT_Float);
       
    46         this.bytes = bytes;
       
    47     }
       
    48 
       
    49 
       
    50     /**
       
    51      * Initialize from another object. Note that both objects use the same
       
    52      * references (shallow copy). Use clone() for a physical copy.
       
    53      */
       
    54     public ConstantFloat(final ConstantFloat c) {
       
    55         this(c.getBytes());
       
    56     }
       
    57 
       
    58 
       
    59     /**
       
    60      * Initialize instance from file data.
       
    61      *
       
    62      * @param file Input stream
       
    63      * @throws IOException
       
    64      */
       
    65     ConstantFloat(final DataInput file) throws IOException {
       
    66         this(file.readFloat());
       
    67     }
       
    68 
       
    69 
       
    70     /**
       
    71      * Called by objects that are traversing the nodes of the tree implicitely
       
    72      * defined by the contents of a Java class. I.e., the hierarchy of methods,
       
    73      * fields, attributes, etc. spawns a tree of objects.
       
    74      *
       
    75      * @param v Visitor object
       
    76      */
       
    77     @Override
       
    78     public void accept( final Visitor v ) {
       
    79         v.visitConstantFloat(this);
       
    80     }
       
    81 
       
    82 
       
    83     /**
       
    84      * Dump constant float to file stream in binary format.
       
    85      *
       
    86      * @param file Output file stream
       
    87      * @throws IOException
       
    88      */
       
    89     @Override
       
    90     public final void dump( final DataOutputStream file ) throws IOException {
       
    91         file.writeByte(super.getTag());
       
    92         file.writeFloat(bytes);
       
    93     }
       
    94 
       
    95 
       
    96     /**
       
    97      * @return data, i.e., 4 bytes.
       
    98      */
       
    99     public final float getBytes() {
       
   100         return bytes;
       
   101     }
       
   102 
       
   103 
       
   104     /**
       
   105      * @param bytes the raw bytes that represent this float
       
   106      */
       
   107     public final void setBytes( final float bytes ) {
       
   108         this.bytes = bytes;
       
   109     }
       
   110 
       
   111 
       
   112     /**
       
   113      * @return String representation.
       
   114      */
       
   115     @Override
       
   116     public final String toString() {
       
   117         return super.toString() + "(bytes = " + bytes + ")";
       
   118     }
       
   119 
       
   120 
       
   121     /** @return Float object
       
   122      */
       
   123     @Override
       
   124     public Object getConstantValue( final ConstantPool cp ) {
       
   125         return new Float(bytes);
       
   126     }
   107 }
   127 }