Top Description Fields Constructors Methods
org.apache.commons.math3.complex

public Class ComplexFormat

extends Object
Class Inheritance
Imports
java.text.FieldPosition, .NumberFormat, .ParsePosition, java.util.Locale, org.apache.commons.math3.exception.MathIllegalArgumentException, .MathParseException, .NoDataException, .NullArgumentException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.util.CompositeFormat

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

Field Summary

Modifier and TypeField and Description
private static final String
DEFAULT_IMAGINARY_CHARACTER

The default imaginary character.

private final String
imaginaryCharacter

The notation used to signify the imaginary part of the complex number.

private final NumberFormat
imaginaryFormat

The format used for the imaginary part.

private final NumberFormat
realFormat

The format used for the real part.

Constructor Summary

AccessConstructor and Description
public
ComplexFormat()

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

public
ComplexFormat(NumberFormat
the custom format for both real and imaginary parts.
format
)

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

public
ComplexFormat(NumberFormat
the custom format for the real part.
realFormat
,
NumberFormat
the custom format for the imaginary part.
imaginaryFormat
)

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

public
ComplexFormat(String
The custom imaginary character.
imaginaryCharacter
)

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

public
ComplexFormat(String
The custom imaginary character.
imaginaryCharacter
,
NumberFormat
the custom format for both real and imaginary parts.
format
)

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

public
ComplexFormat(String
The custom imaginary character.
imaginaryCharacter
,
NumberFormat
the custom format for the real part.
realFormat
,
NumberFormat
the custom format for the imaginary part.
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

Modifier and TypeMethod and Description
public String

Returns:

A formatted number in the form "Re(c) + Im(c)i".
format
(Complex
Complex object to format.
c
)

This method calls format(Object, StringBuffer, FieldPosition).

public String

Returns:

A formatted number.
format
(Double
Double object to format.
c
)

This method calls format(Object, StringBuffer, FieldPosition).

public StringBuffer

Returns:

the value passed in as toAppendTo.
format
(Complex
the object to format.
complex
,
StringBuffer
where the text is to be appended
toAppendTo
,
FieldPosition
On input: an alignment field, if desired. On output: the offsets of the alignment field
pos
)

Formats a Complex object to produce a string.

public StringBuffer

Returns:

the value passed in as toAppendTo.
format
(Object
the object to format.
obj
,
StringBuffer
where the text is to be appended
toAppendTo
,
FieldPosition
On input: an alignment field, if desired. On output: the offsets of the alignment field
pos
)

Formats a object to produce a string.

private StringBuffer

Returns:

the value passed in as toAppendTo.
formatImaginary
(double
Absolute value of the imaginary part of a complex number.
absIm
,
StringBuffer
where the text is to be appended.
toAppendTo
,
FieldPosition
On input: an alignment field, if desired. On output: the offsets of the alignment field.
pos
)

Format the absolute value of the imaginary part.

public static Locale[]

Returns:

available complex format locales.
getAvailableLocales
()

Get the set of locales for which complex formats are available.

public String

Returns:

the imaginaryCharacter.
getImaginaryCharacter
()

Access the imaginaryCharacter.

public NumberFormat

Returns:

the imaginaryFormat.
getImaginaryFormat
()

Access the imaginaryFormat.

public static ComplexFormat

Returns:

the default complex format.
getInstance
()

Returns the default complex format for the current locale.

public static ComplexFormat

Returns:

the complex format specific to the given locale.
getInstance
(Locale
the specific locale used by the format.
locale
)

Returns the default complex format for the given locale.

public static ComplexFormat

Returns:

the complex format specific to the given locale.
getInstance
(String
Imaginary character.
imaginaryCharacter
,
Locale
the specific locale used by the format.
locale
)

Returns the default complex format for the given locale.

public NumberFormat

Returns:

the realFormat.
getRealFormat
()

Access the realFormat.

public Complex

Returns:

the parsed Complex object.
parse
(String
the string to parse.
source
)

Parses a string to produce a Complex object.

public Complex

Returns:

the parsed Complex object.
parse
(String
the string to parse
source
,
ParsePosition
input/ouput parsing parameter.
pos
)

Parses a string to produce a Complex object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_IMAGINARY_CHARACTERback to summary
private static final String DEFAULT_IMAGINARY_CHARACTER

The default imaginary character.

imaginaryCharacterback to summary
private final String imaginaryCharacter

The notation used to signify the imaginary part of the complex number.

imaginaryFormatback to summary
private final NumberFormat imaginaryFormat

The format used for the imaginary part.

realFormatback to summary
private final NumberFormat realFormat

The format used for the real part.

Constructor Detail

ComplexFormatback to summary
public ComplexFormat()

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

ComplexFormatback to summary
public ComplexFormat(NumberFormat format) throws NullArgumentException

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

Parameters
format:NumberFormat

the custom format for both real and imaginary parts.

Exceptions
NullArgumentException:
if realFormat is null.
ComplexFormatback to summary
public ComplexFormat(NumberFormat realFormat, NumberFormat imaginaryFormat) throws NullArgumentException

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

Parameters
realFormat:NumberFormat

the custom format for the real part.

imaginaryFormat:NumberFormat

the custom format for the imaginary part.

Exceptions
NullArgumentException:
  • if imaginaryFormat is null.
  • if realFormat is null.
ComplexFormatback to summary
public ComplexFormat(String imaginaryCharacter) throws NullArgumentException, NoDataException

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

Parameters
imaginaryCharacter:String

The custom imaginary character.

Exceptions
NullArgumentException:
if imaginaryCharacter is null.
NoDataException:
if imaginaryCharacter is an empty string.
ComplexFormatback to summary
public ComplexFormat(String imaginaryCharacter, NumberFormat format) throws NullArgumentException, NoDataException

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

Parameters
imaginaryCharacter:String

The custom imaginary character.

format:NumberFormat

the custom format for both real and imaginary parts.

Exceptions
NullArgumentException:
  • if imaginaryCharacter is null.
  • if format is null.
NoDataException:
if imaginaryCharacter is an empty string.
ComplexFormatback to summary
public ComplexFormat(String imaginaryCharacter, NumberFormat realFormat, NumberFormat imaginaryFormat) throws NullArgumentException, NoDataException

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:String

The custom imaginary character.

realFormat:NumberFormat

the custom format for the real part.

imaginaryFormat:NumberFormat

the custom format for the imaginary part.

Exceptions
NullArgumentException:
  • if imaginaryCharacter is null.
  • if imaginaryFormat is null.
  • if realFormat is null.
NoDataException:
if imaginaryCharacter is an empty string.

Method Detail

formatback to summary
public String format(Complex c)

This method calls format(Object, StringBuffer, FieldPosition).

Parameters
c:Complex

Complex object to format.

Returns:String

A formatted number in the form "Re(c) + Im(c)i".

formatback to summary
public String format(Double c)

This method calls format(Object, StringBuffer, FieldPosition).

Parameters
c:Double

Double object to format.

Returns:String

A formatted number.

formatback to summary
public StringBuffer format(Complex complex, StringBuffer toAppendTo, FieldPosition pos)

Formats a Complex object to produce a string.

Parameters
complex:Complex

the object to format.

toAppendTo:StringBuffer

where the text is to be appended

pos:FieldPosition

On input: an alignment field, if desired. On output: the offsets of the alignment field

Returns:StringBuffer

the value passed in as toAppendTo.

formatback to summary
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) throws MathIllegalArgumentException

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:Object

