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

public Class Vector2DFormat

extends VectorFormat<Euclidean2D>
Class Inheritance
Imports
java.text.FieldPosition, .NumberFormat, .ParsePosition, java.util.Locale, org.apache.commons.math3.exception.MathParseException, org.apache.commons.math3.geometry.Vector, .VectorFormat, org.apache.commons.math3.util.CompositeFormat

Formats a 2D 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}" and " { 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

Inherited from org.apache.commons.math3.geometry.VectorFormat:
DEFAULT_PREFIXDEFAULT_SEPARATORDEFAULT_SUFFIX

Constructor Summary

AccessConstructor and Description
public
Vector2DFormat()

Create an instance with default settings.

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

Create an instance with a custom number format for components.

public
Vector2DFormat(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
Vector2DFormat(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 StringBuffer
format(final Vector<Euclidean2D>
the object to format.
vector
,
final StringBuffer
where the text is to be appended
toAppendTo
,
final FieldPosition
On input: an alignment field, if desired. On output: the offsets of the alignment field
pos
)

Implements abstract org.apache.commons.math3.geometry.VectorFormat.format.

Formats a Vector object to produce a string.

public static Vector2DFormat

Returns:

the default 2D vector format.
getInstance
()

Returns the default 2D vector format for the current locale.

public static Vector2DFormat

Returns:

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

Returns the default 2D vector format for the given locale.

public Vector2D
parse(final String
the string to parse
source
)

Implements abstract org.apache.commons.math3.geometry.VectorFormat.parse.

Parses a string to produce a Vector object.

public Vector2D
parse(final String
the string to parse
source
,
final ParsePosition
input/output parsing parameter.
pos
)

Implements abstract org.apache.commons.math3.geometry.VectorFormat.parse.

Parses a string to produce a Vector object.

Inherited from org.apache.commons.math3.geometry.VectorFormat:
formatformatgetAvailableLocalesgetFormatgetPrefixgetSeparatorgetSuffixparseCoordinates

Constructor Detail

Vector2DFormatback to summary
public Vector2DFormat()

Create an instance with default settings.

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

Vector2DFormatback to summary
public Vector2DFormat(final NumberFormat format)

Create an instance with a custom number format for components.

Parameters
format:NumberFormat

the custom format for components.

Vector2DFormatback to summary
public Vector2DFormat(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 "; "

Vector2DFormatback to summary
public Vector2DFormat(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 StringBuffer format(final Vector<Euclidean2D> vector, final StringBuffer toAppendTo, final FieldPosition pos)

Implements abstract org.apache.commons.math3.geometry.VectorFormat.format.

Doc from org.apache.commons.math3.geometry.VectorFormat.format.

Formats a Vector object to produce a string.

Parameters
vector:Vector<Euclidean2D>

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.

Annotations
@Override
getInstanceback to summary
public static Vector2DFormat getInstance()

Returns the default 2D vector format for the current locale.

Returns:Vector2DFormat

the default 2D vector format.

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

Returns the default 2D vector format for the given locale.

Parameters
locale:Locale

the specific locale used by the format.

Returns:Vector2DFormat

the 2D vector format specific to the given locale.

parseback to summary
public Vector2D parse(final String source) throws MathParseException

Implements abstract org.apache.commons.math3.geometry.VectorFormat.parse.

Doc from org.apache.commons.math3.geometry.VectorFormat.parse.

Parses a string to produce a Vector object.

Parameters
source:String

the string to parse

Returns:Vector2D

the parsed Vector object.

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

Implements abstract org.apache.commons.math3.geometry.VectorFormat.parse.

Doc from org.apache.commons.math3.geometry.VectorFormat.parse.

Parses a string to produce a Vector object.

Parameters
source:String

the string to parse

pos:ParsePosition

input/output parsing parameter.

Returns:Vector2D

the parsed Vector object.

Annotations
@Override