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