the object to format.

toAppendTo:StringBuffer

where the text is to be appended

pos:FieldPosition

On input: an alignment field, if desired. On output: the offsets of the alignment field

Returns:StringBuffer

the value passed in as toAppendTo.

Exceptions
MathIllegalArgumentException:
is obj is not a valid type.
See Also
java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
formatImaginaryback to summary
private StringBuffer formatImaginary(double absIm, StringBuffer toAppendTo, FieldPosition pos)

Format the absolute value of the imaginary part.

Parameters
absIm:double

Absolute value of the imaginary part of a complex number.

toAppendTo:StringBuffer

where the text is to be appended.

pos:FieldPosition

On input: an alignment field, if desired. On output: the offsets of the alignment field.

Returns:StringBuffer

the value passed in as toAppendTo.

getAvailableLocalesback to summary
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:Locale[]

available complex format locales.

getImaginaryCharacterback to summary
public String getImaginaryCharacter()

Access the imaginaryCharacter.

Returns:String

the imaginaryCharacter.

getImaginaryFormatback to summary
public NumberFormat getImaginaryFormat()

Access the imaginaryFormat.

Returns:NumberFormat

the imaginaryFormat.

getInstanceback to summary
public static ComplexFormat getInstance()

Returns the default complex format for the current locale.

Returns:ComplexFormat

the default complex format.

getInstanceback to summary
public static ComplexFormat getInstance(Locale locale)

Returns the default complex format for the given locale.

Parameters
locale:Locale

the specific locale used by the format.

Returns:ComplexFormat

the complex format specific to the given locale.

getInstanceback to summary
public static ComplexFormat getInstance(String imaginaryCharacter, Locale locale) throws NullArgumentException, NoDataException

Returns the default complex format for the given locale.

Parameters
imaginaryCharacter:String

Imaginary character.

locale:Locale

the specific locale used by the format.

Returns:ComplexFormat

the complex format specific to the given locale.

Exceptions
NullArgumentException:
if imaginaryCharacter is null.
NoDataException:
if imaginaryCharacter is an empty string.
getRealFormatback to summary
public NumberFormat getRealFormat()

Access the realFormat.

Returns:NumberFormat

the realFormat.

parseback to summary
public Complex parse(String source) throws MathParseException

Parses a string to produce a Complex object.

Parameters
source:String

the string to parse.

Returns:Complex

the parsed Complex object.

Exceptions
MathParseException:
if the beginning of the specified string cannot be parsed.
parseback to summary
public Complex parse(String source, ParsePosition pos)

Parses a string to produce a Complex object.

Parameters
source:String

the string to parse

pos:ParsePosition

input/ouput parsing parameter.

Returns:Complex

the parsed Complex object.