Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.math.complex
Class ComplexFormat

    java.lang.Object
      java.text.Format
          org.apache.commons.math.complex.ComplexFormat

All Implemented Interfaces:
  Cloneable, Serializable

public class ComplexFormat
extends Format
implements Serializable

Formats a Complex number in cartesian format "Re(c) + Im(c)i". 'i' can be replaced with 'j', and the number format for both real and imaginary parts can be configured.

Version:
  $Revision: 1.10 $ $Date: 2004/09/21 04:45:55 $
Author:
  Apache Software Foundation
See Also:
  Serialized Form

Nested Class Summary

Nested classes inherited from class java.text.Format
`Format.Field`

Field Summary
`(package private) static long` | `serialVersionUID` Serializable version identifier

Constructor Summary
`ComplexFormat()` Create an instance with the default imaginary character, 'i', and the default number format for both real and imaginary parts.
`ComplexFormat(NumberFormat format)` Create an instance with a custom number format for both real and imaginary parts.
`ComplexFormat(NumberFormat realFormat, NumberFormat imaginaryFormat)` Create an instance with a custom number format for the real part and a custom number format for the imaginary part.
`ComplexFormat(String imaginaryCharacter)` Create an instance with a custom imaginary character, and the default number format for both real and imaginary parts.
`ComplexFormat(String imaginaryCharacter, NumberFormat format)` Create an instance with a custom imaginary character, and a custom number format for both real and imaginary parts.
`ComplexFormat(String imaginaryCharacter, NumberFormat realFormat, NumberFormat imaginaryFormat)` Create an instance with a custom imaginary character, a custom number format for the real part, and a custom number format for the imaginary part.

Method Summary
`StringBuffer` | `format(Complex complex, StringBuffer toAppendTo, FieldPosition pos)` Formats a `Complex` object to produce a string.
`StringBuffer` | `format(Object obj, StringBuffer toAppendTo, FieldPosition pos)` Formats a object to produce a string.
`static String` | `formatComplex(Complex c)` This static method calls formatComplex() on a default instance of ComplexFormat.
`static Locale[]` | `getAvailableLocales()` Get the set of locales for which complex formats are available.
`String` | `getImaginaryCharacter()` Access the imaginaryCharacter.
`NumberFormat` | `getImaginaryFormat()` Access the imaginaryFormat.
`static ComplexFormat` | `getInstance()` Returns the default complex format for the current locale.
`static ComplexFormat` | `getInstance(Locale locale)` Returns the default complex format for the given locale.
`NumberFormat` | `getRealFormat()` Access the realFormat.
`Complex` | `parse(String source)` Parses a string to produce a `Complex` object.
`Complex` | `parse(String source, ParsePosition pos)` Parses a string to produce a `Complex` object.
`Object` | `parseObject(String source, ParsePosition pos)` Parses a string to produce a object.
`void` | `setImaginaryCharacter(String imaginaryCharacter)` Modify the imaginaryCharacter.
`void` | `setImaginaryFormat(NumberFormat imaginaryFormat)` Modify the imaginaryFormat.
`void` | `setRealFormat(NumberFormat realFormat)` Modify the realFormat.

Methods inherited from class java.text.Format
`clone, format, formatToCharacterIterator, parseObject`

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### serialVersionUID

    static final long serialVersionUID

  Serializable version identifier

  See Also:
    Constant Field Values

Constructor Detail

### ComplexFormat

    public ComplexFormat()

  Create an instance with the default imaginary character, 'i', and the default number format for both real and imaginary parts.

### ComplexFormat

    public ComplexFormat(NumberFormat format)

  Create an instance with a custom number format for both real and imaginary parts.

Parameters:
  `format` - the custom format for both real and imaginary parts.

### ComplexFormat

    public ComplexFormat(NumberFormat realFormat,
                         NumberFormat imaginaryFormat)

  Create an instance with a custom number format for the real part and a custom number format for the imaginary part.

Parameters:
  `realFormat` - the custom format for the real part.
  `imaginaryFormat` - the custom format for the imaginary part.

### ComplexFormat

    public ComplexFormat(String imaginaryCharacter)

  Create an instance with a custom imaginary character, and the default number format for both real and imaginary parts.

Parameters:
  `imaginaryCharacter` - The custom imaginary character.

### ComplexFormat

    public ComplexFormat(String imaginaryCharacter,
                         NumberFormat format)

  Create an instance with a custom imaginary character, and a custom number format for both real and imaginary parts.

