ConstantFloat.java revision 286
0N/A/*
0N/A * reserved comment block
0N/A * DO NOT REMOVE OR ALTER!
0N/A */
0N/Apackage com.sun.org.apache.bcel.internal.classfile;
0N/A
0N/A/* ====================================================================
0N/A * The Apache Software License, Version 1.1
0N/A *
0N/A * Copyright (c) 2001 The Apache Software Foundation. All rights
0N/A * reserved.
0N/A *
0N/A * Redistribution and use in source and binary forms, with or without
0N/A * modification, are permitted provided that the following conditions
0N/A * are met:
0N/A *
0N/A * 1. Redistributions of source code must retain the above copyright
0N/A * notice, this list of conditions and the following disclaimer.
0N/A *
0N/A * 2. Redistributions in binary form must reproduce the above copyright
0N/A * notice, this list of conditions and the following disclaimer in
0N/A * the documentation and/or other materials provided with the
0N/A * distribution.
0N/A *
0N/A * 3. The end-user documentation included with the redistribution,
0N/A * if any, must include the following acknowledgment:
0N/A * "This product includes software developed by the
0N/A * Apache Software Foundation (http://www.apache.org/)."
0N/A * Alternately, this acknowledgment may appear in the software itself,
0N/A * if and wherever such third-party acknowledgments normally appear.
0N/A *
0N/A * 4. The names "Apache" and "Apache Software Foundation" and
0N/A * "Apache BCEL" must not be used to endorse or promote products
0N/A * derived from this software without prior written permission. For
0N/A * written permission, please contact apache@apache.org.
0N/A *
0N/A * 5. Products derived from this software may not be called "Apache",
0N/A * "Apache BCEL", nor may "Apache" appear in their name, without
0N/A * prior written permission of the Apache Software Foundation.
0N/A *
0N/A * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0N/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0N/A * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
0N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1183N/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
1183N/A * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
1183N/A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
1183N/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
0N/A * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0N/A * SUCH DAMAGE.
0N/A * ====================================================================
0N/A *
0N/A * This software consists of voluntary contributions made by many
0N/A * individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import com.sun.org.apache.bcel.internal.Constants;
import java.io.*;
/**
* This class is derived from the abstract
* <A HREF="com.sun.org.apache.bcel.internal.classfile.Constant.html">Constant</A> class
* and represents a reference to a float object.
*
* @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
* @see Constant
*/
public final class ConstantFloat extends Constant implements ConstantObject {
private float bytes;
/**
* @param bytes Data
*/
public ConstantFloat(float bytes)
{
super(Constants.CONSTANT_Float);
this.bytes = bytes;
}
/**
* Initialize from another object. Note that both objects use the same
* references (shallow copy). Use clone() for a physical copy.
*/
public ConstantFloat(ConstantFloat c) {
this(c.getBytes());
}
/**
* Initialize instance from file data.
*
* @param file Input stream
* @throws IOException
*/
ConstantFloat(DataInputStream file) throws IOException
{
this(file.readFloat());
}
/**
* Called by objects that are traversing the nodes of the tree implicitely
* defined by the contents of a Java class. I.e., the hierarchy of methods,
* fields, attributes, etc. spawns a tree of objects.
*
* @param v Visitor object
*/
public void accept(Visitor v) {
v.visitConstantFloat(this);
}
/**
* Dump constant float to file stream in binary format.
*
* @param file Output file stream
* @throws IOException
*/
public final void dump(DataOutputStream file) throws IOException
{
file.writeByte(tag);
file.writeFloat(bytes);
}
/**
* @return data, i.e., 4 bytes.
*/
public final float getBytes() { return bytes; }
/**
* @param bytes.
*/
public final void setBytes(float bytes) {
this.bytes = bytes;
}
/**
* @return String representation.
*/
public final String toString() {
return super.toString() + "(bytes = " + bytes + ")";
}
/** @return Float object
*/
public Object getConstantValue(ConstantPool cp) {
return new Float(bytes);
}
}