edu.neu.ccs
Class XBigDecimal

java.lang.Object
  extended byedu.neu.ccs.XObject
      extended byedu.neu.ccs.XNumber
          extended byedu.neu.ccs.XBigDecimal
All Implemented Interfaces:
Cloneable, Serializable, Stringable

public class XBigDecimal
extends XNumber

XBigDecimal is an object wrapper for the arbitrary precision BigDecimal class, that also provides Stringable capabilities. Hence, unlike BigDecimal, objects of this class are mutable.

The default value for this class is the BigDecimal representation of zero.

This class provides the operations of the class BigDecimal in two forms. Member methods will mutate the object that is operated on but leave all parameters unchanged and will return void. Static methods will create new objects and change no parameters. In all cases, if an argument to an operation is null, it is treated as zero.

Unlike simpler Stringable numeric types, XBigDecimal does not support the evaluation of arithmetic expressions when parsing input from String data. The reason for this is that division normally requires a rounding mode and it would be quite awkward to supply that mode interactively in the midst of an expression.

Since:
1.0
Version:
2.4.0
See Also:
Serialized Form

Field Summary
static int ROUND_CEILING
          Rounding mode to round towards positive infinity.
static int ROUND_DOWN
          Rounding mode to round towards zero.
static int ROUND_FLOOR
          Rounding mode to round towards negative infinity.
static int ROUND_HALF_DOWN
          Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case round down.
static int ROUND_HALF_EVEN
          Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.
static int ROUND_HALF_UP
          Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case round up.
static int ROUND_UNNECESSARY
          Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary.
static int ROUND_UP
          Rounding mode to round away from zero.
private  BigDecimal value
          The wrapped value of this object.
private static BigDecimal ZERO
          The zero BigDecimal.
 
Fields inherited from class edu.neu.ccs.XObject
changeAdapter, VALUE
 
Constructor Summary
XBigDecimal()
          Constructs a wrapper for the default BigDecimal value of zero.
XBigDecimal(BigDecimal b)
          Constructs a wrapper for the given BigDecimal value.
XBigDecimal(double x)
          Translates a double into an XBigDecimal.
XBigDecimal(long x)
          Translates a long x into an XBigDecimal that is mathematically equal to x.
XBigDecimal(long x, int scale)
          Translates a long x and a scale into an XBigDecimal that is mathematically equal to x/10scale.
XBigDecimal(String s)
          Constructs an XBigDecimal using the information contained in the given string data.
XBigDecimal(XBigDecimal b)
          Constructs an XBigDecimal by copying the internal value of the given XBigDecimal.
XBigDecimal(XBigInteger x)
          Translates an XBigInteger x into an XBigDecimal that is mathematically equal to x.
XBigDecimal(XBigInteger x, int scale)
          Translates an XBigInteger x and a scale into an XBigDecimal that is mathematically equal to x/10scale.
 
Method Summary
 void abs()
          Sets this to abs(this).
static XBigDecimal abs(XBigDecimal y)
          Returns a new XBigDecimal whose value is the absolute value of the given y.
 void add(XBigDecimal y)
          Sets this to (this + y).
static XBigDecimal add(XBigDecimal x, XBigDecimal y)
          Returns a new XBigDecimal whose value is x + y.
 byte byteValue()
          Returns the value of this number as a byte value.
 int compareTo(Object o)
          Compares this XBigDecimal with the specified Object o.
 int compareTo(XBigDecimal y)
          Compares this XBigDecimal with the specified XBigDecimal y.
 void divide(XBigDecimal y, int roundingMode)
          Sets this to (this / y) and maintains the scale as this.scale().
 void divide(XBigDecimal y, int scale, int roundingMode)
          Sets this to (this / y) using the given scale for the quotient.
static XBigDecimal divide(XBigDecimal x, XBigDecimal y, int roundingMode)
          Returns a new XBigDecimal whose value is x / y and whose scale is x.scale().
