public class RealMatrixFormat extends Object
nxm
matrix in components list format
"{{a00,a01, ...,
a0m-1},{a10,
a11, ..., a1m-1},{...},{
an-10, an-11, ...,
an-1m-1}}".
The prefix and suffix "{" and "}", the row prefix and suffix "{" and "}", the row separator "," and the column separator "," can be replaced by any user-defined strings. The number format for components can be configured.
White space is ignored at parse time, even if it is in the prefix, suffix or separator specifications. So even if the default separator does include a space character that is used at format time, both input string "{{1,1,1}}" and " { { 1 , 1 , 1 } } " will be parsed without error and the same matrix will be returned. In the second case, however, the parse position after parsing will be just after the closing curly brace, i.e. just before the trailing space.
Note: the grouping functionality of the used NumberFormat
is
disabled to prevent problems when parsing (e.g. 1,345.34 would be a valid number
but conflicts with the default column separator).
Constructor | Description |
---|---|
RealMatrixFormat() |
Create an instance with default settings.
|
RealMatrixFormat(String prefix,
String suffix,
String rowPrefix,
String rowSuffix,
String rowSeparator,
String columnSeparator) |
Create an instance with custom prefix, suffix and separator.
|
RealMatrixFormat(String prefix,
String suffix,
String rowPrefix,
String rowSuffix,
String rowSeparator,
String columnSeparator,
NumberFormat format) |
Create an instance with custom prefix, suffix, separator and format
for components.
|
RealMatrixFormat(NumberFormat format) |
Create an instance with a custom number format for components.
|
Modifier and Type | Method | Description |
---|---|---|
String |
format(RealMatrix m) |
This method calls
format(RealMatrix,StringBuffer,FieldPosition) . |
StringBuffer |
format(RealMatrix matrix,
StringBuffer toAppendTo,
FieldPosition pos) |
Formats a
RealMatrix object to produce a string. |
static Locale[] |
getAvailableLocales() |
Get the set of locales for which real vectors formats are available.
|
String |
getColumnSeparator() |
Get the format separator between components.
|
NumberFormat |
getFormat() |
Get the components format.
|
static RealMatrixFormat |
getInstance() |
Returns the default real vector format for the current locale.
|
static RealMatrixFormat |
getInstance(Locale locale) |
Returns the default real vector format for the given locale.
|
String |
getPrefix() |
Get the format prefix.
|
String |
getRowPrefix() |
Get the format prefix.
|
String |
getRowSeparator() |
Get the format separator between rows of the matrix.
|
String |
getRowSuffix() |
Get the format suffix.
|
String |
getSuffix() |
Get the format suffix.
|
RealMatrix |
parse(String source) |
Parse a string to produce a
RealMatrix object. |
RealMatrix |
parse(String source,
ParsePosition pos) |
Parse a string to produce a
RealMatrix object. |
public RealMatrixFormat()
The instance uses the default prefix, suffix and row/column separator: "[", "]", ";" and ", " and the default number format for components.
public RealMatrixFormat(NumberFormat format)
format
- the custom format for components.public RealMatrixFormat(String prefix, String suffix, String rowPrefix, String rowSuffix, String rowSeparator, String columnSeparator)
prefix
- prefix to use instead of the default "{"suffix
- suffix to use instead of the default "}"rowPrefix
- row prefix to use instead of the default "{"rowSuffix
- row suffix to use instead of the default "}"rowSeparator
- tow separator to use instead of the default ";"columnSeparator
- column separator to use instead of the default ", "public RealMatrixFormat(String prefix, String suffix, String rowPrefix, String rowSuffix, String rowSeparator, String columnSeparator, NumberFormat format)
prefix
- prefix to use instead of the default "{"suffix
- suffix to use instead of the default "}"rowPrefix
- row prefix to use instead of the default "{"rowSuffix
- row suffix to use instead of the default "}"rowSeparator
- tow separator to use instead of the default ";"columnSeparator
- column separator to use instead of the default ", "format
- the custom format for components.public static Locale[] getAvailableLocales()
This is the same set as the NumberFormat
set.
public String getPrefix()
public String getSuffix()
public String getRowPrefix()
public String getRowSuffix()
public String getRowSeparator()
public String getColumnSeparator()
public NumberFormat getFormat()
public static RealMatrixFormat getInstance()
public static RealMatrixFormat getInstance(Locale locale)
locale
- the specific locale used by the format.public String format(RealMatrix m)
format(RealMatrix,StringBuffer,FieldPosition)
.m
- RealMatrix object to format.public StringBuffer format(RealMatrix matrix, StringBuffer toAppendTo, FieldPosition pos)
RealMatrix
object to produce a string.matrix
- 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 fieldpublic RealMatrix parse(String source)
RealMatrix
object.source
- String to parse.RealMatrix
object.MathIllegalStateException
- if the beginning of the specified string
cannot be parsed.public RealMatrix parse(String source, ParsePosition pos)
RealMatrix
object.source
- String to parse.pos
- input/ouput parsing parameter.RealMatrix
object.Copyright © 2016–2018 Hipparchus.org. All rights reserved.