Package org.hipparchus.util
Class CompositeFormat
- java.lang.Object
-
- org.hipparchus.util.CompositeFormat
-
public class CompositeFormat extends Object
Base class for formatters of composite objects (complex numbers, vectors ...).
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringBuffer
formatDouble(double value, NumberFormat format, StringBuffer toAppendTo, FieldPosition pos)
Formats a double value to produce a string.static NumberFormat
getDefaultNumberFormat()
Create a default number format.static NumberFormat
getDefaultNumberFormat(Locale locale)
Create a default number format.static void
parseAndIgnoreWhitespace(String source, ParsePosition pos)
Parsessource
until a non-whitespace character is found.static boolean
parseFixedstring(String source, String expected, ParsePosition pos)
Parsesource
for an expected fixed string.static char
parseNextCharacter(String source, ParsePosition pos)
Parsessource
until a non-whitespace character is found.static Number
parseNumber(String source, NumberFormat format, ParsePosition pos)
Parsessource
for a number.
-
-
-
Method Detail
-
getDefaultNumberFormat
public static NumberFormat getDefaultNumberFormat()
Create a default number format. The default number format is based onNumberFormat.getInstance()
with the only customizing that the maximum number of fraction digits is set to 10.- Returns:
- the default number format.
-
getDefaultNumberFormat
public static NumberFormat getDefaultNumberFormat(Locale locale)
Create a default number format. The default number format is based onNumberFormat.getInstance(java.util.Locale)
with the only customizing that the maximum number of fraction digits is set to 10.- Parameters:
locale
- the specific locale used by the format.- Returns:
- the default number format specific to the given locale.
-
parseAndIgnoreWhitespace
public static void parseAndIgnoreWhitespace(String source, ParsePosition pos)
Parsessource
until a non-whitespace character is found.- Parameters:
source
- the string to parsepos
- input/output parsing parameter. On output,pos
holds the index of the next non-whitespace character.
-
parseNextCharacter
public static char parseNextCharacter(String source, ParsePosition pos)
Parsessource
until a non-whitespace character is found.- Parameters:
source
- the string to parsepos
- input/output parsing parameter.- Returns:
- the first non-whitespace character.
-
parseNumber
public static Number parseNumber(String source, NumberFormat format, ParsePosition pos)
Parsessource
for a number. This method can parse normal, numeric values as well as special values. These special values include Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY.- Parameters:
source
- the string to parseformat
- the number format used to parse normal, numeric values.pos
- input/output parsing parameter.- Returns:
- the parsed number.
-
parseFixedstring
public static boolean parseFixedstring(String source, String expected, ParsePosition pos)
Parsesource
for an expected fixed string.- Parameters:
source
- the string to parseexpected
- expected stringpos
- input/output parsing parameter.- Returns:
- true if the expected string was there
-
formatDouble
public static StringBuffer formatDouble(double value, NumberFormat format, StringBuffer toAppendTo, FieldPosition pos)
Formats a double value to produce a string. In general, the value is formatted using the formatting rules offormat
. There are three exceptions to this:- NaN is formatted as '(NaN)'
- Positive infinity is formatted as '(Infinity)'
- Negative infinity is formatted as '(-Infinity)'
- Parameters:
value
- the double to format.format
- the format used.toAppendTo
- where the text is to be appendedpos
- On input: an alignment field, if desired. On output: the offsets of the alignment field- Returns:
- the value passed in as toAppendTo.
-
-