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

    public abstract class CompositeFormat
    extends Format

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:
  Serialized Form

### Nested Class Summary

### Nested classes/interfaces inherited from class java.text.Format

`Format.Field`

### Field Summary

Fields
`private static long` `serialVersionUID` Serializable version identifier.

### Constructor Summary

Constructors
Constructor and Description
`CompositeFormat()`

### Method Summary

Methods
`protected StringBuffer` `formatDouble(double value, NumberFormat format, StringBuffer toAppendTo, FieldPosition pos)` Formats a double value to produce a string.
`protected static NumberFormat` `getDefaultNumberFormat()` Create a default number format.
`protected static NumberFormat` `getDefaultNumberFormat(Locale locale)` Create a default number format.
`protected void` `parseAndIgnoreWhitespace(String source, ParsePosition pos)` Parses `source` until a non-whitespace character is found.
`protected boolean` `parseFixedstring(String source, String expected, ParsePosition pos)` Parse `source` for an expected fixed string.
`protected char` `parseNextCharacter(String source, ParsePosition pos)` Parses `source` until a non-whitespace character is found.
`private Number` `parseNumber(String source, double value, ParsePosition pos)` Parses `source` for special double values.
`protected Number` `parseNumber(String source, NumberFormat format, ParsePosition pos)` Parses `source` for a number.

### Methods inherited from class java.text.Format

`clone, format, format, formatToCharacterIterator, parseObject, parseObject`

### Methods inherited from class java.lang.Object

`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### serialVersionUID

    private static final long serialVersionUID

Serializable version identifier.

See Also:
  Constant Field Values

### Constructor Detail

#### CompositeFormat

    public CompositeFormat()

### Method Detail

#### getDefaultNumberFormat

    protected static NumberFormat getDefaultNumberFormat()

Create a default number format. The default number format is based on `NumberFormat.getInstance()` with the only customizing that the maximum number of fraction digits is set to 2.

Returns:
  the default number format.

#### getDefaultNumberFormat

    protected static NumberFormat getDefaultNumberFormat(Locale locale)

Create a default number format. The default number format is based on `NumberFormat.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

    protected void parseAndIgnoreWhitespace(String source,
                                ParsePosition pos)

Parses `source` until a non-whitespace character is found.

Parameters:
  `source` - the string to parse
  `pos` - input/ouput parsing parameter. On output, `pos` holds the index of the next non-whitespace character.

#### parseNextCharacter

    protected char parseNextCharacter(String source,
                          ParsePosition pos)

Parses `source` until a non-whitespace character is found.

Parameters:
  `source` - the string to parse
  `pos` - input/ouput parsing parameter.
Returns:
  the first non-whitespace character.

#### parseNumber

    private Number parseNumber(String source,
                     double value,
                     ParsePosition pos)

Parses `source` for special double values. These values include Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY.

Parameters:
  `source` - the string to parse
  `value` - the special value to parse.
  `pos` - input/ouput parsing parameter.
Returns:
  the special number.

#### parseNumber

    protected Number parseNumber(String source,
                     NumberFormat format,
                     ParsePosition pos)

Parses `source` 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 parse
  `format` - the number format used to parse normal, numeric values.
  `pos` - input/ouput parsing parameter.
Returns:
  the parsed number.

#### parseFixedstring

    protected boolean parseFixedstring(String source,
                           String expected,
                           ParsePosition pos)

Parse `source` for an expected fixed string.

Parameters:
  `source` - the string to parse
  `expected` - expected string
  `pos` - 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 of `format`. There are three exceptions to this:

1. NaN is formatted as '(NaN)'
2. Positive infinity is formatted as '(Infinity)'
3. Negative infinity is formatted as '(-Infinity)'

Parameters:
  `value` - the double to format.
  `format` - the format used.
  `toAppendTo` - where the text is to be appended
  `pos` - On input: an alignment field, if desired. On output: the offsets of the alignment field
Returns:
  the value passed in as toAppendTo.