Class LocationFormatter

java.lang.Object
io.jenetics.jpx.format.LocationFormatter

public final class LocationFormatter extends Object
Formatter for printing and parsing geographic location objects.

Patterns for Formatting and Parsing

Patterns are based on a simple sequence of letters and symbols. A pattern is used to create a Formatter using the #ofPattern(String) and #ofPattern(String, Locale) methods. For example, D°MM'SS.SSS"X will format to 60°15'59.613"N. A formatter created from a pattern can be used as many times as necessary, it is immutable and is thread-safe.

Pattern Letters and Symbols
SymbolMeaningExamples
Ldeprecated synonym for 'D'
D Latitude in degrees. Values in -90 <= d <= +90. See examples. 34; 23.2332
M Latitude minutes. Values in 0 <= m < 60. See examples. 45; 45.6
S Latitude seconds. Values in 0 <= s < 60. See examples. 7; 07
X hemisphere (N or S) N; S
ldeprecated synonym for 'd'
d Longitude degrees. Values in -180 <= d <= +180. Similar to Latitude degrees. 34; 23.2332
m Longitude minutes. Similar to latitude minutes. 45; 45.6
s Longitude seconds. Similar to Latitude seconds. 7; 07
x hemisphere (E or W) E; W
E Elevation in meters. See examples. 234; 1023; -12
Hdeprecated synonym for 'E'
' escape for text
'' single quote '
[ optional section start
] optional section end
Examples
Pattern Meaning Examples
+D Latitude sign indicated by prefix +/- +47; -24
D X Latitude sign indicated by X 47 N; 24 S
D.DD Latitude degrees with decimal faction 47.50
D M Latitude in degrees and minutes 47 30
D Latitude degrees in variable width 9; 47
DD Latitude degrees in fixed width 09; 47
D M.MM Latitude minutes with decimal fraction 47 2.25
D M S Latitude minutes and seconds 47 2 15
D M Latitude minutes in variable width 47 2; 46 12
D MM Latitude minutes in fixed width 47 02; 46 12
D M S Latitude seconds in variable width 47 2 3; 46 2 13
D M SS Latitude seconds in fixed width 47 2 03; 46 2 13
D M S.SS Latitude seconds with decimal fraction 46 2 13.54
+d Longitude sign indicated by prefix +/- +147; -124
d x Latitude sign indicated by x 147 E; 124 W
d Longitude degrees in variable width 9; 47; 175
ddd Longitude degrees in fixed width 009; 047; 175
d m.mm Longitude minutes with decimal fraction 47 2.25
d m s Longitude minutes and seconds 47 2 15
d m Longitude minutes in variable width 47 2; 46 12
d mm Longitude minutes in fixed width 47 02; 46 12
d m s Longitude seconds in variable width 47 2 3; 46 2 13
d m ss Longitude seconds in fixed width 47 2 03; 46 2 13
d m s.ss Longitude seconds with decimal fraction 46 2 13.54
E Elevation without positive sign 9; -9
+E Elevation with positive or negative sign +9; -9
E Elevation in variable width 9; 19; 190
EEE Elevation in fixed width 009; 019; 190
E.EEE Elevation with decimal fraction 9.123
Since:
1.4
Version:
2.2
  • Field Details

  • Method Details

    • format

      public String format(Location location)
      Formats the given location using this formatter.
      Parameters:
      location - the location to format
      Returns:
      the format string
      Throws:
      NullPointerException - if the given location is null
      FormatterException - if the formatter tries to format a non-existing, non-optional location fields.
    • toPattern

      public String toPattern()
      Return the pattern string represented by this formatter.
      Returns:
      the pattern string of this formatter
      See Also:
    • format

      public String format(Latitude lat, Longitude lon, Length ele)
      Formats the given location elements using this formatter.
      Parameters:
      lat - the latitude part of the location
      lon - the longitude part of the location
      ele - the elevation part of the location
      Returns:
      the format string
      Throws:
      FormatterException - if the formatter tries to format a non-existing, non-optional location fields.
      See Also:
    • format

      public String format(Latitude lat, Longitude lon)
      Formats the given location elements using this formatter.
      Parameters:
      lat - the latitude part of the location
      lon - the longitude part of the location
      Returns:
      the format string
      Throws:
      FormatterException - if the formatter tries to format a non-existing, non-optional location fields.
      See Also:
    • format

      public String format(Latitude lat)
      Formats the given location elements using this formatter.
      Parameters:
      lat - the latitude part of the location
      Returns:
      the format string
      Throws:
      FormatterException - if the formatter tries to format a non-existing, non-optional location fields.
      See Also:
    • format

      public String format(Longitude lon)
      Formats the given location elements using this formatter.
      Parameters:
      lon - the longitude part of the location
      Returns:
      the format string
      Throws:
      FormatterException - if the formatter tries to format a non-existing, non-optional location fields.
      See Also:
    • format

      public String format(Length ele)
      Formats the given location elements using this formatter.
      Parameters:
      ele - the elevation part of the location
      Returns:
      the format string
      Throws:
      FormatterException - if the formatter tries to format a non-existing, non-optional location field.
      See Also:
    • parse

      Parses the text using this formatter, providing control over the text position. This parses the text without requiring the parse to start from the beginning of the string or finish at the end. The text will be parsed from the specified start ParsePosition. The entire length of the text does not have to be parsed, the ParsePosition will be updated with the index at the end of parsing.
      Parameters:
      text - the text to parse, not null
      pos - the position to parse from, updated with length parsed and the index of any error, not null
      Returns:
      the parsed Location, not null
      Throws:
      ParseException - - if unable to parse the requested result
      IndexOutOfBoundsException - - if the position is invalid
    • parse

      public Location parse(CharSequence text)
      Fully parses the text producing a location. This parses the entire text producing a location. It is typically more useful to use parse(CharSequence, ParsePosition). If the parse completes without reading the entire length of the text, or a problem occurs during parsing or merging, then an exception is thrown.
      Parameters:
      text - the text to parse, not null
      Returns:
      the parsed temporal object, not null
      Throws:
      ParseException - if unable to parse the requested result
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • ofPattern

      public static LocationFormatter ofPattern(String pattern)
      Creates a formatter using the specified pattern.
      Parameters:
      pattern - the formatter pattern
      Returns:
      the location-formatter of the given pattern
      Throws:
      NullPointerException - if the given pattern is null
      IllegalArgumentException - if the given pattern is invalid
      See Also: