|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.text.Format
org.apache.commons.math.complex.ComplexFormat
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.
Nested Class Summary |
Nested classes inherited from class java.text.Format |
java.text.Format.Field |
Field Summary | |
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. |
(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(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. |
Method Summary | |
java.lang.StringBuffer |
format(Complex complex,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos)
Formats a Complex object to produce a string. |
java.lang.StringBuffer |
format(java.lang.Object obj,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos)
Formats a object to produce a string. |
static java.lang.String |
formatComplex(Complex c)
This static method calls formatComplex() on a default instance of ComplexFormat. |
private java.lang.StringBuffer |
formatDouble(double value,
java.text.NumberFormat format,
java.lang.StringBuffer toAppendTo,
java.text.FieldPosition pos)
Formats a double value to produce a string. |
static java.util.Locale[] |
getAvailableLocales()
Get the set of locales for which complex formats are available. |
private static java.text.NumberFormat |
getDefaultNumberFormat()
Create a default number format. |
private static java.text.NumberFormat |
getDefaultNumberFormat(java.util.Locale locale)
Create a default number format. |
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. |
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 void |
parseAndIgnoreWhitespace(java.lang.String source,
java.text.ParsePosition pos)
Parses source until a non-whitespace character is found. |
private char |
parseNextCharacter(java.lang.String source,
java.text.ParsePosition pos)
Parses source until a non-whitespace character is found. |
private java.lang.Number |
parseNumber(java.lang.String source,
double value,
java.text.ParsePosition pos)
Parses source for a special double values. |
private java.lang.Number |
parseNumber(java.lang.String source,
java.text.NumberFormat format,
java.text.ParsePosition pos)
Parses source for a number. |
java.lang.Object |
parseObject(java.lang.String source,
java.text.ParsePosition pos)
Parses a string to produce a object. |
void |
setImaginaryCharacter(java.lang.String imaginaryCharacter)
Modify the imaginaryCharacter. |
void |
setImaginaryFormat(java.text.NumberFormat imaginaryFormat)
Modify the imaginaryFormat. |
void |
setRealFormat(java.text.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 |
static final long serialVersionUID
private static final java.lang.String DEFAULT_IMAGINARY_CHARACTER
private java.lang.String imaginaryCharacter
private java.text.NumberFormat imaginaryFormat
private java.text.NumberFormat realFormat
Constructor Detail |
public ComplexFormat()
public ComplexFormat(java.text.NumberFormat format)
format
- the custom format for both real and imaginary parts.public ComplexFormat(java.text.NumberFormat realFormat, java.text.NumberFormat imaginaryFormat)
realFormat
- the custom format for the real part.imaginaryFormat
- the custom format for the imaginary part.public ComplexFormat(java.lang.String imaginaryCharacter)
imaginaryCharacter
- The custom imaginary character.public ComplexFormat(java.lang.String imaginaryCharacter, java.text.NumberFormat format)
imaginaryCharacter
- The custom imaginary character.format
- the custom format for both real and imaginary parts.public ComplexFormat(java.lang.String imaginaryCharacter, java.text.NumberFormat realFormat, java.text.NumberFormat imaginaryFormat)
imaginaryCharacter
- The custom imaginary character.realFormat
- the custom format for the real part.imaginaryFormat
- the custom format for the imaginary part.Method Detail |
public static java.lang.String formatComplex(Complex c)
c
- Complex 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 field
public java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
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 field
java.lang.IllegalArgumentException
- is obj
is not a valid type.Format.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
private java.lang.StringBuffer formatDouble(double value, java.text.NumberFormat format, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
format
. There are
three exceptions to this:
value
- the double to format.format
- the format used.toAppendTo
- where the text is to be appendedpos
- On input: an alignment field, if desired. On output: the
offsets of the alignment field
public static java.util.Locale[] getAvailableLocales()
NumberFormat
set.
private static java.text.NumberFormat getDefaultNumberFormat()
NumberFormat.getInstance()
with the only customizing is the
maximum number of fraction digits, which is set to 2.
private static java.text.NumberFormat getDefaultNumberFormat(java.util.Locale locale)
NumberFormat.getInstance(java.util.Locale)
with the only
customizing is the maximum number of fraction digits, which is set to 2.
locale
- the specific locale used by the format.
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 java.text.NumberFormat getRealFormat()
public Complex parse(java.lang.String source) throws java.text.ParseException
Complex
object.
source
- the string to parse
Complex
object.
java.text.ParseException
- if the beginning of the specified string
cannot be parsed.public Complex parse(java.lang.String source, java.text.ParsePosition pos)
Complex
object.
source
- the string to parsepos
- input/ouput parsing parameter.
Complex
object.private void parseAndIgnoreWhitespace(java.lang.String source, java.text.ParsePosition pos)
source
until a non-whitespace character is found.
source
- the string to parsepos
- input/ouput parsing parameter. On output, pos
holds the index of the next non-whitespace character.private char parseNextCharacter(java.lang.String source, java.text.ParsePosition pos)
source
until a non-whitespace character is found.
source
- the string to parsepos
- input/ouput parsing parameter.
private java.lang.Number parseNumber(java.lang.String source, double value, java.text.ParsePosition pos)
source
for a special double values. These values
include Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY.
source
- the string to parsevalue
- the special value to parse.pos
- input/ouput parsing parameter.
private java.lang.Number parseNumber(java.lang.String source, java.text.NumberFormat format, java.text.ParsePosition pos)
source
for a number. This method can parse normal,
numeric values as well as special values. These special values include
Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY.
source
- the string to parseformat
- the number format used to parse normal, numeric values.pos
- input/ouput parsing parameter.
public java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)
source
- the string to parsepos
- input/ouput parsing parameter.
Format.parseObject(java.lang.String, java.text.ParsePosition)
public void setImaginaryCharacter(java.lang.String imaginaryCharacter)
imaginaryCharacter
- The new imaginaryCharacter value.
java.lang.IllegalArgumentException
- if imaginaryCharacter
is
null
or an empty string.public void setImaginaryFormat(java.text.NumberFormat imaginaryFormat)
imaginaryFormat
- The new imaginaryFormat value.
java.lang.IllegalArgumentException
- if imaginaryFormat
is
null
.public void setRealFormat(java.text.NumberFormat realFormat)
realFormat
- The new realFormat value.
java.lang.IllegalArgumentException
- if realFormat
is
null
.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |