org.openmali.types.primitives
Class MutableFloat

java.lang.Object
  extended by java.lang.Number
      extended by org.openmali.types.primitives.MutableFloat
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<MutableFloat>

public class MutableFloat
extends java.lang.Number
implements java.lang.Comparable<MutableFloat>

This a mutable derivation of the Float class. Most of the code is borrowed from the Float class.

See Also:
Serialized Form

Constructor Summary
MutableFloat(double value)
          Constructs a newly allocated MutableFloat object that represents the argument converted to type float.
MutableFloat(float value)
          Constructs a newly allocated MutableFloat object that represents the primitive float argument.
MutableFloat(java.lang.String s)
          Constructs a newly allocated MutableFloat object that represents the floating-point value of type float represented by the string.
 
Method Summary
 byte byteValue()
          Returns the value of this MutableFloat as a byte (by casting to a byte).
 int compareTo(MutableFloat anotherFloat)
          Compares two MutableFloat objects numerically.
 double doubleValue()
          Returns the double value of this MutableFloat object.
 boolean equals(java.lang.Object obj)
          Compares this object against the specified object.
 float floatValue()
          Returns the float value of this MutableFloat object.
 int hashCode()
          Returns a hash code for this MutableFloat object.
 int intValue()
          Returns the value of this MutableFloat as an int (by casting to type int).
 boolean isInfinite()
          Returns true if this MutableFloat value is infinitely large in magnitude, false otherwise.
 boolean isNaN()
          Returns true if this MutableFloat value is a Not-a-Number (NaN), false otherwise.
 long longValue()
          Returns value of this MutableFloat as a long (by casting to type long).
 void setValue(float value)
           
 short shortValue()
          Returns the value of this MutableFloat as a short (by casting to a short).
 java.lang.String toString()
          Returns a string representation of this MutableFloat object.
static MutableFloat valueOf(float f)
          Returns a MutableFloat instance representing the specified float value.
static MutableFloat valueOf(java.lang.String s)
          Returns a MutableFloat object holding the float value represented by the argument string s.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MutableFloat

public MutableFloat(float value)
Constructs a newly allocated MutableFloat object that represents the primitive float argument.

Parameters:
value - the value to be represented by the MutableFloat.

MutableFloat

public MutableFloat(double value)
Constructs a newly allocated MutableFloat object that represents the argument converted to type float.

Parameters:
value - the value to be represented by the MutableFloat.

MutableFloat

public MutableFloat(java.lang.String s)
             throws java.lang.NumberFormatException
Constructs a newly allocated MutableFloat object that represents the floating-point value of type float represented by the string. The string is converted to a float value as if by the valueOf method.

Parameters:
s - a string to be converted to a MutableFloat.
Throws:
java.lang.NumberFormatException - if the string does not contain a parsable number.
See Also:
Float.valueOf(java.lang.String)
Method Detail

setValue

public final void setValue(float value)

isNaN

public final boolean isNaN()
Returns true if this MutableFloat value is a Not-a-Number (NaN), false otherwise.

Returns:
true if the value represented by this object is NaN; false otherwise.

isInfinite

public final boolean isInfinite()
Returns true if this MutableFloat value is infinitely large in magnitude, false otherwise.

Returns:
true if the value represented by this object is positive infinity or negative infinity; false otherwise.

toString

public java.lang.String toString()
Returns a string representation of this MutableFloat object. The primitive float value represented by this object is converted to a String exactly as if by the method toString of one argument.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of this object.
See Also:
Float.toString(float)

byteValue

public final byte byteValue()
Returns the value of this MutableFloat as a byte (by casting to a byte).

Overrides:
byteValue in class java.lang.Number
Returns:
the float value represented by this object converted to type byte

shortValue

public final short shortValue()
Returns the value of this MutableFloat as a short (by casting to a short).

Overrides:
shortValue in class java.lang.Number
Returns:
the float value represented by this object converted to type short
Since:
JDK1.1

intValue

public final int intValue()
Returns the value of this MutableFloat as an int (by casting to type int).

Specified by:
intValue in class java.lang.Number
Returns:
the float value represented by this object converted to type int

longValue

public final long longValue()
Returns value of this MutableFloat as a long (by casting to type long).

Specified by:
longValue in class java.lang.Number
Returns:
the float value represented by this object converted to type long

floatValue

public final float floatValue()
Returns the float value of this MutableFloat object.

Specified by:
floatValue in class java.lang.Number
Returns:
the float value represented by this object

doubleValue

public double doubleValue()
Returns the double value of this MutableFloat object.

Specified by:
doubleValue in class java.lang.Number
Returns:
the float value represented by this object is converted to type double and the result of the conversion is returned.

