com.lmax.api
Class FixedPointNumber

java.lang.Object
  extended by com.lmax.api.FixedPointNumber

public final class FixedPointNumber
extends java.lang.Object

FixedPointNumber class for use with the LMAX API.


Field Summary
static FixedPointNumber ONE
           
static FixedPointNumber TEN
           
static FixedPointNumber ZERO
           
 
Method Summary
 boolean equals(java.lang.Object o)
          Equality is based solely on the long value for this number.
 void format(java.lang.StringBuilder buffer, int scale)
          Populate the supplied StringBuilder with the value of this FixedPointNumber, appending trailing zeros up to the specified scale.
 int hashCode()
          Hashcode is based solely on the long value for this number.
 long longValue()
          Convert this FixedPointNumber to a long value that represents a decimal number with 6 decimal places.
 FixedPointNumber negate()
          Negate this FixedPointNumber.
 long signum()
          Returns the signum function of this FixedPointNumber.
 java.lang.String toString()
          Convert this FixedPointNumber to a String removing trailing zeros.
 void toStringBuilder(java.lang.StringBuilder buffer)
          Populate the supplied CharSequence with the value of this FixedPointNumber.
static FixedPointNumber valueOf(char[] content, int offset, int count)
          Create a new FixedPointNumber based on a string representation of a number within a char[], e.g.
static FixedPointNumber valueOf(java.lang.CharSequence value)
          Create a new FixedPointNumber based on a string representation of a number, e.g.
static FixedPointNumber valueOf(long value)
          Create a new FixedPointNumber based on a long value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static final FixedPointNumber ZERO

ONE

public static final FixedPointNumber ONE

TEN

public static final FixedPointNumber TEN
Method Detail

valueOf

public static FixedPointNumber valueOf(long value)
Create a new FixedPointNumber based on a long value. This represents a value out to six decimal places. E.g. 12345678L represents a price of 12.345678.

Parameters:
value - The value to be represented as a FixedPointNumber.
Returns:
The new FixedPointNumber

valueOf

public static FixedPointNumber valueOf(java.lang.CharSequence value)
Create a new FixedPointNumber based on a string representation of a number, e.g. "12.345678" represents 12.345678

Parameters:
value - The value to be converted into a FixedPointNumber.
Returns:
The new FixedPointNumber

valueOf

public static FixedPointNumber valueOf(char[] content,
                                       int offset,
                                       int count)
Create a new FixedPointNumber based on a string representation of a number within a char[], e.g. "abc12.345678def" with an offset of 3 and count of 9 represents 12.345678

Parameters:
content - The char[] containing the value to be converted into a FixedPointNumber.
offset - The offset into content containing the start of the number.
count - The number of chars in content to use.
Returns:
The new FixedPointNumber

signum

public long signum()
Returns the signum function of this FixedPointNumber.

Returns:
-1, 0, or 1 as the value of this FixedPointNumber is negative, zero, or positive.

negate

public FixedPointNumber negate()
Negate this FixedPointNumber.

Returns:
a new FixedPointNumber that is the negative of this number.

toString

public java.lang.String toString()
Convert this FixedPointNumber to a String removing trailing zeros.

Overrides:
toString in class java.lang.Object
Returns:
a String form for this FixedPointNumber

toStringBuilder

public void toStringBuilder(java.lang.StringBuilder buffer)
Populate the supplied CharSequence with the value of this FixedPointNumber.

Parameters:
buffer - a CharSequence to be populated with the value of this FixedPointNumber

format

public void format(java.lang.StringBuilder buffer,
                   int scale)
Populate the supplied StringBuilder with the value of this FixedPointNumber, appending trailing zeros up to the specified scale.

The scale MUST be greater than or equal to the scale of the FixedPointNumber value - no truncation or rounding will occur, e.g. 12.345 with a scale of 4 will output "12.3450", but a scale of 2 will cause an IllegalArgumentException to be thrown.

Parameters:
buffer - the StringBuilder to append the result to
scale - the scale to ensure the result is formatted to

longValue

public long longValue()
Convert this FixedPointNumber to a long value that represents a decimal number with 6 decimal places. A long value of 1 actually represents a value of 0.000001.

Returns:
a long form for this FixedPointNumber

equals

public boolean equals(java.lang.Object o)
Equality is based solely on the long value for this number.

Overrides:
equals in class java.lang.Object
Parameters:
o - the object to compare
Returns:
true if this FixedPointNumber equals the argument

hashCode

public int hashCode()
Hashcode is based solely on the long value for this number.

Overrides:
hashCode in class java.lang.Object
Returns:
the hashCode