static XBigDecimal divide(XBigDecimal x, XBigDecimal y, int scale, int roundingMode)
          Returns a new XBigDecimal whose value is x / y and whose scale is the given scale.
 double doubleValue()
          Returns the value of this number as a double value.
 boolean equals(Object other)
          Returns true if the given object is of type XBigDecimal and its BigDecimal value is equal to the BigDecimal value of this XBigDecimal; returns false otherwise.
 float floatValue()
          Returns the value of this number as a float value.
 void fromStringData(String data)
          Sets the state of this XBigDecimal using the information contained in the given string data.
 BigDecimal getValue()
          Returns the BigDecimal value wrapped by this object.
 int hashCode()
          Returns the int hash code of the wrapped BigDecimal value.
 int intValue()
          Returns the value of this number as a int value.
static boolean isRoundingMode(int roundingMode)
          Returns true if the rounding mode is valid; otherwise false.
 long longValue()
          Returns the value of this number as a long value.
 void max(XBigDecimal y)
          Sets this to max(this, y).
static XBigDecimal max(XBigDecimal x, XBigDecimal y)
          Returns a new XBigDecimal whose value is the maximum of the given x and y values.
 void min(XBigDecimal y)
          Sets this to min(this, y).
static XBigDecimal min(XBigDecimal x, XBigDecimal y)
          Returns a new XBigDecimal whose value is the minimum of the given x and y values.
 void movePointLeft(int n)
          Sets this to an XBigDecimal that is equivalent to this with the decimal point moved n places to the left.
static XBigDecimal movePointLeft(XBigDecimal y, int n)
          Returns a new XBigDecimal that is equivalent to the given y with the decimal point moved n places to the left.
 void movePointRight(int n)
          Sets this to an XBigDecimal that is equivalent to this with the decimal point moved n places to the right.
static XBigDecimal movePointRight(XBigDecimal y, int n)
          Returns a new XBigDecimal that is equivalent to the given y with the decimal point moved n places to the right.
 void multiply(XBigDecimal y)
          Sets this to (this * y).
static XBigDecimal multiply(XBigDecimal x, XBigDecimal y)
          Returns a new XBigDecimal whose value is x * y.
 void negate()
          Sets this to (-this).
static XBigDecimal negate(XBigDecimal y)
          Returns a new XBigDecimal whose value is the negation of the given y.
 int scale()
          Returns the scale of this XBigDecimal.
 void setScale(int scale)
          Sets this to a numerically equal value whose scale is the given scale.
 void setScale(int scale, int roundingMode)
          Sets this to an XBigDecimal whose scale is the given scale and whose unscaled value is determined by multiplying or dividing the unscaled value of this by the appropriate power of ten to maintain its overall value; if the scale is reduced by the operation, the unscaled value must be divided (rather than multiplied), and the value may be changed; in this case, the specified rounding mode is applied to the division.
static XBigDecimal setScale(XBigDecimal y, int scale)
          Returns a new XBigDecimal whose scale is the given scale and whose value is numerically equal to the given y.
static XBigDecimal setScale(XBigDecimal y, int scale, int roundingMode)
          Returns a new XBigDecimal whose scale is the given scale and whose unscaled value is determined by multiplying or dividing the unscaled value of the given y by the appropriate power of ten to maintain its overall value; if the scale is reduced by the operation, the unscaled value must be divided (rather than multiplied), and the value may be changed; in this case, the specified rounding mode is applied to the division.
 void setValue(BigDecimal b)
          Sets the value wrapped by this object to the given BigDecimal value.
 void setValue(double x)
          Translates a double into an XBigDecimal that is then set as the value of this.
 void setValue(long x)
          Translates a long x into an XBigDecimal that is mathematically equal to x.
 void setValue(long x, int scale)
          Translates a long x and a scale into an XBigDecimal that is mathematically equal to x/10scale.
 void setValue(String data)
          Sets the state of this XBigDecimal using the information contained in the given string data.
 void setValue(XBigDecimal b)
          Sets the value wrapped by this object to the internal value of the given XBigDecimal value.
 void setValue(XBigInteger x)
          Translates an XBigInteger x into an XBigDecimal that is mathematically equal to x.
 void setValue(XBigInteger x, int scale)
          Translates an XBigInteger x and a scale into an XBigDecimal that is mathematically equal to x/10scale.
 short shortValue()
          Returns the value of this number as a short value.
 int signum()
          Returns -1, 0 or 1 as the value of this XBigDecimal is negative, zero or positive.
 void subtract(XBigDecimal y)
          Sets this to (this - y).