Parameters:
  `imaginaryCharacter` - The custom imaginary character.
  `format` - the custom format for both real and imaginary parts.

### ComplexFormat

    public ComplexFormat(String imaginaryCharacter,
                         NumberFormat realFormat,
                         NumberFormat imaginaryFormat)

  Create an instance with a custom imaginary character, a custom number format for the real part, and a custom number format for the imaginary part.

Parameters:
  `imaginaryCharacter` - The custom imaginary character.
  `realFormat` - the custom format for the real part.
  `imaginaryFormat` - the custom format for the imaginary part.

Method Detail

### formatComplex

    public static String formatComplex(Complex c)

  This static method calls formatComplex() on a default instance of ComplexFormat.

  Parameters:
    `c` - Complex object to format
  Returns:
    A formatted number in the form "Re(c) + Im(c)i"

### format

    public StringBuffer format(Complex complex,
                               StringBuffer toAppendTo,
                               FieldPosition pos)

  Formats a `Complex` object to produce a string.

  Parameters:
    `complex` - the object to format.
    `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.

### format

    public StringBuffer format(Object obj,
                               StringBuffer toAppendTo,
                               FieldPosition pos)

  Formats a object to produce a string. `obj` must be either a `Complex` object or a `Number` object. Any other type of object will result in an `IllegalArgumentException` being thrown.

  Parameters:
    `obj` - the object to format.
    `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.
  Throws:
    `IllegalArgumentException` - is `obj` is not a valid type.
  See Also:
    `Format.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)`

### getAvailableLocales

    public static Locale[] getAvailableLocales()

  Get the set of locales for which complex formats are available. This is the same set as the `NumberFormat` set.

  Returns:
    available complex format locales.

### getImaginaryCharacter

    public String getImaginaryCharacter()

  Access the imaginaryCharacter.

  Returns:
    the imaginaryCharacter.

### getImaginaryFormat

    public NumberFormat getImaginaryFormat()

  Access the imaginaryFormat.

  Returns:
    the imaginaryFormat.

### getInstance

    public static ComplexFormat getInstance()

  Returns the default complex format for the current locale.

  Returns:
    the default complex format.

### getInstance

    public static ComplexFormat getInstance(Locale locale)

  Returns the default complex format for the given locale.

  Parameters:
    `locale` - the specific locale used by the format.
  Returns:
    the complex format specific to the given locale.

### getRealFormat

    public NumberFormat getRealFormat()

  Access the realFormat.

  Returns:
    the realFormat.

### parse

    public Complex parse(String source)
                  throws ParseException

  Parses a string to produce a `Complex` object.

  Parameters:
    `source` - the string to parse
  Returns:
    the parsed `Complex` object.
  Throws:
    `ParseException` - if the beginning of the specified string cannot be parsed.

### parse

    public Complex parse(String source,
                         ParsePosition pos)

  Parses a string to produce a `Complex` object.

  Parameters:
    `source` - the string to parse
    `pos` - input/ouput parsing parameter.
  Returns:
    the parsed `Complex` object.

### parseObject

    public Object parseObject(String source,
                              ParsePosition pos)

  Parses a string to produce a object.

  Parameters:
    `source` - the string to parse
    `pos` - input/ouput parsing parameter.
  Returns:
    the parsed object.
  See Also:
    `Format.parseObject(java.lang.String, java.text.ParsePosition)`

### setImaginaryCharacter

    public void setImaginaryCharacter(String imaginaryCharacter)

  Modify the imaginaryCharacter.

  Parameters:
    `imaginaryCharacter` - The new imaginaryCharacter value.
  Throws:
    `IllegalArgumentException` - if `imaginaryCharacter` is `null` or an empty string.

### setImaginaryFormat

    public void setImaginaryFormat(NumberFormat imaginaryFormat)

  Modify the imaginaryFormat.

  Parameters:
    `imaginaryFormat` - The new imaginaryFormat value.
  Throws:
    `IllegalArgumentException` - if `imaginaryFormat` is `null`.

### setRealFormat

    public void setRealFormat(NumberFormat realFormat)

  Modify the realFormat.

  Parameters:
    `realFormat` - The new realFormat value.
  Throws:
    `IllegalArgumentException` - if `realFormat` is `null`.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2003-2004 The Apache Software Foundation. All Rights Reserved.