Top Description Fields Constructors Methods
org.apache.commons.math3.linear

public Class RealMatrixFormat

extends Object
Class Inheritance
Imports
java.text.FieldPosition, .NumberFormat, .ParsePosition, java.util.ArrayList, .List, .Locale, org.apache.commons.math3.exception.MathParseException, org.apache.commons.math3.util.CompositeFormat

Formats a 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).

Since
3.1

Field Summary

Modifier and TypeField and Description
private final String
columnSeparator

Column separator.

private static final String
DEFAULT_COLUMN_SEPARATOR

The default column separator: ",".

private static final String
DEFAULT_PREFIX

The default prefix: "{".

private static final String
DEFAULT_ROW_PREFIX

The default row prefix: "{".

private static final String
DEFAULT_ROW_SEPARATOR

The default row separator: ",".

private static final String
DEFAULT_ROW_SUFFIX

The default row suffix: "}".

private static final String
DEFAULT_SUFFIX

The default suffix: "}".

private final NumberFormat
format

The format used for components.

private final String
prefix

Prefix.

private final String
rowPrefix

Row prefix.

private final String
rowSeparator

Row separator.

private final String
rowSuffix

Row suffix.

private final String
suffix

Suffix.

Constructor Summary

AccessConstructor and Description
public
RealMatrixFormat()

Create an instance with default settings.

public
RealMatrixFormat(final NumberFormat
the custom format for components.
format
)

Create an instance with a custom number format for components.

public
RealMatrixFormat(final String
prefix to use instead of the default "{"
prefix
,
final String
suffix to use instead of the default "}"
suffix
,
final String
row prefix to use instead of the default "{"
rowPrefix
,
final String
row suffix to use instead of the default "}"
rowSuffix
,
final String
tow separator to use instead of the default ";"
rowSeparator
,
final String
column separator to use instead of the default ", "
columnSeparator
)

Create an instance with custom prefix, suffix and separator.

public
RealMatrixFormat(final String
prefix to use instead of the default "{"
prefix
,
final String
suffix to use instead of the default "}"
suffix
,
final String
row prefix to use instead of the default "{"
rowPrefix
,
final String
row suffix to use instead of the default "}"
rowSuffix
,
final String
tow separator to use instead of the default ";"
rowSeparator
,
final String
column separator to use instead of the default ", "
columnSeparator
,
final NumberFormat
the custom format for components.
format
)

Create an instance with custom prefix, suffix, separator and format for components.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

a formatted matrix.
format
(RealMatrix
RealMatrix object to format.
m
)

This method calls format(RealMatrix, StringBuffer, FieldPosition).

public StringBuffer

Returns:

the value passed in as toAppendTo.
format
(RealMatrix
the object to format.
matrix
,
StringBuffer
where the text is to be appended
toAppendTo
,
FieldPosition
On input: an alignment field, if desired. On output: the offsets of the alignment field
pos
)

Formats a RealMatrix object to produce a string.

public static Locale[]

Returns:

available real vector format locales.
getAvailableLocales
()

Get the set of locales for which real vectors formats are available.

public String

Returns:

format separator between components.
getColumnSeparator
()

Get the format separator between components.

public NumberFormat

Returns:

components format.
getFormat
()

Get the components format.

public static RealMatrixFormat

Returns:

the default real vector format.
getInstance
()

Returns the default real vector format for the current locale.

public static RealMatrixFormat

Returns:

the real vector format specific to the given locale.
getInstance
(final Locale
the specific locale used by the format.
locale
)

Returns the default real vector format for the given locale.

public String

Returns:

format prefix.
getPrefix
()

Get the format prefix.

public String

Returns:

format prefix.
getRowPrefix
()

Get the format prefix.

public String

Returns:

format separator for rows.
getRowSeparator
()

Get the format separator between rows of the matrix.

public String

Returns:

format suffix.
getRowSuffix
()

Get the format suffix.

public String

Returns:

format suffix.
getSuffix
()

Get the format suffix.

public RealMatrix

Returns:

the parsed RealMatrix object.
parse
(String
String to parse.
source
)

Parse a string to produce a RealMatrix object.

public RealMatrix

Returns:

the parsed RealMatrix object.
parse
(String
String to parse.
source
,
ParsePosition
input/ouput parsing parameter.
pos
)

Parse a string to produce a RealMatrix object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

columnSeparatorback to summary
private final String columnSeparator

Column separator.

DEFAULT_COLUMN_SEPARATORback to summary
private static final String DEFAULT_COLUMN_SEPARATOR

The default column separator: ",".

DEFAULT_PREFIXback to summary
private static final String DEFAULT_PREFIX

The default prefix: "{".

DEFAULT_ROW_PREFIXback to summary
private static final String DEFAULT_ROW_PREFIX

The default row prefix: "{".

DEFAULT_ROW_SEPARATORback to summary
private static final String DEFAULT_ROW_SEPARATOR

The default row separator: ",".