static XBigDecimal subtract(XBigDecimal x, XBigDecimal y)
          Returns a new XBigDecimal whose value is x - y.
static BigDecimal[] toPrimitiveArray(XBigDecimal[] x)
          Returns an array of BigDecimal objects copied from the given array of XBigDecimal objects.
 String toString()
          Returns the string representation of the wrapped BigDecimal value.
 String toStringData()
          Returns a string encapsulation of this XBigDecimal that contains the information needed to set the state of this XBigDecimal at a later time.
 XBigInteger toUnscaledXBigInteger()
          Returns an XBigInteger whose value is the unscaled value of this XBigDecimal.
static XBigDecimal[] toXArray(BigDecimal[] a)
          Returns an array of XBigDecimal objects initialized from the given array of BigDecimal objects.
 XBigInteger toXBigInteger()
          Converts this XBigDecimal to an XBigInteger by truncation, that is, by discarding the fractional part of the number.
 
Methods inherited from class edu.neu.ccs.XObject
addPropertyChangeListener, addPropertyChangeListener, formatErrorMessage, removePropertyChangeListener, removePropertyChangeListener, toStringArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

private static final BigDecimal ZERO
The zero BigDecimal.


value

private BigDecimal value
The wrapped value of this object.


ROUND_UP

public static final int ROUND_UP

Rounding mode to round away from zero.

Always increments the digit prior to a non-zero discarded fraction.

Note that this rounding mode never decreases the magnitude of the calculated value.

See Also:
Constant Field Values

ROUND_DOWN

public static final int ROUND_DOWN

Rounding mode to round towards zero.

Never increments the digit prior to a discarded fraction (i.e., truncates).

Note that this rounding mode never increases the magnitude of the calculated value.

See Also:
Constant Field Values

ROUND_CEILING

public static final int ROUND_CEILING

Rounding mode to round towards positive infinity.

If the number is positive, behaves as for ROUND_UP; if negative, behaves as for ROUND_DOWN.

Note that this rounding mode never decreases the calculated value.

See Also:
Constant Field Values

ROUND_FLOOR

public static final int ROUND_FLOOR

Rounding mode to round towards negative infinity.

If the number is positive, behaves as for ROUND_DOWN; if negative, behaves as for ROUND_UP.

Note that this rounding mode never increases the calculated value.

See Also:
Constant Field Values

ROUND_HALF_UP

public static final int ROUND_HALF_UP

Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case round up.

Behaves as for ROUND_UP if the discarded fraction is >= .5; otherwise, behaves as for ROUND_DOWN.

Note that this is the rounding mode that most of us were taught in grade school.

See Also:
Constant Field Values

ROUND_HALF_DOWN

public static final int ROUND_HALF_DOWN

Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case round down.

Behaves as for ROUND_UP if the discarded fraction is > .5; otherwise, behaves as for ROUND_DOWN.

See Also:
Constant Field Values

ROUND_HALF_EVEN

public static final int ROUND_HALF_EVEN

Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.

Behaves as for ROUND_HALF_UP if the digit to the left of the discarded fraction is odd; behaves as for ROUND_HALF_DOWN if it's even.

Note that this is the rounding mode that minimizes cumulative error when applied repeatedly over a sequence of calculations.

