Package org.hipparchus.complex
Class ComplexFormat
- java.lang.Object
-
- org.hipparchus.complex.ComplexFormat
-
public class ComplexFormat extends Object
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
Constructors Constructor Description ComplexFormat()
Create 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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description String
format(Double c)
This method callsformat(Object,StringBuffer,FieldPosition)
.StringBuffer
format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
Formats a object to produce a string.String
format(Complex c)
This method callsformat(Object,StringBuffer,FieldPosition)
.StringBuffer
format(Complex complex, StringBuffer toAppendTo, FieldPosition pos)
Formats aComplex
object to produce a string.static Locale[]
getAvailableLocales()
Get the set of locales for which complex formats are available.static ComplexFormat
getComplexFormat()
Returns the default complex format for the current locale.static ComplexFormat
getComplexFormat(String imaginaryCharacter, Locale locale)
Returns the default complex format for the given locale.static ComplexFormat
getComplexFormat(Locale locale)
Returns the default complex format for the given locale.String
getImaginaryCharacter()
Access the imaginaryCharacter.NumberFormat
getImaginaryFormat()
Access the imaginaryFormat.static ComplexFormat
getInstance()
Deprecated.as of 1.4, replaced bygetComplexFormat()
static ComplexFormat
getInstance(String imaginaryCharacter, Locale locale)
Deprecated.as of 1.4, replaced bygetComplexFormat(String, Locale)
static ComplexFormat
getInstance(Locale locale)
Deprecated.as of 1.4, replaced bygetComplexFormat(Locale)
NumberFormat
getRealFormat()
Access the realFormat.Complex
parse(String source)
Parses a string to produce aComplex
object.Complex
parse(String source, ParsePosition pos)
Parses a string to produce aComplex
object.
-
-
-
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) throws NullArgumentException
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
- ifrealFormat
isnull
.
-
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
- ifimaginaryFormat
isnull
.NullArgumentException
- ifrealFormat
isnull
.
-
ComplexFormat
public ComplexFormat(String imaginaryCharacter) throws MathIllegalArgumentException, NullArgumentException
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
- ifimaginaryCharacter
isnull
.MathIllegalArgumentException
- ifimaginaryCharacter
is an empty string.
-
ComplexFormat
public ComplexFormat(String imaginaryCharacter, NumberFormat format) throws MathIllegalArgumentException, NullArgumentException
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
- ifimaginaryCharacter
isnull
.MathIllegalArgumentException
- ifimaginaryCharacter
is an empty string.NullArgumentException
- ifformat
isnull
.
-
ComplexFormat
public ComplexFormat(String imaginaryCharacter, NumberFormat realFormat, NumberFormat imaginaryFormat) throws MathIllegalArgumentException, NullArgumentException
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
- ifimaginaryCharacter
isnull
.MathIllegalArgumentException
- ifimaginaryCharacter
is an empty string.NullArgumentException
- ifimaginaryFormat
isnull
.NullArgumentException
- ifrealFormat
isnull
.
-
-
Method Detail
-
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.
-
format
public String format(Complex c)
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
public String format(Double c)
This method callsformat(Object,StringBuffer,FieldPosition)
.- Parameters:
c
- Double object to format.- Returns:
- A formatted number.
-
format
public StringBuffer format(Complex complex, StringBuffer toAppendTo, FieldPosition pos)
Formats aComplex
object 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.obj
must be either aComplex
object or aNumber
object. Any other type of object will result in anIllegalArgumentException
being 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
- isobj
is not a valid type.- See Also:
Format.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
-
getImaginaryCharacter
public String getImaginaryCharacter()
Access the imaginaryCharacter.- Returns:
- the imaginaryCharacter.
-
getImaginaryFormat
public NumberFormat getImaginaryFormat()
Access the imaginaryFormat.- Returns:
- the imaginaryFormat.
-
getComplexFormat
public static ComplexFormat getComplexFormat()
Returns the default complex format for the current locale.- Returns:
- the default complex format.
- Since:
- 1.4
-
getInstance
@Deprecated public static ComplexFormat getInstance()
Deprecated.as of 1.4, replaced bygetComplexFormat()
Returns the default complex format for the current locale.- Returns:
- the default complex format.
-
getComplexFormat
public static ComplexFormat getComplexFormat(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.
- Since:
- 1.4
-
getInstance
@Deprecated public static ComplexFormat getInstance(Locale locale)
Deprecated.as of 1.4, replaced bygetComplexFormat(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.
-
getComplexFormat
public static ComplexFormat getComplexFormat(String imaginaryCharacter, Locale locale) throws MathIllegalArgumentException, NullArgumentException
Returns the default complex format for the given locale.- Parameters:
locale
- the specific locale used by the format.imaginaryCharacter
- Imaginary character.- Returns:
- the complex format specific to the given locale.
- Throws:
NullArgumentException
- ifimaginaryCharacter
isnull
.MathIllegalArgumentException
- ifimaginaryCharacter
is an empty string.- Since:
- 1.4
-
getInstance
@Deprecated public static ComplexFormat getInstance(String imaginaryCharacter, Locale locale) throws MathIllegalArgumentException, NullArgumentException
Deprecated.as of 1.4, replaced bygetComplexFormat(String, Locale)
Returns the default complex format for the given locale.- Parameters:
locale
- the specific locale used by the format.imaginaryCharacter
- Imaginary character.- Returns:
- the complex format specific to the given locale.
- Throws:
NullArgumentException
- ifimaginaryCharacter
isnull
.MathIllegalArgumentException
- ifimaginaryCharacter
is an empty string.
-
getRealFormat
public NumberFormat getRealFormat()
Access the realFormat.- Returns:
- the realFormat.
-
parse
public Complex parse(String source) throws MathIllegalStateException
Parses a string to produce aComplex
object.- Parameters:
source
- the string to parse.- Returns:
- the parsed
Complex
object. - Throws:
MathIllegalStateException
- if the beginning of the specified string cannot be parsed.
-
parse
public Complex parse(String source, ParsePosition pos)
Parses a string to produce aComplex
object.- Parameters:
source
- the string to parsepos
- input/ouput parsing parameter.- Returns:
- the parsed
Complex
object.
-
-