Package org.apache.commons.text.numbers
Class DoubleFormat.AbstractDoubleFormat
- java.lang.Object
-
- org.apache.commons.text.numbers.DoubleFormat.AbstractDoubleFormat
-
- All Implemented Interfaces:
java.util.function.DoubleFunction<java.lang.String>
,ParsedDecimal.FormatOptions
- Direct Known Subclasses:
DoubleFormat.EngineeringDoubleFormat
,DoubleFormat.MixedDoubleFormat
,DoubleFormat.PlainDoubleFormat
,DoubleFormat.ScientificDoubleFormat
- Enclosing class:
- DoubleFormat
private abstract static class DoubleFormat.AbstractDoubleFormat extends java.lang.Object implements java.util.function.DoubleFunction<java.lang.String>, ParsedDecimal.FormatOptions
Base class for standard double formatting classes.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
alwaysIncludeExponent
Flag indicating if exponent values should always be included, even if zero.private char
decimalSeparator
Decimal separator character.private char[]
digits
String containing the digits 0-9.private char[]
exponentSeparatorChars
Exponent separator character.private boolean
fractionPlaceholder
Flag determining if fraction placeholders should be used.private char
groupingSeparator
Thousands grouping separator.private boolean
groupThousands
Flag indicating if thousands should be grouped.private int
maxPrecision
Maximum precision; 0 indicates no limit.private int
minDecimalExponent
Minimum decimal exponent.private char
minusSign
Minus sign character.private java.lang.String
nan
String representing NaN.private java.lang.String
negativeInfinity
String representing negative infinity.private java.lang.String
positiveInfinity
String representing positive infinity.private boolean
signedZero
Flag determining if signed zero strings are allowed.
-
Constructor Summary
Constructors Constructor Description AbstractDoubleFormat(DoubleFormat.Builder builder)
Constructs a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.String
apply(double d)
private java.lang.String
applyFinite(double d)
Returns a formatted string representation of the given finite value.protected abstract java.lang.String
applyFiniteInternal(ParsedDecimal val)
Returns a formatted representation of the given rounded decimal value todst
.char
getDecimalSeparator()
Get the decimal separator character.char[]
getDigits()
Get an array containing the localized digit characters 0-9 in that order.char[]
getExponentSeparatorChars()
Get the exponent separator as an array of characters.char
getGroupingSeparator()
Get the character used to separate thousands groupings.char
getMinusSign()
Get the minus sign character.boolean
isAlwaysIncludeExponent()
Returntrue
if exponent values should always be included in formatted output, even if the value is zero.boolean
isGroupThousands()
Returntrue
if thousands should be grouped.boolean
isIncludeFractionPlaceholder()
Returntrue
if fraction placeholders (e.g.,".0"
in"1.0"
) should be included.boolean
isSignedZero()
Returntrue
if the string zero should be prefixed with the minus sign for negative zero values.
-
-
-
Field Detail
-
maxPrecision
private final int maxPrecision
Maximum precision; 0 indicates no limit.
-
minDecimalExponent
private final int minDecimalExponent
Minimum decimal exponent.
-
positiveInfinity
private final java.lang.String positiveInfinity
String representing positive infinity.
-
negativeInfinity
private final java.lang.String negativeInfinity
String representing negative infinity.
-
nan
private final java.lang.String nan
String representing NaN.
-
fractionPlaceholder
private final boolean fractionPlaceholder
Flag determining if fraction placeholders should be used.
-
signedZero
private final boolean signedZero
Flag determining if signed zero strings are allowed.
-
digits
private final char[] digits
String containing the digits 0-9.
-
decimalSeparator
private final char decimalSeparator
Decimal separator character.
-
groupingSeparator
private final char groupingSeparator
Thousands grouping separator.
-
groupThousands
private final boolean groupThousands
Flag indicating if thousands should be grouped.
-
minusSign
private final char minusSign
Minus sign character.
-
exponentSeparatorChars
private final char[] exponentSeparatorChars
Exponent separator character.
-
alwaysIncludeExponent
private final boolean alwaysIncludeExponent
Flag indicating if exponent values should always be included, even if zero.
-
-
Constructor Detail
-
AbstractDoubleFormat
AbstractDoubleFormat(DoubleFormat.Builder builder)
Constructs a new instance.- Parameters:
builder
- builder instance containing configuration values
-
-
Method Detail
-
apply
public java.lang.String apply(double d)
- Specified by:
apply
in interfacejava.util.function.DoubleFunction<java.lang.String>
-
applyFinite
private java.lang.String applyFinite(double d)
Returns a formatted string representation of the given finite value.- Parameters:
d
- double value
-
applyFiniteInternal
protected abstract java.lang.String applyFiniteInternal(ParsedDecimal val)
Returns a formatted representation of the given rounded decimal value todst
.- Parameters:
val
- value to format- Returns:
- a formatted representation of the given rounded decimal value to
dst
.
-
getDecimalSeparator
public char getDecimalSeparator()
Get the decimal separator character.- Specified by:
getDecimalSeparator
in interfaceParsedDecimal.FormatOptions
- Returns:
- decimal separator character
-
getDigits
public char[] getDigits()
Get an array containing the localized digit characters 0-9 in that order. This string must be non-null and have a length of 10.- Specified by:
getDigits
in interfaceParsedDecimal.FormatOptions
- Returns:
- array containing the digit characters 0-9
-
getExponentSeparatorChars
public char[] getExponentSeparatorChars()
Get the exponent separator as an array of characters.- Specified by:
getExponentSeparatorChars
in interfaceParsedDecimal.FormatOptions
- Returns:
- exponent separator as an array of characters
-
getGroupingSeparator
public char getGroupingSeparator()
Get the character used to separate thousands groupings.- Specified by:
getGroupingSeparator
in interfaceParsedDecimal.FormatOptions
- Returns:
- character used to separate thousands groupings
-
getMinusSign
public char getMinusSign()
Get the minus sign character.- Specified by:
getMinusSign
in interfaceParsedDecimal.FormatOptions
- Returns:
- minus sign character
-
isAlwaysIncludeExponent
public boolean isAlwaysIncludeExponent()
Returntrue
if exponent values should always be included in formatted output, even if the value is zero.- Specified by:
isAlwaysIncludeExponent
in interfaceParsedDecimal.FormatOptions
- Returns:
true
if exponent values should always be included
-
isGroupThousands
public boolean isGroupThousands()
Returntrue
if thousands should be grouped.- Specified by:
isGroupThousands
in interfaceParsedDecimal.FormatOptions
- Returns:
true
if thousand should be grouped
-
isIncludeFractionPlaceholder
public boolean isIncludeFractionPlaceholder()
Returntrue
if fraction placeholders (e.g.,".0"
in"1.0"
) should be included.- Specified by:
isIncludeFractionPlaceholder
in interfaceParsedDecimal.FormatOptions
- Returns:
true
if fraction placeholders should be included
-
isSignedZero
public boolean isSignedZero()
Returntrue
if the string zero should be prefixed with the minus sign for negative zero values.- Specified by:
isSignedZero
in interfaceParsedDecimal.FormatOptions
- Returns:
true
if the minus zero string should be allowed
-
-