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

public Class RealVectorFormat

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 vector in components list format "{v0; v1; ...; vk-1}".

The prefix and suffix "{" and "}" and the 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 vector 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.

Since
2.0

Field Summary

Modifier and TypeField and Description
private static final String
DEFAULT_PREFIX

The default prefix: "{".

private static final String
DEFAULT_SEPARATOR

The default separator: ", ".

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
separator

Separator.

private final String
suffix

Suffix.

private final String
trimmedPrefix

Trimmed prefix.

private final String
trimmedSeparator

Trimmed separator.

private final String
trimmedSuffix

Trimmed suffix.

Constructor Summary

AccessConstructor and Description
public
RealVectorFormat()

Create an instance with default settings.

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

Create an instance with a custom number format for components.

public
RealVectorFormat(final String
prefix to use instead of the default "{"
prefix
,
final String
suffix to use instead of the default "}"
suffix
,
final String
separator to use instead of the default "; "
separator
)

Create an instance with custom prefix, suffix and separator.

public
RealVectorFormat(final String
prefix to use instead of the default "{"
prefix
,
final String
suffix to use instead of the default "}"
suffix
,
final String
separator to use instead of the default "; "
separator
,
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 vector.
format
(RealVector
RealVector object to format.
v
)

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

public StringBuffer

Returns:

the value passed in as toAppendTo.
format
(RealVector
the object to format.
vector
,
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 RealVector 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 NumberFormat

Returns:

components format.
getFormat
()

Get the components format.

public static RealVectorFormat

Returns:

the default real vector format.
getInstance
()

Returns the default real vector format for the current locale.

public static RealVectorFormat

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 separator.
getSeparator
()

Get the format separator between components.

public String

Returns:

format suffix.
getSuffix
()

Get the format suffix.

public ArrayRealVector

Returns:

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

Parse a string to produce a RealVector object.

public ArrayRealVector

Returns:

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

Parse a string to produce a RealVector object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_PREFIXback to summary
private static final String DEFAULT_PREFIX

The default prefix: "{".

DEFAULT_SEPARATORback to summary
private static final String DEFAULT_SEPARATOR

The default separator: ", ".

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.

separatorback to summary
private final String separator

Separator.

suffixback to summary
private final String suffix

Suffix.

trimmedPrefixback to summary
private final String trimmedPrefix

Trimmed prefix.

trimmedSeparatorback to summary
private final String trimmedSeparator

Trimmed separator.

trimmedSuffixback to summary
private final String trimmedSuffix

Trimmed suffix.

Constructor Detail

RealVectorFormatback to summary
public RealVectorFormat()

Create an instance with default settings.

The instance uses the default prefix, suffix and separator: "{", "}", and "; " and the default number format for components.

RealVectorFormatback to summary
public RealVectorFormat(final NumberFormat format)

Create an instance with a custom number format for components.

Parameters
format:NumberFormat

the custom format for components.

RealVectorFormatback to summary
public RealVectorFormat(final String prefix, final String suffix, final String separator)

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 "}"

separator:String

separator to use instead of the default "; "

RealVectorFormatback to summary
public RealVectorFormat(final String prefix, final String suffix, final String separator, 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 "}"

separator:String

separator to use instead of the default "; "

format:NumberFormat

the custom format for components.

Method Detail

formatback to summary
public String format(RealVector v)

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

Parameters
v:RealVector

RealVector object to format.

Returns:String

a formatted vector.

formatback to summary
public StringBuffer format(RealVector vector, StringBuffer toAppendTo, FieldPosition pos)

Formats a RealVector object to produce a string.

Parameters
vector:RealVector

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.

getFormatback to summary
public NumberFormat getFormat()

Get the components format.

Returns:NumberFormat

components format.

getInstanceback to summary
public static RealVectorFormat getInstance()

Returns the default real vector format for the current locale.

Returns:RealVectorFormat

the default real vector format.

getInstanceback to summary
public static RealVectorFormat 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:RealVectorFormat

the real vector format specific to the given locale.

getPrefixback to summary
public String getPrefix()

Get the format prefix.

Returns:String

format prefix.

getSeparatorback to summary
public String getSeparator()

Get the format separator between components.

Returns:String

format separator.

getSuffixback to summary
public String getSuffix()

Get the format suffix.

Returns:String

format suffix.

parseback to summary
public ArrayRealVector parse(String source)

Parse a string to produce a RealVector object.

Parameters
source:String

String to parse.

Returns:ArrayRealVector

the parsed RealVector object.

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

Parse a string to produce a RealVector object.

Parameters
source:String

String to parse.

pos:ParsePosition

input/ouput parsing parameter.

Returns:ArrayRealVector

the parsed RealVector object.