See Also:
Constant Field Values

ROUND_UNNECESSARY

public static final int ROUND_UNNECESSARY

Rounding mode to assert that the requested operation has an exact result, hence no rounding is necessary.

If this rounding mode is specified on an operation that yields an inexact result, an ArithmeticException is thrown.

See Also:
Constant Field Values
Constructor Detail

XBigDecimal

public XBigDecimal()

Constructs a wrapper for the default BigDecimal value of zero.


XBigDecimal

public XBigDecimal(BigDecimal b)

Constructs a wrapper for the given BigDecimal value.

If the given value is null, the wrapped value is set to zero.

Parameters:
b - the value to be wrapped

XBigDecimal

public XBigDecimal(XBigDecimal b)

Constructs an XBigDecimal by copying the internal value of the given XBigDecimal.

If the given value is null, the wrapped value is set to zero.

Parameters:
b - the value to be copied

XBigDecimal

public XBigDecimal(String s)
            throws ParseException

Constructs an XBigDecimal using the information contained in the given string data.

Makes use of the parsing capabilities of the method fromStringData(String).

Parameters:
s - a string representation of the desired value
Throws:
ParseException - if the string is null or malformed

XBigDecimal

public XBigDecimal(XBigInteger x)

Translates an XBigInteger x into an XBigDecimal that is mathematically equal to x.

Parameters:
x - the XBigInteger used to set this value

XBigDecimal

public XBigDecimal(XBigInteger x,
                   int scale)

Translates an XBigInteger x and a scale into an XBigDecimal that is mathematically equal to x/10scale.

Parameters:
x - the XBigInteger used to set this value
scale - the power-of-ten scale factor which must be >= 0
Throws:
NumberFormatException - if scale is negative

XBigDecimal

public XBigDecimal(long x)

Translates a long x into an XBigDecimal that is mathematically equal to x.

Parameters:
x - the long used to set this value

XBigDecimal

public XBigDecimal(long x,
                   int scale)

Translates a long x and a scale into an XBigDecimal that is mathematically equal to x/10scale.

Parameters:
x - the long used to set this value
scale - the power-of-ten scale factor which must be >= 0
Throws:
NumberFormatException - if scale is negative

XBigDecimal

public XBigDecimal(double x)

Translates a double into an XBigDecimal.

The scale of the XBigDecimal is the smallest value such that (10scale*x) is an integer.

Note: The results of this constructor can be somewhat unpredictable. One might assume that new XBigDecimal(.1) is exactly equal to .1, but it is actually equal to:

    .1000000000000000055511151231257827021181583404541015625

This is so because .1 cannot be represented exactly as a double (or, for that matter, as a binary fraction of any finite length). Thus, the long value that is being passed in to the constructor is not exactly equal to .1, appearances notwithstanding.

The (String) constructor, on the other hand, is perfectly predictable: new XBigDecimal(".1") is exactly equal to .1, as one would expect. Therefore, it is generally recommended that the XBigDecimal(String) constructor be used in preference to this one.

An alternate constructor option that is also precise is new XBigDecimal(x,scale) where x is either long or XBigInteger. The only disadvantage of this option is that one must manually count the correct number of decimal digits (scale) that must be used.

Parameters:
x - the double used to set this value
Method Detail

fromStringData

public void fromStringData(String data)
                    throws ParseException

Sets the state of this XBigDecimal using the information contained in the given string data.

Utilizes the BigDecimal constructor BigDecimal(String) to create the new internal wrapped value. See the documentation of this constructor for the details concerning the valid format in which this decimal data may be supplied.

If the BigDecimal constructor throws a NumberFormatException, this exception is re-thrown as a ParseException.

If the given data is null, also throws a ParseException.

Fires property change: VALUE.

Specified by:
fromStringData in interface Stringable
Specified by:
fromStringData in class XObject
Parameters:
data - a string representation of the desired value
Throws:
ParseException - as explained above

