S
- the scale metrics type associated with this decimalpublic final class GenericDecimalFactory<S extends ScaleMetrics> extends Object implements DecimalFactory<S>
DecimalFactory
for generic
decimal values. Different generic decimal instances of the same class can
have different scales as opposed to the decimal values defined in the
immutable
and mutable
packages.
The recommended way to create a generic factory is via
Factories.getGenericDecimalFactory(ScaleMetrics)
.
GenericImmutableDecimal
,
GenericMutableDecimal
Constructor and Description |
---|
GenericDecimalFactory(S scaleMetrics)
Constructor with scale metrics argument.
|
Modifier and Type | Method and Description |
---|---|
GenericDecimalFactory<?> |
deriveFactory(int scale)
Returns a factory for the given
scale . |
<T extends ScaleMetrics> |
deriveFactory(T scaleMetrics)
Returns a factory for the given
scaleMetrics . |
int |
getScale()
Returns the scale of values created by this factory.
|
S |
getScaleMetrics()
Returns the scale metrics type associated with Decimal values created by
this factory.
|
Class<? extends GenericImmutableDecimal<S>> |
immutableType()
Returns the implementing class for immutable values.
|
Class<? extends MutableDecimal<S>> |
mutableType()
Returns the implementing class for mutable values.
|
GenericImmutableDecimal<S>[] |
newArray(int length)
Creates a one dimensional array of the specified
length for
immutable Decimal values. |
GenericMutableDecimal<S> |
newMutable()
Creates a new mutable value initialized with zero.
|
GenericMutableDecimal<S>[] |
newMutableArray(int length)
Creates a one dimensional array of the specified
length for
mutable Decimal values. |
GenericImmutableDecimal<S> |
parse(String value)
Translates the string representation of a
Decimal into an
immutable Decimal . |
GenericImmutableDecimal<S> |
parse(String value,
RoundingMode roundingMode)
Translates the string representation of a
Decimal into an
immutable Decimal . |
GenericImmutableDecimal<S> |
valueOf(BigDecimal value)
Returns a new immutable Decimal whose value is calculated by rounding the
specified
BigDecimal argument to the scale of
this factory using HALF_UP rounding. |
GenericImmutableDecimal<S> |
valueOf(BigDecimal value,
RoundingMode roundingMode)
Returns a new immutable Decimal whose value is calculated by rounding the
specified
BigDecimal argument to the scale of
this factory using the specified roundingMode . |
GenericImmutableDecimal<S> |
valueOf(BigInteger value)
Returns a new immutable Decimal whose value is numerically equal to that
of the specified
BigInteger value. |
GenericImmutableDecimal<S> |
valueOf(Decimal<?> value)
|
GenericImmutableDecimal<S> |
valueOf(Decimal<?> value,
RoundingMode roundingMode)
|
GenericImmutableDecimal<S> |
valueOf(double value)
|
GenericImmutableDecimal<S> |
valueOf(double value,
RoundingMode roundingMode)
Returns a new immutable Decimal whose value is calculated by rounding the
specified
double argument to the scale of
this factory using the specified roundingMode . |
GenericImmutableDecimal<S> |
valueOf(float value)
|
GenericImmutableDecimal<S> |
valueOf(float value,
RoundingMode roundingMode)
Returns a new immutable Decimal whose value is calculated by rounding the
specified
float argument to the scale of this
factory using the specified roundingMode . |
GenericImmutableDecimal<S> |
valueOf(long value)
Returns a new immutable Decimal whose value is numerically equal to that
of the specified
long value. |
GenericImmutableDecimal<S> |
valueOfUnscaled(long unscaled)
Returns a new immutable Decimal whose value is numerically equal to
(unscaled × 10-scale) where
scale
refers to this factory's scale . |
GenericImmutableDecimal<S> |
valueOfUnscaled(long unscaledValue,
int scale)
Returns a new immutable Decimal whose value is numerically equal to
(unscaled × 10-scale).
|
GenericImmutableDecimal<S> |
valueOfUnscaled(long unscaledValue,
int scale,
RoundingMode roundingMode)
Returns a new immutable Decimal whose value is numerically equal to
(unscaled × 10-scale).
|
public GenericDecimalFactory(S scaleMetrics)
Note: Application code should use
Factories.getGenericDecimalFactory(ScaleMetrics)
instead.
scaleMetrics
- the scale metrics for the new generic factory.public S getScaleMetrics()
DecimalFactory
getScaleMetrics
in interface DecimalFactory<S extends ScaleMetrics>
public int getScale()
DecimalFactory
getScale
in interface DecimalFactory<S extends ScaleMetrics>
public Class<? extends GenericImmutableDecimal<S>> immutableType()
DecimalFactory
immutableType
in interface DecimalFactory<S extends ScaleMetrics>
public Class<? extends MutableDecimal<S>> mutableType()
DecimalFactory
mutableType
in interface DecimalFactory<S extends ScaleMetrics>
public GenericDecimalFactory<?> deriveFactory(int scale)
DecimalFactory
scale
.deriveFactory
in interface DecimalFactory<S extends ScaleMetrics>
scale
- the scale of Decimal numbers created by the returned factorypublic <T extends ScaleMetrics> GenericDecimalFactory<T> deriveFactory(T scaleMetrics)
DecimalFactory
scaleMetrics
.deriveFactory
in interface DecimalFactory<S extends ScaleMetrics>
T
- the generic type for scaleMetrics
scaleMetrics
- the metrics defining the scale of the Decimal numbers created
by the returned factoryscaleMetrics
public GenericImmutableDecimal<S> valueOf(long value)
DecimalFactory
long
value. An exception is thrown if the
specified value is too large to be represented as a Decimal of this
factory's scale
.valueOf
in interface DecimalFactory<S extends ScaleMetrics>
value
- long value to convert into an immutable Decimal valuelong
valuepublic GenericImmutableDecimal<S> valueOf(float value)
DecimalFactory
float
argument to the scale
of this
factory using HALF_UP
rounding. An exception
is thrown if the specified value is too large to be represented as a
Decimal of this factory's scale.valueOf
in interface DecimalFactory<S extends ScaleMetrics>
value
- float value to convert into an immutable Decimal valuepublic GenericImmutableDecimal<S> valueOf(float value, RoundingMode roundingMode)
DecimalFactory
float
argument to the scale
of this
factory using the specified roundingMode
. An exception is thrown
if the specified value is too large to be represented as a Decimal of
this factory's scale.valueOf
in interface DecimalFactory<S extends ScaleMetrics>
value
- float value to convert into an immutable Decimal valueroundingMode
- the rounding mode to apply during the conversion if necessarypublic GenericImmutableDecimal<S> valueOf(double value)
DecimalFactory
double
argument to the scale
of
this factory using HALF_UP
rounding. An
exception is thrown if the specified value is too large to be represented
as a Decimal of this factory's scale.valueOf
in interface DecimalFactory<S extends ScaleMetrics>
value
- double value to convert into an immutable Decimal valuepublic GenericImmutableDecimal<S> valueOf(double value, RoundingMode roundingMode)
DecimalFactory
double
argument to the scale
of
this factory using the specified roundingMode
. An exception is
thrown if the specified value is too large to be represented as a Decimal
of this factory's scale.valueOf
in interface DecimalFactory<S extends ScaleMetrics>
value
- double value to convert into an immutable Decimal valueroundingMode
- the rounding mode to apply during the conversion if necessarypublic GenericImmutableDecimal<S> valueOf(BigInteger value)
DecimalFactory
BigInteger
value. An exception is thrown if the
specified value is too large to be represented as a Decimal of this
factory's scale
.valueOf
in interface DecimalFactory<S extends ScaleMetrics>
value
- BigInteger
value to convert into an immutable Decimal
valuepublic GenericImmutableDecimal<S> valueOf(BigDecimal value)
DecimalFactory
BigDecimal
argument to the scale
of
this factory using HALF_UP
rounding. An
exception is thrown if the specified value is too large to be represented
as a Decimal of this factory's scale.valueOf
in interface DecimalFactory<S extends ScaleMetrics>
value
- BigDecimal
value to convert into an immutable Decimal
valuepublic GenericImmutableDecimal<S> valueOf(BigDecimal value, RoundingMode roundingMode)
DecimalFactory
BigDecimal
argument to the scale
of
this factory using the specified roundingMode
. An exception is
thrown if the specified value is too large to be represented as a Decimal
of this factory's scale.valueOf
in interface DecimalFactory<S extends ScaleMetrics>
value
- BigDecimal
value to convert into an immutable Decimal
valueroundingMode
- the rounding mode to apply during the conversion if necessarypublic GenericImmutableDecimal<S> valueOf(Decimal<?> value)
DecimalFactory
Decimal
argument to the scale
of
this factory using HALF_UP
rounding. An
exception is thrown if the specified value is too large to be represented
as a Decimal of this factory's scale.valueOf
in interface DecimalFactory<S extends ScaleMetrics>
value
- Decimal value to convert into an immutable Decimal value of
this factory's scalepublic GenericImmutableDecimal<S> valueOf(Decimal<?> value, RoundingMode roundingMode)
DecimalFactory
Decimal
argument to the scale
of
this factory using the specified roundingMode
. An exception is
thrown if the specified value is too large to be represented as a Decimal
of this factory's scale.valueOf
in interface DecimalFactory<S extends ScaleMetrics>
value
- Decimal value to convert into an immutable Decimal value of
this factory's scaleroundingMode
- the rounding mode to apply during the conversion if necessarypublic GenericImmutableDecimal<S> parse(String value)
DecimalFactory
Decimal
into an
immutable Decimal
. The string representation 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 factory'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 factory's
scale.
parse
in interface DecimalFactory<S extends ScaleMetrics>
value
- String value to convert into an immutable Decimal value of
this factory's scalepublic GenericImmutableDecimal<S> parse(String value, RoundingMode roundingMode)
DecimalFactory
Decimal
into an
immutable Decimal
. The string representation 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 factory'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 factory's scale.
parse
in interface DecimalFactory<S extends ScaleMetrics>
value
- String value to convert into an immutable Decimal value of
this factory's scaleroundingMode
- the rounding mode to apply if the fraction contains more
digits than the scale of this factorypublic GenericImmutableDecimal<S> valueOfUnscaled(long unscaled)
DecimalFactory
scale
refers to this factory's scale
.valueOfUnscaled
in interface DecimalFactory<S extends ScaleMetrics>
unscaled
- unscaled value to convert into an immutable Decimal valuepublic GenericImmutableDecimal<S> valueOfUnscaled(long unscaledValue, int scale)
DecimalFactory
scale
of this factory using
HALF_UP
rounding. An exception is thrown if
the specified value is too large to be represented as a Decimal of this
factory's scale.valueOfUnscaled
in interface DecimalFactory<S extends ScaleMetrics>
unscaledValue
- unscaled value to convert into an immutable Decimal valuescale
- the scale to apply to the unscaled
valuepublic GenericImmutableDecimal<S> valueOfUnscaled(long unscaledValue, int scale, RoundingMode roundingMode)
DecimalFactory
scale
of this factory using the specified
roundingMode
. An exception is thrown if the specified value is
too large to be represented as a Decimal of this factory's scale.valueOfUnscaled
in interface DecimalFactory<S extends ScaleMetrics>
unscaledValue
- unscaled value to convert into an immutable Decimal valuescale
- the scale to apply to the unscaled
valueroundingMode
- the rounding mode to apply during the conversion if necessarypublic GenericImmutableDecimal<S>[] newArray(int length)
DecimalFactory
length
for
immutable Decimal values.newArray
in interface DecimalFactory<S extends ScaleMetrics>
length
- the length of the returned arraypublic GenericMutableDecimal<S> newMutable()
DecimalFactory
newMutable
in interface DecimalFactory<S extends ScaleMetrics>
public GenericMutableDecimal<S>[] newMutableArray(int length)
DecimalFactory
length
for
mutable Decimal values.newMutableArray
in interface DecimalFactory<S extends ScaleMetrics>
length
- the length of the returned array