Package org.apache.commons.math3.complex
Class ComplexFormat
java.lang.Object
org.apache.commons.math3.complex.ComplexFormat
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.
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an instance with the default imaginary character, 'i', and the default number format for both real and imaginary parts.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.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. -
Method Summary
Modifier and TypeMethodDescriptionThis method callsformat(Object,StringBuffer,FieldPosition).format(Object obj, StringBuffer toAppendTo, FieldPosition pos) Formats a object to produce a string.This method callsformat(Object,StringBuffer,FieldPosition).format(Complex complex, StringBuffer toAppendTo, FieldPosition pos) Formats aComplexobject to produce a string.static Locale[]Get the set of locales for which complex formats are available.Access the imaginaryCharacter.Access the imaginaryFormat.static ComplexFormatReturns the default complex format for the current locale.static ComplexFormatgetInstance(String imaginaryCharacter, Locale locale) Returns the default complex format for the given locale.static ComplexFormatgetInstance(Locale locale) Returns the default complex format for the given locale.Access the realFormat.Parses a string to produce aComplexobject.parse(String source, ParsePosition pos) Parses a string to produce aComplexobject.
-
Constructor Details
-
ComplexFormat
public ComplexFormat()Create an instance with the default imaginary character, 'i', and the default number format for both real and imaginary parts. -
ComplexFormat
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.- Throws:
NullArgumentException- ifrealFormatisnull.
-
ComplexFormat
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- the custom format for the real part.imaginaryFormat- the custom format for the imaginary part.- Throws:
NullArgumentException- ifimaginaryFormatisnull.NullArgumentException- ifrealFormatisnull.
-
ComplexFormat
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.- Throws:
NullArgumentException- ifimaginaryCharacterisnull.NoDataException- ifimaginaryCharacteris an empty string.
-
ComplexFormat
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- The custom imaginary character.format- the custom format for both real and imaginary parts.- Throws:
NullArgumentException- ifimaginaryCharacterisnull.NoDataException- ifimaginaryCharacteris an empty string.NullArgumentException- ifformatisnull.
-
ComplexFormat
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- The custom imaginary character.realFormat- the custom format for the real part.imaginaryFormat- the custom format for the imaginary part.- Throws:
NullArgumentException- ifimaginaryCharacterisnull.NoDataException- ifimaginaryCharacteris an empty string.NullArgumentException- ifimaginaryFormatisnull.NullArgumentException- ifrealFormatisnull.
-
-
Method Details
-
getAvailableLocales
Get the set of locales for which complex formats are available.This is the same set as the
NumberFormatset.- Returns:
- available complex format locales.
-
format
This method callsformat(Object,StringBuffer,FieldPosition).- Parameters:
c- Complex object to format.- Returns:
- A formatted number in the form "Re(c) + Im(c)i".
-
format
This method callsformat(Object,StringBuffer,FieldPosition).- Parameters:
c- Double object to format.- Returns:
- A formatted number.
-
format
Formats aComplexobject to produce a string.- Parameters:
complex- the object to format.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.
-
format
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) throws MathIllegalArgumentException Formats a object to produce a string.objmust be either aComplexobject or aNumberobject. Any other type of object will result in anIllegalArgumentExceptionbeing thrown.- Parameters:
obj- the object to format.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.
- Throws:
MathIllegalArgumentException- isobjis not a valid type.- See Also:
-
getImaginaryCharacter
Access the imaginaryCharacter.- Returns:
- the imaginaryCharacter.
-
getImaginaryFormat
Access the imaginaryFormat.- Returns:
- the imaginaryFormat.
-
getInstance
Returns the default complex format for the current locale.- Returns:
- the default complex format.
-
getInstance
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.
-
getInstance
public static ComplexFormat getInstance(String imaginaryCharacter, Locale locale) throws NullArgumentException, NoDataException Returns the default complex format for the given locale.- Parameters:
imaginaryCharacter- Imaginary character.locale- the specific locale used by the format.- Returns:
- the complex format specific to the given locale.
- Throws:
NullArgumentException- ifimaginaryCharacterisnull.NoDataException- ifimaginaryCharacteris an empty string.
-
getRealFormat
Access the realFormat.- Returns:
- the realFormat.
-
parse
Parses a string to produce aComplexobject.- Parameters:
source- the string to parse.- Returns:
- the parsed
Complexobject. - Throws:
MathParseException- if the beginning of the specified string cannot be parsed.
-
parse
Parses a string to produce aComplexobject.- Parameters:
source- the string to parsepos- input/ouput parsing parameter.- Returns:
- the parsed
Complexobject.
-