toStringData

public String toStringData()

Returns a string encapsulation of this XBigDecimal that contains the information needed to set the state of this XBigDecimal at a later time.

Identical to toString.

Specified by:
toStringData in interface Stringable
Specified by:
toStringData in class XObject

toString

public String toString()

Returns the string representation of the wrapped BigDecimal value.

The digit-to-character mapping provided by Character.forDigit(int, int) is used. A leading minus sign is used to indicate sign and the number of digits to the right of the decimal point is used to indicate scale.

This representation is compatible with the (String) constructor.


equals

public boolean equals(Object other)
Returns true if the given object is of type XBigDecimal and its BigDecimal value is equal to the BigDecimal value of this XBigDecimal; returns false otherwise.

Parameters:
other - the object to be compared

hashCode

public int hashCode()
Returns the int hash code of the wrapped BigDecimal value.


setValue

public void setValue(BigDecimal b)

Sets the value wrapped by this object to the given BigDecimal value.

If the given value is null, the internal value is set to zero.

Fires property change: VALUE.

Parameters:
b - the value to be wrapped

setValue

public final void setValue(XBigDecimal b)

Sets the value wrapped by this object to the internal value of the given XBigDecimal value.

If the given input is null, the internal value is set to zero.

Fires property change: VALUE.

Parameters:
b - the value to be copied

setValue

public final void setValue(String data)
                    throws ParseException

Sets the state of this XBigDecimal using the information contained in the given string data.

Makes use of the parsing capabilities of the method fromStringData(String).

Fires property change: VALUE.

Parameters:
data - a string representation of the desired value
Throws:
ParseException - if data is null or malformed

setValue

public void setValue(XBigInteger x)

Translates an XBigInteger x into an XBigDecimal that is mathematically equal to x.

Fires property change: VALUE.

Parameters:
x - the XBigInteger used to set this value

setValue

public void setValue(XBigInteger x,
                     int scale)

Translates an XBigInteger x and a scale into an XBigDecimal that is mathematically equal to x/10scale.

Fires property change: VALUE.

Parameters:
x - the XBigInteger used to set this value
scale - the power-of-ten scale factor which must be >= 0
Throws:
NumberFormatException - if scale is negative

setValue

public void setValue(long x)

Translates a long x into an XBigDecimal that is mathematically equal to x.

Uses BigDecimal.valueOf(long) internally.

Fires property change: VALUE.

Parameters:
x - the long used to set this value

setValue

public void setValue(long x,
                     int scale)

Translates a long x and a scale into an XBigDecimal that is mathematically equal to x/10scale.

Uses BigDecimal.valueOf(long, int) internally.

Fires property change: VALUE.

Parameters:
x - the long used to set this value
scale - the power-of-ten scale factor which must be >= 0
Throws:
NumberFormatException - if scale is negative

setValue

public void setValue(double x)

Translates a double into an XBigDecimal that is then set as the value of this.

The scale of the XBigDecimal is the smallest value such that (10scale*x) is an integer.

Note: The result set via this method can be somewhat unpredictable. One might assume that the result of setValue(.1) is exactly equal to .1, but it is actually equal to:

    .1000000000000000055511151231257827021181583404541015625

This is so because .1 cannot be represented exactly as a double (or, for that matter, as a binary fraction of any finite length). Thus, the long value that is being passed in to the inner constructor is not exactly equal to .1, appearances notwithstanding.

The setValue(String) method, on the other hand, is perfectly predictable: the result of setValue(".1") is exactly equal to .1, as one would expect. Therefore, it is generally recommended that the setValue(String) method be used in preference to this one.

An alternate option that is also precise is setValue(x,scale) where x is either long or XBigInteger. The only disadvantage of this option is that one must manually count the correct number of decimal digits (scale) that must be used.

Fires property change: VALUE.

Parameters:
x - the double used to set this value

getValue