hashCode

public int hashCode()
Returns a hash code for this MutableFloat object. The result is the integer bit representation, exactly as produced by the method Float.floatToIntBits(float), of the primitive float value represented by this MutableFloat object.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object.

equals

public boolean equals(java.lang.Object obj)
Compares this object against the specified object. The result is true if and only if the argument is not null and is a Float object that represents a float with the same value as the float represented by this object. For this purpose, two float values are considered to be the same if and only if the method Float.floatToIntBits(float) returns the identical int value when applied to each.

Note that in most cases, for two instances of class Float, f1 and f2, the value of f1.equals(f2) is true if and only if

   f1.floatValue() == f2.floatValue()
 

also has the value true. However, there are two exceptions:

This definition allows hash tables to operate properly.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to be compared
Returns:
true if the objects are the same; false otherwise.
See Also:
Float.floatToIntBits(float)

compareTo

public int compareTo(MutableFloat anotherFloat)
Compares two MutableFloat objects numerically. There are two ways in which comparisons performed by this method differ from those performed by the Java language numerical comparison operators (<, <=, ==, >= >) when applied to primitive float values: This ensures that the natural ordering of Float objects imposed by this method is consistent with equals.

Specified by:
compareTo in interface java.lang.Comparable<MutableFloat>
Parameters:
anotherFloat - the Float to be compared.
Returns:
the value 0 if anotherFloat is numerically equal to this MutableFloat; a value less than 0 if this MutableFloat is numerically less than anotherFloat; and a value greater than 0 if this MutableFloat is numerically greater than anotherFloat.
Since:
1.2
See Also:
Comparable.compareTo(Object)

valueOf

public static MutableFloat valueOf(java.lang.String s)
                            throws java.lang.NumberFormatException
Returns a MutableFloat object holding the float value represented by the argument string s.

If s is null, then a NullPointerException is thrown.

Leading and trailing whitespace characters in s are ignored. Whitespace is removed as if by the String.trim() method; that is, both ASCII space and control characters are removed. The rest of s should constitute a FloatValue as described by the lexical syntax rules:

FloatValue:
Signopt NaN
Signopt Infinity
Signopt FloatingPointLiteral
Signopt HexFloatingPointLiteral
SignedInteger

HexFloatingPointLiteral:
HexSignificand BinaryExponent FloatTypeSuffixopt

HexSignificand:
HexNumeral
HexNumeral .
0x HexDigitsopt . HexDigits
0X HexDigitsopt . HexDigits

BinaryExponent:
BinaryExponentIndicator SignedInteger

BinaryExponentIndicator:
p
P
where Sign, FloatingPointLiteral, HexNumeral, HexDigits, SignedInteger and FloatTypeSuffix are as defined in the lexical structure sections of the of the Java Language Specification. If s does not have the form of a FloatValue, then a NumberFormatException is thrown. Otherwise, s is regarded as representing an exact decimal value in the usual "computerized scientific notation" or as an exact hexadecimal value; this exact numerical value is then conceptually converted to an "infinitely precise" binary value that is then rounded to type float by the usual round-to-nearest rule of IEEE 754 floating-point arithmetic, which includes preserving the sign of a zero value. Finally, a MutableFloat object representing this float value is returned.

To interpret localized string representations of a floating-point value, use subclasses of java.text.NumberFormat.

Note that trailing format specifiers, specifiers that determine the type of a floating-point literal (1.0f is a float value; 1.0d is a double value), do not influence the results of this method. In other words, the numerical value of the input string is converted directly to the target floating-point type. In general, the two-step sequence of conversions, string to double followed by double to float, is not equivalent to converting a string directly to float. For example, if first converted to an intermediate double and then to float, the string
"1.00000017881393421514957253748434595763683319091796875001d"
results in the float value 1.0000002f; if the string is converted directly to float, 1.0000001f results.

To avoid calling this method on a invalid string and having a NumberFormatException be thrown, the documentation for Double.valueOf(String) lists a regular expression which can be used to screen the input.

Parameters:
s - the string to be parsed.
Returns:
a MutableFloat object holding the value represented by the String argument.
Throws:
java.lang.NumberFormatException - if the string does not contain a parsable number.

valueOf

public static MutableFloat valueOf(float f)
Returns a MutableFloat instance representing the specified float value. If a new MutableFloat instance is not required, this method should generally be used in preference to the constructor MutableFloat(float), as this method is likely to yield significantly better space and time performance by caching frequently requested values.

Parameters:
f - a float value.
Returns:
a MutableFloat instance representing f.
Since:
1.5