org.apache.commons.math3.linear

## Class RealMatrixFormat

- java.lang.Object
- - org.apache.commons.math3.linear.RealMatrixFormat

-     public class RealMatrixFormat
      extends java.lang.Object

  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
  Version:
    $Id: RealMatrixFormat.java 1364793 2012-07-23 20:46:28Z tn $

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private java.lang.String` | `columnSeparator` Column separator.
    `private static java.lang.String` | `DEFAULT_COLUMN_SEPARATOR` The default column separator: ",".
    `private static java.lang.String` | `DEFAULT_PREFIX` The default prefix: "{".
    `private static java.lang.String` | `DEFAULT_ROW_PREFIX` The default row prefix: "{".
    `private static java.lang.String` | `DEFAULT_ROW_SEPARATOR` The default row separator: ",".
    `private static java.lang.String` | `DEFAULT_ROW_SUFFIX` The default row suffix: "}".
    `private static java.lang.String` | `DEFAULT_SUFFIX` The default suffix: "}".
    `private java.text.NumberFormat` | `format` The format used for components.
    `private java.lang.String` | `prefix` Prefix.
    `private java.lang.String` | `rowPrefix` Row prefix.
    `private java.lang.String` | `rowSeparator` Row separator.
    `private java.lang.String` | `rowSuffix` Row suffix.
    `private java.lang.String` | `suffix` Suffix.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RealMatrixFormat()` Create an instance with default settings.
    `RealMatrixFormat(java.text.NumberFormat format)` Create an instance with a custom number format for components.
    `RealMatrixFormat(java.lang.String prefix, java.lang.String suffix, java.lang.String rowPrefix, java.lang.String rowSuffix, java.lang.String rowSeparator, java.lang.String columnSeparator)` Create an instance with custom prefix, suffix and separator.
    `RealMatrixFormat(java.lang.String prefix, java.lang.String suffix, java.lang.String rowPrefix, java.lang.String rowSuffix, java.lang.String rowSeparator, java.lang.String columnSeparator, java.text.NumberFormat format)` Create an instance with custom prefix, suffix, separator and format for components.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.String` | `format(RealMatrix m)` This method calls `format(RealMatrix,StringBuffer,FieldPosition)`.
    `java.lang.StringBuffer` | `format(RealMatrix matrix, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)` Formats a `RealMatrix` object to produce a string.
    `static java.util.Locale[]` | `getAvailableLocales()` Get the set of locales for which real vectors formats are available.
    `java.lang.String` | `getColumnSeparator()` Get the format separator between components.
    `java.text.NumberFormat` | `getFormat()` Get the components format.
    `static RealMatrixFormat` | `getInstance()` Returns the default real vector format for the current locale.
    `static RealMatrixFormat` | `getInstance(java.util.Locale locale)` Returns the default real vector format for the given locale.
    `java.lang.String` | `getPrefix()` Get the format prefix.
    `java.lang.String` | `getRowPrefix()` Get the format prefix.
    `java.lang.String` | `getRowSeparator()` Get the format separator between rows of the matrix.
    `java.lang.String` | `getRowSuffix()` Get the format suffix.
    `java.lang.String` | `getSuffix()` Get the format suffix.
    `RealMatrix` | `parse(java.lang.String source)` Parse a string to produce a `RealMatrix` object.
    `RealMatrix` | `parse(java.lang.String source, java.text.ParsePosition pos)` Parse a string to produce a `RealMatrix` object.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_PREFIX

          private static final java.lang.String DEFAULT_PREFIX

      The default prefix: "{".
      See Also:
        Constant Field Values

    - #### DEFAULT_SUFFIX

          private static final java.lang.String DEFAULT_SUFFIX

      The default suffix: "}".
      See Also:
        Constant Field Values

    - #### DEFAULT_ROW_PREFIX

          private static final java.lang.String DEFAULT_ROW_PREFIX

      The default row prefix: "{".
      See Also:
        Constant Field Values

    - #### DEFAULT_ROW_SUFFIX

          private static final java.lang.String DEFAULT_ROW_SUFFIX

      The default row suffix: "}".
      See Also:
        Constant Field Values

    - #### DEFAULT_ROW_SEPARATOR

          private static final java.lang.String DEFAULT_ROW_SEPARATOR

      The default row separator: ",".
      See Also:
        Constant Field Values

    - #### DEFAULT_COLUMN_SEPARATOR

          private static final java.lang.String DEFAULT_COLUMN_SEPARATOR

      The default column separator: ",".
      See Also:
        Constant Field Values

    - #### prefix

          private final java.lang.String prefix

      Prefix.

    - #### suffix

          private final java.lang.String suffix

      Suffix.

    - #### rowPrefix

          private final java.lang.String rowPrefix

      Row prefix.

    - #### rowSuffix

          private final java.lang.String rowSuffix

      Row suffix.

    - #### rowSeparator

          private final java.lang.String rowSeparator

      Row separator.

    - #### columnSeparator

          private final java.lang.String columnSeparator

      Column separator.

    - #### format

          private final java.text.NumberFormat format

      The format used for components.

  - ### Constructor Detail

    - #### RealMatrixFormat

          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.

    - #### RealMatrixFormat

          public RealMatrixFormat(java.text.NumberFormat format)

      Create an instance with a custom number format for components.
      Parameters:
        `format` - the custom format for components.

    - #### RealMatrixFormat

          public RealMatrixFormat(java.lang.String prefix,
                          java.lang.String suffix,
                          java.lang.String rowPrefix,
                          java.lang.String rowSuffix,
                          java.lang.String rowSeparator,
                          java.lang.String columnSeparator)

      Create an instance with custom prefix, suffix and separator.
      Parameters:
        `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 ", "

    - #### RealMatrixFormat

          public RealMatrixFormat(java.lang.String prefix,
                          java.lang.String suffix,
                          java.lang.String rowPrefix,
                          java.lang.String rowSuffix,
                          java.lang.String rowSeparator,
                          java.lang.String columnSeparator,
                          java.text.NumberFormat format)

      Create an instance with custom prefix, suffix, separator and format for components.
      Parameters:
        `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.

  - ### Method Detail

    - #### getAvailableLocales

          public static java.util.Locale[] getAvailableLocales()

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

      This is the same set as the `NumberFormat` set.

      Returns:
        available real vector format locales.

    - #### getPrefix

          public java.lang.String getPrefix()

      Get the format prefix.
      Returns:
        format prefix.

    - #### getSuffix

          public java.lang.String getSuffix()

      Get the format suffix.
      Returns:
        format suffix.

    - #### getRowPrefix

          public java.lang.String getRowPrefix()

      Get the format prefix.
      Returns:
        format prefix.

    - #### getRowSuffix

          public java.lang.String getRowSuffix()

      Get the format suffix.
      Returns:
        format suffix.

    - #### getRowSeparator

          public java.lang.String getRowSeparator()

      Get the format separator between rows of the matrix.
      Returns:
        format separator for rows.

    - #### getColumnSeparator

          public java.lang.String getColumnSeparator()

      Get the format separator between components.
      Returns:
        format separator between components.

    - #### getFormat

          public java.text.NumberFormat getFormat()

      Get the components format.
      Returns:
        components format.

    - #### getInstance

          public static RealMatrixFormat getInstance()

      Returns the default real vector format for the current locale.
      Returns:
        the default real vector format.

    - #### getInstance

          public static RealMatrixFormat getInstance(java.util.Locale locale)

      Returns the default real vector format for the given locale.
      Parameters:
        `locale` - the specific locale used by the format.
      Returns:
        the real vector format specific to the given locale.

    - #### format

          public java.lang.String format(RealMatrix m)

      This method calls `format(RealMatrix,StringBuffer,FieldPosition)`.
      Parameters:
        `m` - RealMatrix object to format.
      Returns:
        a formatted matrix.

    - #### format

          public java.lang.StringBuffer format(RealMatrix matrix,
                                      java.lang.StringBuffer toAppendTo,
                                      java.text.FieldPosition pos)

      Formats a `RealMatrix` object to produce a string.
      Parameters:
        `matrix` - the object to format.
        `toAppendTo` - where the text is to be appended
        `pos` - On input: an alignment field, if desired. On output: the offsets of the alignment field
      Returns:
        the value passed in as toAppendTo.

    - #### parse

          public RealMatrix parse(java.lang.String source)

      Parse a string to produce a `RealMatrix` object.
      Parameters:
        `source` - String to parse.
      Returns:
        the parsed `RealMatrix` object.
      Throws:
        `MathParseException` - if the beginning of the specified string cannot be parsed.

    - #### parse

          public RealMatrix parse(java.lang.String source,
                         java.text.ParsePosition pos)

      Parse a string to produce a `RealMatrix` object.
      Parameters:
        `source` - String to parse.
        `pos` - input/ouput parsing parameter.
      Returns:
        the parsed `RealMatrix` object.

Copyright (c) 2003-2013 Apache Software Foundation