Package org.apache.commons.math.util
Class CompositeFormat
java.lang.Object
java.text.Format
org.apache.commons.math.util.CompositeFormat
- All Implemented Interfaces:
Serializable,Cloneable
- Direct Known Subclasses:
ComplexFormat,RealVectorFormat,Vector3DFormat
Base class for formatters of composite objects (complex numbers, vectors ...).
- Version:
- $Revision: 1042376 $ $Date: 2010-12-05 16:54:55 +0100 (dim. 05 déc. 2010) $
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.text.Format
Format.Field -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringBufferformatDouble(double value, NumberFormat format, StringBuffer toAppendTo, FieldPosition pos) Formats a double value to produce a string.protected static NumberFormatCreate a default number format.protected static NumberFormatgetDefaultNumberFormat(Locale locale) Create a default number format.protected voidparseAndIgnoreWhitespace(String source, ParsePosition pos) Parsessourceuntil a non-whitespace character is found.protected booleanparseFixedstring(String source, String expected, ParsePosition pos) Parsesourcefor an expected fixed string.protected charparseNextCharacter(String source, ParsePosition pos) Parsessourceuntil a non-whitespace character is found.protected NumberparseNumber(String source, NumberFormat format, ParsePosition pos) Parsessourcefor a number.Methods inherited from class java.text.Format
clone, format, format, formatToCharacterIterator, parseObject, parseObject
-
Constructor Details
-
CompositeFormat
public CompositeFormat()
-
-
Method Details
-
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 2.- Returns:
- the default number format.
-
getDefaultNumberFormat
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 2.- Parameters:
locale- the specific locale used by the format.- Returns:
- the default number format specific to the given locale.
-
parseAndIgnoreWhitespace
Parsessourceuntil a non-whitespace character is found.- Parameters:
source- the string to parsepos- input/ouput parsing parameter. On output,posholds the index of the next non-whitespace character.
-
parseNextCharacter
Parsessourceuntil a non-whitespace character is found.- Parameters:
source- the string to parsepos- input/ouput parsing parameter.- Returns:
- the first non-whitespace character.
-
parseNumber
Parsessourcefor 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/ouput parsing parameter.- Returns:
- the parsed number.
-
parseFixedstring
Parsesourcefor an expected fixed string.- Parameters:
source- the string to parseexpected- expected stringpos- input/ouput parsing parameter.- Returns:
- true if the expected string was there
-
formatDouble
protected 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.
-