S
- the scale metrics type associated with this DecimalD
- the concrete class implementing this MutableDecimal
public abstract class AbstractMutableDecimal<S extends ScaleMetrics,D extends AbstractMutableDecimal<S,D>> extends AbstractDecimal<S,D> implements MutableDecimal<S>
Decimal
classes of different scales.Constructor and Description |
---|
AbstractMutableDecimal(long unscaled)
Constructor with unscaled value.
|
Modifier and Type | Method and Description |
---|---|
abstract D |
clone()
Returns a clone of this mutable Decimal numerically identical to this
value.
|
protected D |
createOrAssign(long unscaled)
Returns
this decimal after assigning the value
(unscaled × 10-scale). |
MutableDecimal<S> |
max(MutableDecimal<S> val)
Returns the maximum of this
Decimal and val . |
MutableDecimal<S> |
min(MutableDecimal<S> val)
Returns the minimum of this
Decimal and val . |
MutableDecimal<?> |
multiplyExact(Decimal<?> multiplicand)
Returns a
Decimal whose value is (this * multiplicand) . |
MutableDecimal<?> |
scale(int scale)
|
MutableDecimal<?> |
scale(int scale,
RoundingMode roundingMode)
|
<S extends ScaleMetrics> |
scale(S scaleMetrics)
|
<S extends ScaleMetrics> |
scale(S scaleMetrics,
RoundingMode roundingMode)
|
D |
set(BigDecimal value)
Sets
this Decimal to the specified value and returns
this now representing value . |
D |
set(BigDecimal value,
RoundingMode roundingMode)
Sets
this Decimal to the specified value and returns
this now representing value . |
D |
set(BigInteger value)
Sets
this Decimal to the specified value and returns
this now representing value . |
D |
set(Decimal<?> value,
RoundingMode roundingMode)
Sets
this Decimal to the specified value and returns
this now representing value . |
D |
set(Decimal<S> value)
Sets
this Decimal to the specified value and returns
this now representing value . |
D |
set(double value)
Sets
this Decimal to the specified value and returns
this now representing value . |
D |
set(double value,
RoundingMode roundingMode)
Sets
this Decimal to the specified value and returns
this now representing value . |
D |
set(float value)
Sets
this Decimal to the specified value and returns
this now representing value . |
D |
set(float value,
RoundingMode roundingMode)
Sets
this Decimal to the specified value and returns
this now representing value . |
D |
set(long value)
Sets
this Decimal to the specified value and returns
this now representing value . |
D |
set(String value)
Parses the given string value and sets
this Decimal to the parsed
value . |
D |
set(String value,
RoundingMode roundingMode)
Parses the given string value and sets
this Decimal to the parsed
value . |
D |
setMinusOne()
Sets
this Decimal to -1 and returns this now representing
minus one. |
D |
setOne()
Sets
this Decimal to 1 and returns this now representing
one. |
D |
setUlp()
Sets
this Decimal to the smallest positive value representable by
this Mutable Decimal and returns this now representing one ULP. |
D |
setUnscaled(long unscaledValue)
Sets
this Decimal to the specified unscaledValue and
returns this now representing (unscaledValue * 10
-scale) where scale refers to the scale of this mutable Decimal. |
D |
setUnscaled(long unscaledValue,
int scale)
Sets
this Decimal to the specified unscaledValue with the
given scale and returns this now representing
(unscaledValue * 10-scale). |
D |
setUnscaled(long unscaledValue,
int scale,
RoundingMode roundingMode)
Sets
this Decimal to the specified unscaledValue with the
given scale and returns this now representing
(unscaledValue * 10-scale). |
D |
setZero()
Sets
this Decimal to 0 and returns this now representing
zero. |
long |
unscaledValue()
Returns the unscaled value underlying this
Decimal . |
abs, abs, add, add, add, add, add, add, add, add, addSquared, addSquared, addSquared, addUnscaled, addUnscaled, addUnscaled, addUnscaled, addUnscaled, avg, avg, byteValueExact, compareTo, compareToNumerically, create, createArray, divide, divide, divide, divide, divide, divide, divide, divide, divideAndRemainder, divideAndRemainder, divideBy, divideBy, divideBy, divideByPowerOfTen, divideByPowerOfTen, divideByPowerOfTen, divideExact, divideToIntegralValue, divideToIntegralValue, divideToLongValue, divideToLongValue, divideTruncate, divideUnscaled, divideUnscaled, divideUnscaled, divideUnscaled, divideUnscaled, divideUnscaled, doubleValue, doubleValue, equals, floatValue, floatValue, fractionalPart, getArithmeticFor, getArithmeticFor, getArithmeticFor, getCheckedArithmeticFor, getDefaultArithmetic, getDefaultCheckedArithmetic, getRoundingDownArithmetic, getRoundingFloorArithmetic, getRoundingHalfEvenArithmetic, getRoundingUnnecessaryArithmetic, hashCode, integralPart, intValue, intValueExact, invert, invert, invert, isBetweenZeroAndMinusOne, isBetweenZeroAndOne, isEqualTo, isEqualToNumerically, isGreaterThan, isGreaterThanOrEqualTo, isIntegral, isIntegralPartZero, isLessThan, isLessThanOrEqualTo, isMinusOne, isNegative, isNonNegative, isNonPositive, isOne, isPositive, isUlp, isZero, longValue, longValue, longValueExact, max, max, min, min, multiply, multiply, multiply, multiply, multiply, multiply, multiply, multiplyBy, multiplyBy, multiplyBy, multiplyByPowerOfTen, multiplyByPowerOfTen, multiplyByPowerOfTen, multiplyUnscaled, multiplyUnscaled, multiplyUnscaled, multiplyUnscaled, multiplyUnscaled, multiplyUnscaled, negate, negate, pow, pow, pow, remainder, round, round, round, self, shiftLeft, shiftLeft, shiftLeft, shiftRight, shiftRight, shiftRight, shortValueExact, signum, sqrt, sqrt, square, square, square, subtract, subtract, subtract, subtract, subtract, subtract, subtract, subtract, subtractSquared, subtractSquared, subtractSquared, subtractUnscaled, subtractUnscaled, subtractUnscaled, subtractUnscaled, subtractUnscaled, toBigDecimal, toBigDecimal, toBigInteger, toBigInteger, toBigIntegerExact, toString
byteValue, shortValue
finalize, getClass, notify, notifyAll, wait, wait, wait
abs, abs, add, add, add, add, add, add, add, add, addSquared, addSquared, addSquared, addUnscaled, addUnscaled, addUnscaled, addUnscaled, addUnscaled, avg, avg, divide, divide, divide, divide, divide, divide, divide, divide, divideAndRemainder, divideAndRemainder, divideBy, divideBy, divideBy, divideByPowerOfTen, divideByPowerOfTen, divideByPowerOfTen, divideExact, divideToIntegralValue, divideToIntegralValue, divideTruncate, divideUnscaled, divideUnscaled, divideUnscaled, divideUnscaled, divideUnscaled, divideUnscaled, fractionalPart, integralPart, invert, invert, invert, multiply, multiply, multiply, multiply, multiply, multiply, multiply, multiplyBy, multiplyBy, multiplyBy, multiplyByPowerOfTen, multiplyByPowerOfTen, multiplyByPowerOfTen, multiplyUnscaled, multiplyUnscaled, multiplyUnscaled, multiplyUnscaled, multiplyUnscaled, multiplyUnscaled, negate, negate, pow, pow, pow, remainder, round, round, round, shiftLeft, shiftLeft, shiftLeft, shiftRight, shiftRight, shiftRight, sqrt, sqrt, square, square, square, subtract, subtract, subtract, subtract, subtract, subtract, subtract, subtract, subtractSquared, subtractSquared, subtractSquared, subtractUnscaled, subtractUnscaled, subtractUnscaled, subtractUnscaled, subtractUnscaled
byteValue, byteValueExact, compareTo, compareToNumerically, divideToLongValue, divideToLongValue, doubleValue, doubleValue, equals, floatValue, floatValue, getFactory, getScale, getScaleMetrics, hashCode, intValue, intValueExact, isBetweenZeroAndMinusOne, isBetweenZeroAndOne, isEqualTo, isEqualToNumerically, isGreaterThan, isGreaterThanOrEqualTo, isIntegral, isIntegralPartZero, isLessThan, isLessThanOrEqualTo, isMinusOne, isNegative, isNonNegative, isNonPositive, isOne, isPositive, isUlp, isZero, longValue, longValue, longValueExact, max, min, shortValue, shortValueExact, signum, toBigDecimal, toBigDecimal, toBigInteger, toBigInteger, toBigIntegerExact, toImmutableDecimal, toMutableDecimal, toString
public AbstractMutableDecimal(long unscaled)
unscaled
- the unscaled valuepublic final long unscaledValue()
Decimal
Decimal
. This Decimal
is
(unscaledValue × 10-f) with f
representing the scale
, hence
the returned value equals (10f × this).unscaledValue
in interface Decimal<S extends ScaleMetrics>
Decimal.getScale()
,
ScaleMetrics.getScaleFactor()
protected D createOrAssign(long unscaled)
this
decimal after assigning the value
(unscaled × 10-scale).createOrAssign
in class AbstractDecimal<S extends ScaleMetrics,D extends AbstractMutableDecimal<S,D>>
unscaled
- unscaled value to assign to this Decimal
this
decimal value now representing
(unscaled × 10-scale)public MutableDecimal<?> scale(int scale)
Decimal
Decimal
value whose scale
is changed to the given scale
value.
HALF_UP
rounding is used if the scale change involves rounding.
An exception is thrown if the scale conversion leads to an overflow.
scale
in interface Decimal<S extends ScaleMetrics>
scale
in interface MutableDecimal<S extends ScaleMetrics>
scale
- the scale to use for the result, must be in [0,18]
Decimal.scale(ScaleMetrics)
,
Decimal.scale(int, RoundingMode)
,
Decimal.round(int)
public <S extends ScaleMetrics> MutableDecimal<S> scale(S scaleMetrics)
Decimal
Decimal
value whose scale
is changed to the scale given by the
scaleMetrics
argument. HALF_UP
rounding is used if the scale change involves
rounding.
An exception is thrown if the scale conversion leads to an overflow.
scale
in interface Decimal<S extends ScaleMetrics>
scale
in interface MutableDecimal<S extends ScaleMetrics>
S
- the scale metrics type of the resultscaleMetrics
- the scale metrics to use for the resultDecimal.scale(int)
,
Decimal.scale(ScaleMetrics, RoundingMode)
,
Decimal.round(int)
public MutableDecimal<?> scale(int scale, RoundingMode roundingMode)
Decimal
Decimal
value whose scale
is changed to the given scale
value. The
specified roundingMode
is used if the scale change involves rounding.
An exception is thrown if the scale conversion leads to an overflow.
scale
in interface Decimal<S extends ScaleMetrics>
scale
in interface MutableDecimal<S extends ScaleMetrics>
scale
- the scale to use for the result, must be in [0,18]
roundingMode
- the rounding mode to apply if the scale change involves roundingDecimal.scale(int)
,
Decimal.scale(ScaleMetrics, RoundingMode)
,
Decimal.round(int, RoundingMode)
public <S extends ScaleMetrics> MutableDecimal<S> scale(S scaleMetrics, RoundingMode roundingMode)
Decimal
Decimal
value whose scale
is changed to the scale given by the
scaleMetrics
argument. The specified roundingMode
is used if the scale change involves rounding.
An exception is thrown if the scale conversion leads to an overflow.
scale
in interface Decimal<S extends ScaleMetrics>
scale
in interface MutableDecimal<S extends ScaleMetrics>
S
- the scale metrics type of the resultscaleMetrics
- the scale metrics to use for the resultroundingMode
- the rounding mode to apply if the scale change involves roundingDecimal.scale(ScaleMetrics)
,
Decimal.scale(int, RoundingMode)
,
Decimal.round(int, RoundingMode)
public MutableDecimal<?> multiplyExact(Decimal<?> multiplicand)
Decimal
Decimal
whose value is (this * multiplicand)
. The scale of the returned value is the
sum of the scales of this
Decimal and the multiplicand
argument. If the result scale exceeds 18,
an IllegalArgumentException
is thrown. An ArithmeticException
is thrown if the product is out of
the possible range for a Decimal with the result scale.
Note that the result is always a new instance --- immutable if this Decimal is an ImmutableDecimal
and mutable if it is a MutableDecimal
.
multiplyExact
in interface Decimal<S extends ScaleMetrics>
multiplyExact
in interface MutableDecimal<S extends ScaleMetrics>
multiplicand
- factor to multiply with this Decimal
(this * multiplicand)
with scale equal to the sum of scales of this
and
multiplicand
public D setZero()
MutableDecimal
this
Decimal to 0 and returns this
now representing
zero.setZero
in interface MutableDecimal<S extends ScaleMetrics>
this
Decimal after assigning the value 0
public D setOne()
MutableDecimal
this
Decimal to 1 and returns this
now representing
one.setOne
in interface MutableDecimal<S extends ScaleMetrics>
this
Decimal after assigning the value 1
public D setMinusOne()
MutableDecimal
this
Decimal to -1 and returns this
now representing
minus one.setMinusOne
in interface MutableDecimal<S extends ScaleMetrics>
this
Decimal after assigning the value -1
public D setUlp()
MutableDecimal
this
Decimal to the smallest positive value representable by
this Mutable Decimal and returns this
now representing one ULP.setUlp
in interface MutableDecimal<S extends ScaleMetrics>
this
Decimal after assigning the value
ULP=10-scalepublic D set(Decimal<S> value)
MutableDecimal
this
Decimal to the specified value
and returns
this
now representing value
.set
in interface MutableDecimal<S extends ScaleMetrics>
value
- value to be setthis
Decimal after assigning the given value
public D set(Decimal<?> value, RoundingMode roundingMode)
MutableDecimal
this
Decimal to the specified value
and returns
this
now representing value
. The specified
Decimal
argument is rounded to the scale
of
this mutable Decimal using RoundingMode.HALF_UP
rounding. An
exception is thrown if the specified value is too large to be represented
as a Decimal of this mutable Decimal's scale.set
in interface MutableDecimal<S extends ScaleMetrics>
value
- value to be setroundingMode
- the rounding mode to apply during the conversion if necessarythis
Decimal after assigning:
roundHALF_UP(value)public D set(long value)
MutableDecimal
this
Decimal to the specified value
and returns
this
now representing value
. An exception is thrown if
the specified value is too large to be represented as a Decimal of this
mutable Decimal's scale.set
in interface MutableDecimal<S extends ScaleMetrics>
value
- value to be setthis
Decimal after assigning the given value
public D set(BigInteger value)
MutableDecimal
this
Decimal to the specified value
and returns
this
now representing value
. An exception is thrown if
the specified value is too large to be represented as a Decimal of this
mutable Decimal's scale.set
in interface MutableDecimal<S extends ScaleMetrics>
value
- value to be setthis
Decimal after assigning the given value
public D set(float value)
MutableDecimal
this
Decimal to the specified value
and returns
this
now representing value
. The specified float
argument is rounded to the scale
of this mutable
Decimal using RoundingMode.HALF_UP
rounding. An exception is
thrown if the specified value is too large to be represented as a Decimal
of this mutable Decimal's scale.set
in interface MutableDecimal<S extends ScaleMetrics>
value
- value to be setthis
Decimal after assigning:
roundHALF_UP(value)public D set(float value, RoundingMode roundingMode)
MutableDecimal
this
Decimal to the specified value
and returns
this
now representing value
. The specified float
argument is rounded to the scale
of this mutable
Decimal using the specified roundingMode
. An exception is thrown
if the specified value is too large to be represented as a Decimal of
this mutable Decimal's scale.set
in interface MutableDecimal<S extends ScaleMetrics>
value
- value to be setroundingMode
- the rounding mode to apply during the conversion if necessarythis
Decimal after assigning: round(value)public D set(double value)
MutableDecimal
this
Decimal to the specified value
and returns
this
now representing value
. The specified double
argument is rounded to the scale
of this mutable
Decimal using RoundingMode.HALF_UP
rounding. An exception is
thrown if the specified value is too large to be represented as a Decimal
of this mutable Decimal's scale.set
in interface MutableDecimal<S extends ScaleMetrics>
value
- value to be setthis
Decimal after assigning:
roundHALF_UP(value)public D set(double value, RoundingMode roundingMode)
MutableDecimal
this
Decimal to the specified value
and returns
this
now representing value
. The specified double
argument is rounded to the scale
of this mutable
Decimal using the specified roundingMode
. An exception is thrown
if the specified value is too large to be represented as a Decimal of
this mutable Decimal's scale.set
in interface MutableDecimal<S extends ScaleMetrics>
value
- value to be setroundingMode
- the rounding mode to apply during the conversion if necessarythis
Decimal after assigning: round(value)public D set(BigDecimal value)
MutableDecimal
this
Decimal to the specified value
and returns
this
now representing value
. The specified
BigDecimal
argument is rounded to the scale
of this mutable Decimal using RoundingMode.HALF_UP
rounding. An
exception is thrown if the specified value is too large to be represented
as a Decimal of this mutable Decimal's scale.set
in interface MutableDecimal<S extends ScaleMetrics>
value
- value to be setthis
Decimal after assigning:
roundHALF_UP(value)public D set(BigDecimal value, RoundingMode roundingMode)
MutableDecimal
this
Decimal to the specified value
and returns
this
now representing value
. The specified
BigDecimal
argument is rounded to the scale
of this mutable Decimal using the specified roundingMode
. An
exception is thrown if the specified value is too large to be represented
as a Decimal of this mutable Decimal's scale.set
in interface MutableDecimal<S extends ScaleMetrics>
value
- value to be setroundingMode
- the rounding mode to apply if rounding is necessarythis
Decimal after assigning: round(value)public D setUnscaled(long unscaledValue)
MutableDecimal
this
Decimal to the specified unscaledValue
and
returns this
now representing (unscaledValue * 10
-scale) where scale refers to the scale
of this mutable Decimal.setUnscaled
in interface MutableDecimal<S extends ScaleMetrics>
unscaledValue
- value to be setthis
Decimal after assigning:
unscaledValue * 10-scale.public D setUnscaled(long unscaledValue, int scale)
MutableDecimal
this
Decimal to the specified unscaledValue
with the
given scale
and returns this
now representing
(unscaledValue * 10-scale). The value is rounded to
the scale
of this mutable Decimal using
HALF_UP
rounding. An exception is thrown if
the specified value is too large to be represented as a Decimal of this
of this mutable Decimal's scale.setUnscaled
in interface MutableDecimal<S extends ScaleMetrics>
unscaledValue
- value to be setscale
- the scale used for unscaledValue
this
Decimal after assigning:
roundHALF_UP(unscaledValue * 10-scale)public D setUnscaled(long unscaledValue, int scale, RoundingMode roundingMode)
MutableDecimal
this
Decimal to the specified unscaledValue
with the
given scale
and returns this
now representing
(unscaledValue * 10-scale). The value is rounded to
the scale
of this mutable Decimal using the specified
roundingMode
. An exception is thrown if the specified value is
too large to be represented as a Decimal of this of this mutable
Decimal's scale.setUnscaled
in interface MutableDecimal<S extends ScaleMetrics>
unscaledValue
- value to be setscale
- the scale used for unscaledValue
roundingMode
- the rounding mode to apply during the conversion if necessarythis
Decimal after assigning:
round(unscaledValue * 10-scale)public D set(String value)
MutableDecimal
this
Decimal to the parsed
value
.
The string representation of a Decimal
consists of an optional
sign, '+'
or '-'
, followed by a sequence of zero or more
decimal digits ("the integer"), optionally followed by a fraction.
The fraction consists of a decimal point followed by zero or more decimal
digits. The string must contain at least one digit in either the integer
or the fraction. If the fraction contains more digits than this mutable
Decimal's scale
, the value is rounded using
HALF_UP
rounding. An exception is thrown if
the value is too large to be represented as a Decimal of this mutable
Decimals's scale.
set
in interface MutableDecimal<S extends ScaleMetrics>
value
- the string value to parse and assignthis
Decimal after assigning the parsed valuepublic D set(String value, RoundingMode roundingMode)
MutableDecimal
this
Decimal to the parsed
value
.
The string representation of a Decimal
consists of an optional
sign, '+'
or '-'
, followed by a sequence of zero or more
decimal digits ("the integer"), optionally followed by a fraction.
The fraction consists of a decimal point followed by zero or more decimal
digits. The string must contain at least one digit in either the integer
or the fraction. If the fraction contains more digits than this mutable
Decimal's scale
, the value is rounded using the
specified roundingMode
. An exception is thrown if the value is
too large to be represented as a Decimal of this mutable Decimals's
scale.
set
in interface MutableDecimal<S extends ScaleMetrics>
value
- the string value to parse and assignroundingMode
- the rounding mode to apply if the fraction contains more
digits than the scale of this mutable Decimalthis
Decimal after assigning the parsed valuepublic MutableDecimal<S> min(MutableDecimal<S> val)
MutableDecimal
Decimal
and val
.min
in interface MutableDecimal<S extends ScaleMetrics>
val
- value with which the minimum is to be computed.Decimal
whose value is the lesser of this
Decimal
and val
. If they are equal, as defined by
the compareTo
method, this
is
returned.Decimal.compareTo(Decimal)
public MutableDecimal<S> max(MutableDecimal<S> val)
MutableDecimal
Decimal
and val
.max
in interface MutableDecimal<S extends ScaleMetrics>
val
- value with which the maximum is to be computed.Decimal
whose value is the greater of this
Decimal
and val
. If they are equal, as defined by
the compareTo
method, this
is
returned.Decimal.compareTo(Decimal)
public abstract D clone()
MutableDecimal
clone
in interface MutableDecimal<S extends ScaleMetrics>
clone
in class Object