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

public abstract Class VectorFormat<S extends Space>

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.commons.math3.geometry.euclidean.oned.Vector1DFormat, org.apache.commons.math3.geometry.euclidean.threed.Vector3DFormat, org.apache.commons.math3.geometry.euclidean.twod.Vector2DFormat
Type Parameters
<S>
Type of the space.
Imports
java.text.FieldPosition, .NumberFormat, .ParsePosition, java.util.Locale, org.apache.commons.math3.util.CompositeFormat, org.apache.commons.math3.exception.MathParseException

Formats a vector in components list format "{x; y; ...}".

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.

Note

using "," as a separator may interfere with the grouping separator of the default NumberFormat for the current locale. Thus it is advised to use a NumberFormat instance with disabled grouping in such a case.

Since
3.0

Field Summary

Modifier and TypeField and Description
public static final String
DEFAULT_PREFIX

The default prefix: "{".

public static final String
DEFAULT_SEPARATOR

The default separator: ", ".

public 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
protected
VectorFormat()

Create an instance with default settings.

protected
VectorFormat(final NumberFormat
the custom format for components.
format
)

Create an instance with a custom number format for components.

protected
VectorFormat(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.

protected
VectorFormat(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 string.
format
(Vector<S>
the object to format.
vector
)

Formats a Vector object to produce a string.

public abstract StringBuffer

Returns:

the value passed in as toAppendTo.
format
(Vector<S>
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 Vector object to produce a string.

protected StringBuffer

Returns:

the value passed in as toAppendTo.
format
(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
,
double...
coordinates of the object to format.
coordinates
)

Formats the coordinates of a Vector to produce a string.

public static Locale[]

Returns:

available point/vector format locales.
getAvailableLocales
()

Get the set of locales for which point/vector formats are available.

public NumberFormat

Returns:

components format.
getFormat
()

Get the components format.

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 abstract Vector<S>

Returns:

the parsed Vector object.
parse
(String
the string to parse
source
)

Parses a string to produce a Vector object.

public abstract Vector<S>

Returns:

the parsed Vector object.
parse
(String
the string to parse
source
,
ParsePosition
input/output parsing parameter.
pos
)

Parses a string to produce a Vector object.

protected double[]

Returns:

coordinates array.
parseCoordinates
(int
dimension of the space
dimension
,
String
the string to parse
source
,
ParsePosition
input/output parsing parameter.
pos
)

Parses a string to produce an array of coordinates.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_PREFIXback to summary
public static final String DEFAULT_PREFIX

The default prefix: "{".

DEFAULT_SEPARATORback to summary
public static final String DEFAULT_SEPARATOR

The default separator: ", ".

DEFAULT_SUFFIXback to summary
public 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

VectorFormatback to summary
protected VectorFormat()

Create an instance with default settings.

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

VectorFormatback to summary
protected VectorFormat(final NumberFormat format)

Create an instance with a custom number format for components.

Parameters
format:NumberFormat

the custom format for components.

VectorFormatback to summary
protected VectorFormat(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 "; "

VectorFormatback to summary
protected VectorFormat(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(Vector<S> vector)

Formats a Vector object to produce a string.

Parameters
vector:Vector<S>

the object to format.

Returns:String

a formatted string.

formatback to summary
public abstract StringBuffer format(Vector<S> vector, StringBuffer toAppendTo, FieldPosition pos)

Formats a Vector object to produce a string.

Parameters
vector:Vector<S>

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.

formatback to summary
protected StringBuffer format(StringBuffer toAppendTo, FieldPosition pos, double... coordinates)

Formats the coordinates of a Vector to produce a string.

Parameters
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

coordinates:double[]

coordinates of the object to format.

Returns:StringBuffer

the value passed in as toAppendTo.

getAvailableLocalesback to summary
public static Locale[] getAvailableLocales()

Get the set of locales for which point/vector formats are available.

This is the same set as the NumberFormat set.

Returns:Locale[]

available point/vector format locales.

getFormatback to summary
public NumberFormat getFormat()

Get the components format.

Returns:NumberFormat

components format.

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 abstract Vector<S> parse(String source) throws MathParseException

Parses a string to produce a Vector object.

Parameters
source:String

the string to parse

Returns:Vector<S>

the parsed Vector object.

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

Parses a string to produce a Vector object.

Parameters
source:String

the string to parse

pos:ParsePosition

input/output parsing parameter.

Returns:Vector<S>

the parsed Vector object.

parseCoordinatesback to summary
protected double[] parseCoordinates(int dimension, String source, ParsePosition pos)

Parses a string to produce an array of coordinates.

Parameters
dimension:int

dimension of the space

source:String

the string to parse

pos:ParsePosition

input/output parsing parameter.

Returns:double[]

coordinates array.