Class BtcFormat.Builder
- Enclosing class:
- BtcFormat
This class constructs new instances of BtcFormat
, allowing for the
configuration of those instances before they are constructed. After obtaining a
Builder
object from the BtcFormat.builder()
method, invoke the
necessary setter methods to obtain your desired configuration. Finally, the build()
method returns a new BtcFormat
object that has the specified
configuration.
All the setter methods override defaults. Invoking build()
without invoking any
of the setting methods is equivalent to invoking BtcFormat.getInstance()
with no arguments.
Each setter methods returns the same instance on which it is invoked, thus these methods can be chained.
Instances of this class are not thread-safe.
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Return a newBtcFormat
instance.Specify a custom currency code to be used in the denomination-unit indicators of formatted values.fractionDigits
(int val) Specify the number of decimal places in the fraction part of formatted numbers.fractionGroups
(int... val) Specify the sizes of a variable number of optional decimal-place groups in the fraction part of formatted values.Specify theLocale
for formatting and parsing.localizedPattern
(String val) Use the given localized-pattern for formatting and parsing.minimumFractionDigits
(int val) Specify the minimum number of decimal places in the fraction part of formatted values.Use the given pattern when formatting and parsing.scale
(int val) Specify a fixed-denomination of units to use when formatting and parsing values.style
(BtcAutoFormat.Style val) Specify the newBtcFormat
is to be automatically-denominating.Specify a currency symbol to be used in the denomination-unit indicators of formatted values.
-
Method Details
-
style
Specify the newBtcFormat
is to be automatically-denominating. The argument determines which of either codes or symbols the newBtcFormat
will use by default to indicate the denominations it chooses when formatting values.Note that the
Style
argument specifies the default style, which is overridden by invoking eitherpattern(String)
orlocalizedPattern(String)
.- Throws:
IllegalArgumentException
- ifscale(int)
has previously been invoked on this instance.
-
fractionDigits
Specify the number of decimal places in the fraction part of formatted numbers. This is equivalent to theminimumFractionDigits(int)
method, but named appropriately for the context of generatingBtcAutoFormat
instances.If neither this method nor
minimumFactionDigits()
is invoked, the default value will be2
. -
scale
Specify a fixed-denomination of units to use when formatting and parsing values. The argument specifies the number of decimal places, in increasing precision, by which each formatted value will differ from that same value denominated in bitcoins. For example, a denomination of millibitcoins is specified with a value of3
.The
BtcFormat
class provides appropriately namedint
-type constants for the three common values,BtcFormat.COIN_SCALE
,BtcFormat.MILLICOIN_SCALE
BtcFormat.MICROCOIN_SCALE
.If neither this method nor
style(BtcAutoFormat.Style)
is invoked on aBtcFormat.Builder
, then theBtcFormat
will default to a fixed-denomination of bitcoins, equivalent to invoking this method with an argument of0
. -
minimumFractionDigits
Specify the minimum number of decimal places in the fraction part of formatted values. This method is equivalent tofractionDigits(int)
, but named appropriately for the context of generating a fixed-denomination formatter.If neither this method nor
fractionDigits()
is invoked, the default value will be2
. -
fractionGroups
Specify the sizes of a variable number of optional decimal-place groups in the fraction part of formatted values. A group of each specified size will be used in addition to all previously applied decimal places only if doing so is useful for expressing precision. The size of each group is limited to a maximum precision of satoshis.If this method is not invoked, then the number of fractional decimal places will be limited to the value passed to
minimumFractionDigits
, or2
if that method is not invoked. -
locale
Specify theLocale
for formatting and parsing. If this method is not invoked, then the runtime default locale will be used. -
symbol
Specify a currency symbol to be used in the denomination-unit indicators of formatted values. This method only sets the symbol, but does not cause it to be used. You must also invoke eitherstyle(SYMBOL)
, or else apply a custom pattern that includes a single currency-sign character by invoking eitherpattern(String)
orlocalizedPattern(String)
.Specify only the base symbol. The appropriate prefix will be applied according to the denomination of formatted and parsed values.
-
code
Specify a custom currency code to be used in the denomination-unit indicators of formatted values. This method only sets the code, but does not cause it to be used. You must also invoke eitherstyle(CODE)
, or else apply a custom pattern that includes a double currency-sign character by invoking eitherpattern(String)
orlocalizedPattern(String)
.Specify only the base code. The appropriate prefix will be applied according to the denomination of formatted and parsed values.
-
pattern
Use the given pattern when formatting and parsing. The format of this pattern is identical to that used by theDecimalFormat
class.If the pattern lacks a negative subpattern, then the formatter will indicate negative values by placing a minus sign immediately preceding the number part of formatted values.
Note that while the pattern format specified by the
DecimalFormat
class includes a mechanism for setting the number of fractional decimal places, that part of the pattern is ignored. Instead, use thefractionDigits(int)
,minimumFractionDigits(int)
andfractionGroups(int...)
methods.Warning: if you set a pattern that includes a currency-sign for a fixed-denomination formatter that uses a non-standard scale, then an exception will be raised when you try to format a value. The standard scales include all for which a metric prefix exists from micro to mega.
Note that by applying a pattern you override the configured formatting style of
BtcAutoFormat
instances. -
localizedPattern
Use the given localized-pattern for formatting and parsing. The format of this pattern is identical to the patterns used by theDecimalFormat
class.The pattern is localized according to the locale of the
BtcFormat
instance, the symbols for which can be examined by inspecting theDecimalFormatSymbols
object returned byBtcFormat.symbols()
. So, for example, if you are in Germany, then the non-localized pattern of"#,##0.###"
would be localized as"#.##0,###"
If the pattern lacks a negative subpattern, then the formatter will indicate negative values by placing a minus sign immediately preceding the number part of formatted values.
Note that while the pattern format specified by the
DecimalFormat
class includes a mechanism for setting the number of fractional decimal places, that part of the pattern is ignored. Instead, use thefractionDigits(int)
,minimumFractionDigits(int)
andfractionGroups(int...)
methods.Warning: if you set a pattern that includes a currency-sign for a fixed-denomination formatter that uses a non-standard scale, then an exception will be raised when you try to format a value. The standard scales include all for which a metric prefix exists from micro to mega.
Note that by applying a pattern you override the configured formatting style of
BtcAutoFormat
instances. -
build
Return a newBtcFormat
instance. The object returned will be configured according to the state of thisBuilder
instance at the time this method is invoked.
-