Class VectorFormat<S extends Space,​V extends Vector<S,​V>>

  • Type Parameters:
    S - Type of the space.
    V - Type of vector implementing Vector interface.
    Direct Known Subclasses:
    Vector1DFormat, Vector2DFormat, Vector3DFormat

    public abstract class VectorFormat<S extends Space,​V extends Vector<S,​V>>
    extends Object
    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.

    • Constructor Detail

      • VectorFormat

        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.

      • VectorFormat

        protected VectorFormat​(NumberFormat format)
        Create an instance with a custom number format for components.
        Parameters:
        format - the custom format for components.
      • VectorFormat

        protected VectorFormat​(String prefix,
                               String suffix,
                               String separator)
        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 "}"
        separator - separator to use instead of the default "; "
      • VectorFormat

        protected VectorFormat​(String prefix,
                               String suffix,
                               String separator,
                               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 "}"
        separator - separator to use instead of the default "; "
        format - the custom format for components.
    • Method Detail

      • getAvailableLocales

        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:
        available point/vector format locales.
      • getPrefix

        public String getPrefix()
        Get the format prefix.
        Returns:
        format prefix.
      • getSuffix

        public String getSuffix()
        Get the format suffix.
        Returns:
        format suffix.
      • getSeparator

        public String getSeparator()
        Get the format separator between components.
        Returns:
        format separator.
      • getFormat

        public NumberFormat getFormat()
        Get the components format.
        Returns:
        components format.
      • format

        public String format​(Vector<S,​V> vector)
        Formats a Vector object to produce a string.
        Parameters:
        vector - the object to format.
        Returns:
        a formatted string.
      • format

        public abstract StringBuffer format​(Vector<S,​V> vector,
                                            StringBuffer toAppendTo,
                                            FieldPosition pos)
        Formats a Vector object to produce a string.
        Parameters:
        vector - 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.
      • format

        protected StringBuffer format​(StringBuffer toAppendTo,
                                      FieldPosition pos,
                                      double... coordinates)
        Formats the coordinates of a Vector to produce a string.
        Parameters:
        toAppendTo - where the text is to be appended
        pos - On input: an alignment field, if desired. On output: the offsets of the alignment field
        coordinates - coordinates of the object to format.
        Returns:
        the value passed in as toAppendTo.
      • parse

        public abstract Vector<S,​V> parse​(String source,
                                                ParsePosition pos)
        Parses a string to produce a Vector object.
        Parameters:
        source - the string to parse
        pos - input/output parsing parameter.
        Returns:
        the parsed Vector object.
      • parseCoordinates

        protected double[] parseCoordinates​(int dimension,
                                            String source,
                                            ParsePosition pos)
        Parses a string to produce an array of coordinates.
        Parameters:
        dimension - dimension of the space
        source - the string to parse
        pos - input/output parsing parameter.
        Returns:
        coordinates array.