DEFAULT_ROW_SUFFIXback to summary
private static final String DEFAULT_ROW_SUFFIX

The default row suffix: "}".

DEFAULT_SUFFIXback to summary
private static final String DEFAULT_SUFFIX

The default suffix: "}".

formatback to summary
private final NumberFormat format

The format used for components.

prefixback to summary
private final String prefix

Prefix.

rowPrefixback to summary
private final String rowPrefix

Row prefix.

rowSeparatorback to summary
private final String rowSeparator

Row separator.

rowSuffixback to summary
private final String rowSuffix

Row suffix.

suffixback to summary
private final String suffix

Suffix.

Constructor Detail

RealMatrixFormatback to summary
public RealMatrixFormat()

Create an instance with default settings.

The instance uses the default prefix, suffix and row/column separator: "[", "]", ";" and ", " and the default number format for components.

RealMatrixFormatback to summary
public RealMatrixFormat(final NumberFormat format)

Create an instance with a custom number format for components.

Parameters
format:NumberFormat

the custom format for components.

RealMatrixFormatback to summary
public RealMatrixFormat(final String prefix, final String suffix, final String rowPrefix, final String rowSuffix, final String rowSeparator, final String columnSeparator)

Create an instance with custom prefix, suffix and separator.

Parameters
prefix:String

prefix to use instead of the default "{"

suffix:String

suffix to use instead of the default "}"

rowPrefix:String

row prefix to use instead of the default "{"

rowSuffix:String

row suffix to use instead of the default "}"

rowSeparator:String

tow separator to use instead of the default ";"

columnSeparator:String

column separator to use instead of the default ", "

RealMatrixFormatback to summary
public RealMatrixFormat(final String prefix, final String suffix, final String rowPrefix, final String rowSuffix, final String rowSeparator, final String columnSeparator, final NumberFormat format)

Create an instance with custom prefix, suffix, separator and format for components.

Parameters
prefix:String

prefix to use instead of the default "{"

suffix:String

suffix to use instead of the default "}"

rowPrefix:String

row prefix to use instead of the default "{"

rowSuffix:String

row suffix to use instead of the default "}"

rowSeparator:String

tow separator to use instead of the default ";"

columnSeparator:String

column separator to use instead of the default ", "

format:NumberFormat

the custom format for components.

Method Detail

formatback to summary
public String format(RealMatrix m)

This method calls format(RealMatrix, StringBuffer, FieldPosition).

Parameters
m:RealMatrix

RealMatrix object to format.

Returns:String

a formatted matrix.

formatback to summary
public StringBuffer format(RealMatrix matrix, StringBuffer toAppendTo, FieldPosition pos)

Formats a RealMatrix object to produce a string.

Parameters
matrix:RealMatrix

the object to format.

toAppendTo:StringBuffer

where the text is to be appended

pos:FieldPosition

On input: an alignment field, if desired. On output: the offsets of the alignment field

Returns:StringBuffer

the value passed in as toAppendTo.

getAvailableLocalesback to summary
public static Locale[] getAvailableLocales()

Get the set of locales for which real vectors formats are available.

This is the same set as the NumberFormat set.

Returns:Locale[]

available real vector format locales.

getColumnSeparatorback to summary
public String getColumnSeparator()

Get the format separator between components.

Returns:String

format separator between components.

getFormatback to summary
public NumberFormat getFormat()

Get the components format.

Returns:NumberFormat

components format.

getInstanceback to summary
public static RealMatrixFormat getInstance()

Returns the default real vector format for the current locale.

Returns:RealMatrixFormat

the default real vector format.

getInstanceback to summary
public static RealMatrixFormat getInstance(final Locale locale)

Returns the default real vector format for the given locale.

Parameters
locale:Locale

the specific locale used by the format.

Returns:RealMatrixFormat

the real vector format specific to the given locale.

getPrefixback to summary
public String getPrefix()

Get the format prefix.

Returns:String

format prefix.

getRowPrefixback to summary
public String getRowPrefix()

Get the format prefix.

Returns:String

format prefix.

getRowSeparatorback to summary
public String getRowSeparator()

Get the format separator between rows of the matrix.

Returns:String

format separator for rows.

getRowSuffixback to summary
public String getRowSuffix()

Get the format suffix.

Returns:String

format suffix.

getSuffixback to summary
public String getSuffix()

Get the format suffix.

Returns:String

format suffix.

parseback to summary
public RealMatrix parse(String source)

Parse a string to produce a RealMatrix object.

Parameters
source:String

String to parse.

Returns:RealMatrix

the parsed RealMatrix object.

Exceptions
MathParseException:
if the beginning of the specified string cannot be parsed.
parseback to summary
public RealMatrix parse(String source, ParsePosition pos)

Parse a string to produce a RealMatrix object.

Parameters
source:String

String to parse.

pos:ParsePosition

input/ouput parsing parameter.

Returns:RealMatrix

the parsed RealMatrix object.