public BigDecimal getValue()

Returns the BigDecimal value wrapped by this object.


byteValue

public byte byteValue()
Description copied from class: XNumber
Returns the value of this number as a byte value.

Specified by:
byteValue in class XNumber

shortValue

public short shortValue()
Description copied from class: XNumber
Returns the value of this number as a short value.

Specified by:
shortValue in class XNumber

intValue

public int intValue()
Description copied from class: XNumber
Returns the value of this number as a int value.

Specified by:
intValue in class XNumber

longValue

public long longValue()
Description copied from class: XNumber
Returns the value of this number as a long value.

Specified by:
longValue in class XNumber

floatValue

public float floatValue()
Description copied from class: XNumber
Returns the value of this number as a float value.

Specified by:
floatValue in class XNumber

doubleValue

public double doubleValue()
Description copied from class: XNumber
Returns the value of this number as a double value.

Specified by:
doubleValue in class XNumber

signum

public final int signum()

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


scale

public final int scale()

Returns the scale of this XBigDecimal.

The scale is the number of digits to the right of the decimal point.


setScale

public final void setScale(int scale)

Sets this to a numerically equal value whose scale is the given scale.

Throws ArithmeticException if:

Parameters:
scale - the power-of-ten scale factor which must be >= 0
Throws:
ArithmeticException - as explained above

setScale

public static XBigDecimal setScale(XBigDecimal y,
                                   int scale)

Returns a new XBigDecimal whose scale is the given scale and whose value is numerically equal to the given y.

Throws ArithmeticException if:

Parameters:
y - the explicit argument
scale - the power-of-ten scale factor which must be >= 0
Throws:
ArithmeticException - as explained above

setScale

public final void setScale(int scale,
                           int roundingMode)

Sets this to an XBigDecimal whose scale is the given scale and whose unscaled value is determined by multiplying or dividing the unscaled value of this by the appropriate power of ten to maintain its overall value; if the scale is reduced by the operation, the unscaled value must be divided (rather than multiplied), and the value may be changed; in this case, the specified rounding mode is applied to the division.

Throws ArithmeticException if:

Throws IllegalArgumentException if the rounding mode is not a valid rounding mode.

Parameters:
scale - the power-of-ten scale factor which must be >= 0
roundingMode - rounding mode to apply
Throws:
ArithmeticException - as explained above
IllegalArgumentException - as explained above

setScale

public static XBigDecimal setScale(XBigDecimal y,
                                   int scale,
                                   int roundingMode)

Returns a new XBigDecimal whose scale is the given scale and whose unscaled value is determined by multiplying or dividing the unscaled value of the given y by the appropriate power of ten to maintain its overall value; if the scale is reduced by the operation, the unscaled value must be divided (rather than multiplied), and the value may be changed; in this case, the specified rounding mode is applied to the division.

Throws ArithmeticException if:

Throws IllegalArgumentException if the rounding mode is not a valid rounding mode.

Parameters:
y - the explicit argument
scale - the power-of-ten scale factor which must be >= 0
roundingMode - rounding mode to apply
Throws:
ArithmeticException - as explained above
IllegalArgumentException - as explained above

movePointLeft

public final void movePointLeft(int n)

Sets this to an XBigDecimal that is equivalent to this with the decimal point moved n places to the left.

The new value is this*10-n.

The new scale is max(this.scale()+n,0).

Parameters:
n - number of places to move the decimal point to the left

movePointLeft

public static XBigDecimal movePointLeft(XBigDecimal y,
                                        int n)

Returns a new XBigDecimal that is equivalent to the given y with the decimal point moved n places to the left.

The new value is y*10-n.

The new scale is max(y.scale()+n,0).

Parameters:
y - the explicit argument
n - number of places to move the decimal point to the left

movePointRight

public final void movePointRight(int n)

Sets this to an XBigDecimal that is equivalent to this with the decimal point moved n places to the right.

