public class ComplexFormat
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private static java.lang.String |
DEFAULT_IMAGINARY_CHARACTER
The default imaginary character.
|
private java.lang.String |
imaginaryCharacter
The notation used to signify the imaginary part of the complex number.
|
private java.text.NumberFormat |
imaginaryFormat
The format used for the imaginary part.
|
private java.text.NumberFormat |
realFormat
The format used for the real part.
|
| Constructor and Description |
|---|
ComplexFormat()
Create an instance with the default imaginary character, 'i', and the
default number format for both real and imaginary parts.
|
ComplexFormat(java.text.NumberFormat format)
Create an instance with a custom number format for both real and
imaginary parts.
|
ComplexFormat(java.text.NumberFormat realFormat,
java.text.NumberFormat imaginaryFormat)
Create an instance with a custom number format for the real part and a
custom number format for the imaginary part.
|
ComplexFormat(java.lang.String imaginaryCharacter)
Create an instance with a custom imaginary character, and the default
number format for both real and imaginary parts.
|
ComplexFormat(java.lang.String imaginaryCharacter,
java.text.NumberFormat format)
Create an instance with a custom imaginary character, and a custom number
format for both real and imaginary parts.
|
ComplexFormat(java.lang.String imaginaryCharacter,
java.text.NumberFormat realFormat,
java.text.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.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
format(Complex c)
This method calls
format(Object,StringBuffer,FieldPosition). |
java.lang.StringBuffer |
format(Complex complex,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos)
Formats a
Complex object to produce a string. |
java.lang.String |
format(java.lang.Double c)
This method calls
format(Object,StringBuffer,FieldPosition). |
java.lang.StringBuffer |
format(java.lang.Object obj,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos)
Formats a object to produce a string.
|
private java.lang.StringBuffer |
formatImaginary(double absIm,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos)
Format the absolute value of the imaginary part.
|
static java.util.Locale[] |
getAvailableLocales()
Get the set of locales for which complex formats are available.
|
java.lang.String |
getImaginaryCharacter()
Access the imaginaryCharacter.
|
java.text.NumberFormat |
getImaginaryFormat()
Access the imaginaryFormat.
|
static ComplexFormat |
getInstance()
Returns the default complex format for the current locale.
|
static ComplexFormat |
getInstance(java.util.Locale locale)
Returns the default complex format for the given locale.
|
static ComplexFormat |
getInstance(java.lang.String imaginaryCharacter,
java.util.Locale locale)
Returns the default complex format for the given locale.
|
java.text.NumberFormat |
getRealFormat()
Access the realFormat.
|
Complex |
parse(java.lang.String source)
Parses a string to produce a
Complex object. |
Complex |
parse(java.lang.String source,
java.text.ParsePosition pos)
Parses a string to produce a
Complex object. |
private static final java.lang.String DEFAULT_IMAGINARY_CHARACTER
private final java.lang.String imaginaryCharacter
private final java.text.NumberFormat imaginaryFormat
private final java.text.NumberFormat realFormat
public ComplexFormat()
public ComplexFormat(java.text.NumberFormat format)
throws NullArgumentException
format - the custom format for both real and imaginary parts.NullArgumentException - if realFormat is null.public ComplexFormat(java.text.NumberFormat realFormat,
java.text.NumberFormat imaginaryFormat)
throws NullArgumentException
realFormat - the custom format for the real part.imaginaryFormat - the custom format for the imaginary part.NullArgumentException - if imaginaryFormat is null.NullArgumentException - if realFormat is null.public ComplexFormat(java.lang.String imaginaryCharacter)
throws NullArgumentException,
NoDataException
imaginaryCharacter - The custom imaginary character.NullArgumentException - if imaginaryCharacter is
null.NoDataException - if imaginaryCharacter is an
empty string.public ComplexFormat(java.lang.String imaginaryCharacter,
java.text.NumberFormat format)
throws NullArgumentException,
NoDataException
imaginaryCharacter - The custom imaginary character.format - the custom format for both real and imaginary parts.NullArgumentException - if imaginaryCharacter is
null.NoDataException - if imaginaryCharacter is an
empty string.NullArgumentException - if format is null.public ComplexFormat(java.lang.String imaginaryCharacter,
java.text.NumberFormat realFormat,
java.text.NumberFormat imaginaryFormat)
throws NullArgumentException,
NoDataException
imaginaryCharacter - The custom imaginary character.realFormat - the custom format for the real part.imaginaryFormat - the custom format for the imaginary part.NullArgumentException - if imaginaryCharacter is
null.NoDataException - if imaginaryCharacter is an
empty string.NullArgumentException - if imaginaryFormat is null.NullArgumentException - if realFormat is null.public static java.util.Locale[] getAvailableLocales()
This is the same set as the NumberFormat set.
public java.lang.String format(Complex c)
format(Object,StringBuffer,FieldPosition).c - Complex object to format.public java.lang.String format(java.lang.Double c)
format(Object,StringBuffer,FieldPosition).c - Double object to format.public java.lang.StringBuffer format(Complex complex, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
Complex object to produce a string.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 fieldprivate java.lang.StringBuffer formatImaginary(double absIm,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos)
absIm - Absolute value of the imaginary part of a complex number.toAppendTo - where the text is to be appended.pos - On input: an alignment field, if desired. On output: the
offsets of the alignment field.public java.lang.StringBuffer format(java.lang.Object obj,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos)
throws MathIllegalArgumentException
obj must be either a
Complex object or a Number object. Any other type of
object will result in an IllegalArgumentException being thrown.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 fieldMathIllegalArgumentException - is obj is not a valid type.Format.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)public java.lang.String getImaginaryCharacter()
public java.text.NumberFormat getImaginaryFormat()
public static ComplexFormat getInstance()
public static ComplexFormat getInstance(java.util.Locale locale)
locale - the specific locale used by the format.public static ComplexFormat getInstance(java.lang.String imaginaryCharacter, java.util.Locale locale) throws NullArgumentException, NoDataException
locale - the specific locale used by the format.imaginaryCharacter - Imaginary character.NullArgumentException - if imaginaryCharacter is
null.NoDataException - if imaginaryCharacter is an
empty string.public java.text.NumberFormat getRealFormat()
public Complex parse(java.lang.String source) throws MathParseException
Complex object.source - the string to parse.Complex object.MathParseException - if the beginning of the specified string
cannot be parsed.Copyright (c) 2003-2015 Apache Software Foundation