< prev index next >

src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/ConstantDouble.java

Print this page




   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  You may obtain a copy of the License at
  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 
  21 package com.sun.org.apache.bcel.internal.classfile;
  22 



  23 
  24 import  com.sun.org.apache.bcel.internal.Constants;
  25 import  java.io.*;
  26 
  27 /**
  28  * This class is derived from the abstract
  29  * <A HREF="com.sun.org.apache.bcel.internal.classfile.Constant.html">Constant</A> class
  30  * and represents a reference to a Double object.
  31  *
  32  * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
  33  * @see     Constant
  34  */
  35 public final class ConstantDouble extends Constant implements ConstantObject {

  36   private double bytes;
  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    * Initialize from another object.
  48    */
  49   public ConstantDouble(ConstantDouble c) {
  50     this(c.getBytes());
  51   }
  52 

  53   /**
  54    * Initialize instance from file data.
  55    *
  56    * @param file Input stream
  57    * @throws IOException
  58    */
  59   ConstantDouble(DataInputStream file) throws IOException
  60   {
  61     this(file.readDouble());
  62   }
  63 

  64   /**
  65    * Called by objects that are traversing the nodes of the tree implicitely
  66    * defined by the contents of a Java class. I.e., the hierarchy of methods,
  67    * fields, attributes, etc. spawns a tree of objects.
  68    *
  69    * @param v Visitor object
  70    */
  71   public void accept(Visitor v) {

  72     v.visitConstantDouble(this);
  73   }


  74   /**
  75    * Dump constant double to file stream in binary format.
  76    *
  77    * @param file Output file stream
  78    * @throws IOException
  79    */
  80   public final void dump(DataOutputStream file) throws IOException
  81   {
  82     file.writeByte(tag);
  83     file.writeDouble(bytes);
  84   }


  85   /**
  86    * @return data, i.e., 8 bytes.
  87    */
  88   public final double getBytes() { return bytes; }




  89   /**
  90    * @param bytes.
  91    */
  92   public final void setBytes(double bytes) {
  93     this.bytes = bytes;
  94   }


  95   /**
  96    * @return String representation.
  97    */
  98   public final String toString()
  99   {
 100     return super.toString() + "(bytes = " + bytes + ")";
 101   }
 102 

 103   /** @return Double object
 104    */
 105   public Object getConstantValue(ConstantPool cp) {
 106     return bytes;

 107   }
 108 }


   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  You may obtain a copy of the License at
  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 
  21 package com.sun.org.apache.bcel.internal.classfile;
  22 
  23 import java.io.DataInput;
  24 import java.io.DataOutputStream;
  25 import java.io.IOException;
  26 
  27 import com.sun.org.apache.bcel.internal.Const;

  28 
  29 /**
  30  * This class is derived from the abstract  {@link Constant}

  31  * and represents a reference to a Double object.
  32  *
  33  * @version $Id: ConstantDouble.java 1747278 2016-06-07 17:28:43Z britter $
  34  * @see     Constant
  35  */
  36 public final class ConstantDouble extends Constant implements ConstantObject {
  37 
  38     private double bytes;
  39 
  40 
  41     /**
  42      * @param bytes Data
  43      */
  44     public ConstantDouble(final double bytes) {
  45         super(Const.CONSTANT_Double);
  46         this.bytes = bytes;
  47     }
  48 
  49 
  50     /**
  51      * Initialize from another object.
  52      */
  53     public ConstantDouble(final ConstantDouble c) {
  54         this(c.getBytes());
  55     }
  56 
  57 
  58     /**
  59      * Initialize instance from file data.
  60      *
  61      * @param file Input stream
  62      * @throws IOException
  63      */
  64     ConstantDouble(final DataInput file) throws IOException {

  65         this(file.readDouble());
  66     }
  67 
  68 
  69     /**
  70      * Called by objects that are traversing the nodes of the tree implicitely
  71      * defined by the contents of a Java class. I.e., the hierarchy of methods,
  72      * fields, attributes, etc. spawns a tree of objects.
  73      *
  74      * @param v Visitor object
  75      */
  76     @Override
  77     public void accept( final Visitor v ) {
  78         v.visitConstantDouble(this);
  79     }
  80 
  81 
  82     /**
  83      * Dump constant double to file stream in binary format.
  84      *
  85      * @param file Output file stream
  86      * @throws IOException
  87      */
  88     @Override
  89     public final void dump( final DataOutputStream file ) throws IOException {
  90         file.writeByte(super.getTag());
  91         file.writeDouble(bytes);
  92     }
  93 
  94 
  95     /**
  96      * @return data, i.e., 8 bytes.
  97      */
  98     public final double getBytes() {
  99         return bytes;
 100     }
 101 
 102 
 103     /**
 104      * @param bytes the raw bytes that represent the double value
 105      */
 106     public final void setBytes( final double bytes ) {
 107         this.bytes = bytes;
 108     }
 109 
 110 
 111     /**
 112      * @return String representation.
 113      */
 114     @Override
 115     public final String toString() {
 116         return super.toString() + "(bytes = " + bytes + ")";
 117     }
 118 
 119 
 120     /** @return Double object
 121      */
 122     @Override
 123     public Object getConstantValue( final ConstantPool cp ) {
 124         return new Double(bytes);
 125     }
 126 }
< prev index next >