The new value is this*10n.

The new scale is max(this.scale()-n,0).

Parameters:
n - number of places to move the decimal point to the right

movePointRight

public static XBigDecimal movePointRight(XBigDecimal y,
                                         int n)

Returns a new XBigDecimal that is equivalent to the given y with the decimal point moved n places to the right.

The new value is y*10n.

The new scale is max(y.scale()-n,0).

Parameters:
y - the explicit argument
n - number of places to move the decimal point to the right

toUnscaledXBigInteger

public final XBigInteger toUnscaledXBigInteger()

Returns an XBigInteger whose value is the unscaled value of this XBigDecimal.

Computes (this*10this.scale()).

If b=this.toUnscaledXBigInteger() and s=this.scale(), then the method call this.setValue(b,s) will replace the wrapped BigDecimal with one of equal value.

In particular, toUnscaledXBigInteger() retains all decimal digit information in this XBigDecimal.

Uses BigDecimal.unscaledValue() internally.


toXBigInteger

public final XBigInteger toXBigInteger()

Converts this XBigDecimal to an XBigInteger by truncation, that is, by discarding the fractional part of the number.

This conversion is analogous to a narrowing primitive conversion from double to long as defined in the Java Language Specification.

Uses BigDecimal.toBigInteger() internally.


abs

public final void abs()

Sets this to abs(this).

Fires property change: VALUE.


abs

public static XBigDecimal abs(XBigDecimal y)

Returns a new XBigDecimal whose value is the absolute value of the given y.

Parameters:
y - the explicit argument

negate

public final void negate()

Sets this to (-this).

Fires property change: VALUE.


negate

public static XBigDecimal negate(XBigDecimal y)

Returns a new XBigDecimal whose value is the negation of the given y.

Parameters:
y - the explicit argument

max

public final void max(XBigDecimal y)

Sets this to max(this, y).

Fires property change: VALUE.

Parameters:
y - the explicit argument

max

public static XBigDecimal max(XBigDecimal x,
                              XBigDecimal y)

Returns a new XBigDecimal whose value is the maximum of the given x and y values.

Parameters:
x - the LHS argument
y - the RHS argument

min

public final void min(XBigDecimal y)

Sets this to min(this, y).

Fires property change: VALUE.

Parameters:
y - the explicit argument

min

public static XBigDecimal min(XBigDecimal x,
                              XBigDecimal y)

Returns a new XBigDecimal whose value is the minimum of the given x and y values.

Parameters:
x - the LHS argument
y - the RHS argument

add

public final void add(XBigDecimal y)

Sets this to (this + y).

Fires property change: VALUE.

Parameters:
y - the explicit argument

add

public static XBigDecimal add(XBigDecimal x,
                              XBigDecimal y)

Returns a new XBigDecimal whose value is x + y.

Parameters:
x - the LHS argument
y - the RHS argument

subtract

public final void subtract(XBigDecimal y)

Sets this to (this - y).

Fires property change: VALUE.

Parameters:
y - the explicit argument

subtract

public static XBigDecimal subtract(XBigDecimal x,
                                   XBigDecimal y)

Returns a new XBigDecimal whose value is x - y.

Parameters:
x - the LHS argument
y - the RHS argument

multiply

public final void multiply(XBigDecimal y)

Sets this to (this * y).

Fires property change: VALUE.

Parameters:
y - the explicit argument

multiply

public static XBigDecimal multiply(XBigDecimal x,
                                   XBigDecimal y)

Returns a new XBigDecimal whose value is x * y.

Parameters:
x - the LHS argument
y - the RHS argument

divide

public final void divide(XBigDecimal y,
                         int roundingMode)

Sets this to (this / y) and maintains the scale as this.scale().

If rounding must be performed to generate a result with the specified scale, the rounding mode is applied.

Throws ArithmeticException if:

Throws IllegalArgumentException if the rounding mode is not a valid rounding mode.

