106 lines
2.8 KiB
Java
106 lines
2.8 KiB
Java
package com.de22.javabytecode.constant;
|
|
|
|
import java.io.IOException;
|
|
import com.de22.javabytecode.*;
|
|
|
|
/**
|
|
* Copyright Wynne Crisman 1999,2006<p>
|
|
*/
|
|
public class ConstantFloat extends Constant {
|
|
private float value = 0;
|
|
/**
|
|
* ConstantType constructor.
|
|
* @param type The class this constant is a member of.
|
|
*/
|
|
public ConstantFloat(Type type) {
|
|
super(type);
|
|
}//ConstantFloat()//
|
|
/**
|
|
* ConstantType constructor.
|
|
* @param type The class this constant is a member of.
|
|
* @param value The value of the constant.
|
|
*/
|
|
public ConstantFloat(Type type, float value) {
|
|
super(type);
|
|
|
|
this.value = value;
|
|
}//ConstantFloat()//
|
|
/**
|
|
* Gets the value for this associated with this constant.
|
|
* @return The float value.
|
|
*/
|
|
public float getValue() {
|
|
return value;
|
|
}//getValue()//
|
|
/**
|
|
* Determines whether the two objects are logically equal.
|
|
* @param object The object to compare with this object.
|
|
* @return Whether they are logically equal.
|
|
*/
|
|
public boolean equals(Object object) {
|
|
return (object instanceof ConstantFloat) && (value == ((ConstantFloat) object).value);
|
|
}//equals()//
|
|
/**
|
|
* Gets the size in number of bytes of the component and all subcomponents.
|
|
* @return The number of bytes required to represent the component and all subcomponents.
|
|
*/
|
|
public int getSize() {
|
|
return 4;
|
|
}//getSize()//
|
|
/**
|
|
* Gets this class' identifying constant.
|
|
* @return The constant value that identifies this constant object type.
|
|
*/
|
|
public byte getTag() {
|
|
return CONSTANT_FLOAT;
|
|
}//getTag()//
|
|
/**
|
|
* Gets the hash code for the constant.
|
|
* @return The constant hash code.
|
|
*/
|
|
public int hashCode() {
|
|
return Float.floatToIntBits(value);
|
|
}//hashCode()//
|
|
/**
|
|
* Reads this object from the given stream.
|
|
* @param in The input stream to read this object from.
|
|
*/
|
|
public void readExternal(java.io.ObjectInput in) throws IOException, ClassNotFoundException {
|
|
super.readExternal(in);
|
|
|
|
value = in.readFloat();
|
|
}//readExternal()//
|
|
/**
|
|
* Gets a string representation of this object.
|
|
* @return A string that represents this object.
|
|
*/
|
|
public String toString() {
|
|
return "Float: " + Float.toString(value);
|
|
}//toString()//
|
|
/* (non-Javadoc)
|
|
* @see com.de22.javabytecode.Constant#getPrettyValue()
|
|
*/
|
|
public String getPrettyValue() {
|
|
return Float.toString(value) + " (Float)";
|
|
}//getPrettyValue()//
|
|
/**
|
|
* @see Component.toString(StringBuffer, int)
|
|
*/
|
|
public void toString(StringBuffer buffer, int tabCount) {
|
|
appendTabs(buffer, tabCount);
|
|
buffer.append("Float Constant (");
|
|
buffer.append(value);
|
|
buffer.append(')');
|
|
appendEndOfLine(buffer);
|
|
}//toString()//
|
|
/**
|
|
* Writes this object to the given stream.
|
|
* @param out The output stream to write this object to.
|
|
*/
|
|
public void writeExternal(java.io.ObjectOutput out) throws IOException {
|
|
super.writeExternal(out);
|
|
|
|
out.writeFloat(value);
|
|
}//writeExternal()//
|
|
}//ConstantFloat//
|