View Javadoc

    1   /*
    2    * Copyright  2000-2004 The Apache Software Foundation
    3    *
    4    *  Licensed under the Apache License, Version 2.0 (the "License");
    5    *  you may not use this file except in compliance with the License.
    6    *  You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   *  Unless required by applicable law or agreed to in writing, software
    11   *  distributed under the License is distributed on an "AS IS" BASIS,
    12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   *  See the License for the specific language governing permissions and
    14   *  limitations under the License.
    15   *
    16   */
    17  package org.apache.bcel.classfile;
    18
    19  import java.io.DataInputStream;
    20  import java.io.DataOutputStream;
    21  import java.io.IOException;
    22  import org.apache.bcel.Constants;
    23
    24  /***
    25   * This class is derived from the abstract
    26   * <A HREF="org.apache.bcel.classfile.Constant.html">Constant</A> class
    27   * and represents a reference to a Double object.
    28   *
    29   * @version $Id: ConstantDouble.java 386056 2006-03-15 11:31:56Z tcurdt $
    30   * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
    31   * @see     Constant
    32   */
    33  public final class ConstantDouble extends Constant implements ConstantObject {
    34
    35      private double bytes;
    36
    37
    38      /***
    39       * @param bytes Data
    40       */
    41      public ConstantDouble(double bytes) {
    42          super(Constants.CONSTANT_Double);
    43          this.bytes = bytes;
    44      }
    45
    46
    47      /***
    48       * Initialize from another object.
    49       */
    50      public ConstantDouble(ConstantDouble c) {
    51          this(c.getBytes());
    52      }
    53
    54
    55      /***
    56       * Initialize instance from file data.
    57       *
    58       * @param file Input stream
    59       * @throws IOException
    60       */
    61      ConstantDouble(DataInputStream file) throws IOException {
    62          this(file.readDouble());
    63      }
    64
    65
    66      /***
    67       * Called by objects that are traversing the nodes of the tree implicitely
    68       * defined by the contents of a Java class. I.e., the hierarchy of methods,
    69       * fields, attributes, etc. spawns a tree of objects.
    70       *
    71       * @param v Visitor object
    72       */
    73      public void accept( Visitor v ) {
    74          v.visitConstantDouble(this);
    75      }
    76
    77
    78      /***
    79       * Dump constant double to file stream in binary format.
    80       *
    81       * @param file Output file stream
    82       * @throws IOException
    83       */
    84      public final void dump( DataOutputStream file ) throws IOException {
    85          file.writeByte(tag);
    86          file.writeDouble(bytes);
    87      }
    88
    89
    90      /***
    91       * @return data, i.e., 8 bytes.
    92       */
    93      public final double getBytes() {
    94          return bytes;
    95      }
    96
    97
    98      /***
    99       * @param bytes the raw bytes that represent the double value
    100      */
    101     public final void setBytes( double bytes ) {
    102         this.bytes = bytes;
    103     }
    104
    105
    106     /***
    107      * @return String representation.
    108      */
    109     public final String toString() {
    110         return super.toString() + "(bytes = " + bytes + ")";
    111     }
    112
    113
    114     /*** @return Double object
    115      */
    116     public Object getConstantValue( ConstantPool cp ) {
    117         return new Double(bytes);
    118     }
    119 }