Fires property change: VALUE.

Parameters:
y - the explicit argument
roundingMode - rounding mode to apply
Throws:
ArithmeticException - as explained above
IllegalArgumentException - as explained above

divide

public static XBigDecimal divide(XBigDecimal x,
                                 XBigDecimal y,
                                 int roundingMode)

Returns a new XBigDecimal whose value is x / y and whose scale is x.scale().

If rounding must be performed to generate a result with the specified scale, the rounding mode is applied.

Throws ArithmeticException if:

Throws IllegalArgumentException if the rounding mode is not a valid rounding mode.

Parameters:
x - the LHS argument
y - the RHS argument
roundingMode - rounding mode to apply
Throws:
ArithmeticException - as explained above
IllegalArgumentException - as explained above

divide

public final void divide(XBigDecimal y,
                         int scale,
                         int roundingMode)

Sets this to (this / y) using the given scale for the quotient.

If rounding must be performed to generate a result with the specified scale, the rounding mode is applied.

Throws ArithmeticException if:

Throws IllegalArgumentException if the rounding mode is not a valid rounding mode.

Fires property change: VALUE.

Parameters:
y - the explicit argument
scale - the scale of the quotient which must be >= 0
roundingMode - rounding mode to apply
Throws:
ArithmeticException - as explained above
IllegalArgumentException - as explained above

divide

public static XBigDecimal divide(XBigDecimal x,
                                 XBigDecimal y,
                                 int scale,
                                 int roundingMode)

Returns a new XBigDecimal whose value is x / y and whose scale is the given scale.

If rounding must be performed to generate a result with the specified scale, the rounding mode is applied.

Throws ArithmeticException if:

Throws IllegalArgumentException if the rounding mode is not a valid rounding mode.

Parameters:
x - the LHS argument
y - the RHS argument
scale - the scale of the quotient which must be >= 0
roundingMode - rounding mode to apply
Throws:
ArithmeticException - as explained above
IllegalArgumentException - as explained above

isRoundingMode

public static boolean isRoundingMode(int roundingMode)

Returns true if the rounding mode is valid; otherwise false.

Parameters:
roundingMode - the proposed rounding mode

compareTo

public final int compareTo(XBigDecimal y)

Compares this XBigDecimal with the specified XBigDecimal y.

This method is provided in preference to individual methods for each of the six boolean comparison operators:

    ==, !=, <, <=, >, >=

The suggested idiom for performing these comparisons is:

    (x.compareTo(y) <op> 0)

where <op> is one of the six comparison operators.

Throws NullPointerException if the given object y is null. Since this method is not specified in the interface Comparable, we throw the natural exception rather than ClassCastException which is required in the more generic compareTo(Object) method.

Parameters:
y - the explicit argument
Throws:
NullPointerException - if y is null

compareTo

public final int compareTo(Object o)

Compares this XBigDecimal with the specified Object o.

This method is provided in preference to individual methods for each of the six boolean comparison operators:

    ==, !=, <, <=, >, >=

The suggested idiom for performing these comparisons is:

    (x.compareTo(y) <op> 0)

where <op> is one of the six comparison operators.

Throws ClassCastException if the given object is null or is not of type XBigDecimal. This is consistent with the specification of the interface Comparable which this method implements.

Parameters:
o - the Object to compare
Throws:
ClassCastException - if o is null or not of type XBigDecimal

toPrimitiveArray

public static BigDecimal[] toPrimitiveArray(XBigDecimal[] x)
Returns an array of BigDecimal objects copied from the given array of XBigDecimal objects.

Parameters:
x - an array of XBigDecimals
Returns:
the resulting array of BigDecimal objects

toXArray

public static XBigDecimal[] toXArray(BigDecimal[] a)
Returns an array of XBigDecimal objects initialized from the given array of BigDecimal objects.

Parameters:
a - an array of BigDecimals
Returns:
the resulting array of XBigDecimal objects