< prev index next >

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

Print this page




  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 float object.
  32  *
  33  * @version $Id$
  34  * @see     Constant
  35  * @LastModified: Jun 2019
  36  */
  37 public final class ConstantFloat extends Constant implements ConstantObject {
  38 
  39     private float bytes;
  40 
  41 
  42     /**
  43      * @param bytes Data
  44      */
  45     public ConstantFloat(final float bytes) {
  46         super(Const.CONSTANT_Float);
  47         this.bytes = bytes;
  48     }
  49 
  50 
  51     /**
  52      * Initialize from another object. Note that both objects use the same
  53      * references (shallow copy). Use clone() for a physical copy.


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


  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 float object.
  32  *

  33  * @see     Constant
  34  * @LastModified: Jun 2019
  35  */
  36 public final class ConstantFloat extends Constant implements ConstantObject {
  37 
  38     private float bytes;
  39 
  40 
  41     /**
  42      * @param bytes Data
  43      */
  44     public ConstantFloat(final float bytes) {
  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.


  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 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 float getBytes() {
 100         return bytes;
 101     }
 102 
 103 
 104     /**
 105      * @param bytes the raw bytes that represent this float
 106      */
 107     public void setBytes( final float bytes ) {
 108         this.bytes = bytes;
 109     }
 110 
 111 
 112     /**
 113      * @return String representation.
 114      */
 115     @Override
 116     public 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 bytes;
 126     }
 127 }
< prev index next >