Class BtcFixedFormat
- java.lang.Object
-
- java.text.Format
-
- org.bitcoinj.utils.BtcFormat
-
- org.bitcoinj.utils.BtcFixedFormat
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
public final class BtcFixedFormat extends BtcFormat
This class, a concrete extension of
BtcFormat
, is distinguished in that each instance formats and by-default parses all Bitcoin monetary values in units of a single denomination that is specified at the time that instance is constructed.By default, neither currency codes nor symbols are included in formatted values as output, nor recognized in parsed values as input. The can be overridden by applying a custom pattern using either the
BtcFormat.Builder.localizedPattern
orBtcFormat.Builder.localizedPattern
methods, as described in the documentation for theBtcFormat.Builder
class.A more detailed explanation, including examples, is in the documentation for the
BtcFormat
class, and further information beyond that is in the documentation for theFormat
class, from which this class descends.- See Also:
Format
,NumberFormat
,DecimalFormat
,Coin
, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.bitcoinj.utils.BtcFormat
BtcFormat.Builder
-
-
Field Summary
Fields Modifier and Type Field Description static int[]
REPEATING_DOUBLETS
A constant specifying the use of as many optional groups of two decimal places in the fraction part of a formatted number as are useful for expressing precision.static int[]
REPEATING_PLACES
A constant specifying the use of as many optional decimal places in the fraction part of a formatted number as are useful for expressing precision.static int[]
REPEATING_TRIPLETS
A constant specifying the use of as many optional groups of three decimal places in the fraction part of a formatted number as are useful for expressing precision.-
Fields inherited from class org.bitcoinj.utils.BtcFormat
COIN_SCALE, COIN_SYMBOL_ALT, decimalGroups, MICROCOIN_SCALE, MILLICOIN_SCALE, minimumFractionDigits, numberFormat
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
BtcFixedFormat(java.util.Locale locale, int scale, int minDecimals, java.util.List<java.lang.Integer> groups)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
code()
Return the currency code that identifies the units in which values formatted and (by-default) parsed by this instance are denominated.boolean
equals(java.lang.Object o)
Return true if the given object is equivalent to this one.int[]
fractionPlaceGroups()
Return the fractional decimal-placing used when formatting.int
hashCode()
Return a hash code value for this instance.int
scale()
Return the decimal-place shift for this object's fixed unit-denomination.protected int
scale(java.math.BigInteger satoshis, int fractionPlaces)
Return the decimal-place shift for this object's unit-denomination.java.lang.String
symbol()
Return the currency symbol that identifies the units in which values formatted by this instance are denominated.java.lang.String
toString()
Returns a brief description of this formatter.-
Methods inherited from class org.bitcoinj.utils.BtcFormat
builder, coinCode, coinSymbol, format, format, format, formatToCharacterIterator, getAvailableLocales, getCodeInstance, getCodeInstance, getCodeInstance, getCodeInstance, getCoinInstance, getCoinInstance, getCoinInstance, getCoinInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getInstance, getMicroInstance, getMicroInstance, getMicroInstance, getMicroInstance, getMilliInstance, getMilliInstance, getMilliInstance, getMilliInstance, getSymbolInstance, getSymbolInstance, getSymbolInstance, getSymbolInstance, negify, parse, parse, parseObject, pattern, prefixCode, prefixSymbol, prefixUnitsIndicator, symbols
-
-
-
-
Field Detail
-
REPEATING_PLACES
public static final int[] REPEATING_PLACES
A constant specifying the use of as many optional decimal places in the fraction part of a formatted number as are useful for expressing precision. This value can be passed as the final argument to a factory method orBtcFormat.format(Object, int, int...)
.
-
REPEATING_DOUBLETS
public static final int[] REPEATING_DOUBLETS
A constant specifying the use of as many optional groups of two decimal places in the fraction part of a formatted number as are useful for expressing precision. This value can be passed as the final argument to a factory method orBtcFormat.format(Object, int, int...)
.
-
REPEATING_TRIPLETS
public static final int[] REPEATING_TRIPLETS
A constant specifying the use of as many optional groups of three decimal places in the fraction part of a formatted number as are useful for expressing precision. This value can be passed as the final argument to a factory method orBtcFormat.format(Object, int, int...)
.
-
-
Method Detail
-
scale
protected int scale(java.math.BigInteger satoshis, int fractionPlaces)
Return the decimal-place shift for this object's unit-denomination. For example, if the denomination is millibitcoins, this method will return the value3
. As a side-effect, prefixes the currency signs of the underlying NumberFormat object. This method is invoked by the superclass when formatting. The arguments are ignored because the denomination is fixed regardless of the value being formatted.- Specified by:
scale
in classBtcFormat
- Parameters:
satoshis
- The number of satoshis having the value for which the shift is calculatedfractionPlaces
- The number of decimal places available for displaying the fractional part of the denominated value- Returns:
- The size of the shift in increasingly-precise decimal places
-
scale
public int scale()
Return the decimal-place shift for this object's fixed unit-denomination. For example, if the denomination is millibitcoins, this method will return the value3
.
-
code
public java.lang.String code()
Return the currency code that identifies the units in which values formatted and (by-default) parsed by this instance are denominated. For example, if the formatter's denomination is millibitcoins, then this method will return"mBTC"
, assuming the default base currency-code is not overridden using aBtcFormat.Builder
.
-
symbol
public java.lang.String symbol()
Return the currency symbol that identifies the units in which values formatted by this instance are denominated. For example, when invoked on an instance denominated in millibitcoins, this method by default returns"₥฿"
, depending on the locale.
-
fractionPlaceGroups
public int[] fractionPlaceGroups()
Return the fractional decimal-placing used when formatting. This method returns anint
array. The value of the first element is the minimum number of decimal places to be used in all cases, limited to a precision of satoshis. The value of each successive element is the size of an optional place-group that will be applied, possibly partially, if useful for expressing precision. The actual size of each group is limited to, and may be reduced to the limit of, a precision of no smaller than satoshis.
-
equals
public boolean equals(java.lang.Object o)
Return true if the given object is equivalent to this one. Formatters for different locales will never be equal, even if they behave identically.
-
hashCode
public int hashCode()
Return a hash code value for this instance.
-
toString
public java.lang.String toString()
Returns a brief description of this formatter. The exact details of the representation are unspecified and subject to change, but will include some representation of the formatting/parsing pattern and the fractional decimal place grouping.- Overrides:
toString
in classjava.lang.Object
-
-