public class TLcdCGRSFormat extends Format implements ILcdFormatter, ILcdParser
The formatting and parsing of CGRS coordinate strings can be customized using a CGRS format String.
An example of a CGRS coordinate string is 25AC5NE
. This string consists of
25
: A number identifying the northing component of a 30 minutes square.AC
: Letters identifying the easting component of a 30 minutes square.5
: One cipher identifying a 10 minute square within this 30 minutes square.NE
: Two letters identifying a 5 minute square within this 10 minutes square.Format.Field
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_CGRS_FORMAT_CELL
A default CGRS format which describes a cell
|
static String |
DEFAULT_CGRS_FORMAT_KEYPAD
A default CGRS format which describes a cell and keypad
|
static String |
DEFAULT_CGRS_FORMAT_QUADRANT
A default CGRS format which describes a cell, keypad and quadrant
|
Constructor and Description |
---|
TLcdCGRSFormat(ILcdBounds aGridBounds,
String aCGRSFormat)
Creates a new
TLcdCGRSFormat that uses the given grid bounds for its calculations
and that uses the given CGRS format to format or parse an ILcdPoint . |
Modifier and Type | Method and Description |
---|---|
StringBuffer |
format(Object aObject,
StringBuffer aToAppendTo,
FieldPosition aPosition) |
ILcdPoint |
parse(String aString)
|
Optional<ILcdPoint> |
parseObject(String aString,
ParsePosition aPosition)
Parses text from a CGRS coordinate string to produce an
ILcdPoint with longitude latitude coordinates
in the same geodetic reference as the grid bounds that were used to construct this TLcdCGRSFormat . |
clone, format, formatToCharacterIterator, parseObject
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
format
public static final String DEFAULT_CGRS_FORMAT_CELL
public static final String DEFAULT_CGRS_FORMAT_KEYPAD
public static final String DEFAULT_CGRS_FORMAT_QUADRANT
public TLcdCGRSFormat(ILcdBounds aGridBounds, String aCGRSFormat)
TLcdCGRSFormat
that uses the given grid bounds for its calculations
and that uses the given CGRS format to format or parse an ILcdPoint
.
The format should be expressed in EBNF notation (expressions enclosed in []
brackets are optional,
expressions enclosed in {}
brackets may be omitted or repeated):
<pattern> ::= <cellY> {<separator>} <cellX> [{<separator>} <keypad>] [{<separator>} <quadrant>] <cellY> ::= "Y" | "Y", <cellMinimumCharacterLength> <cellX> ::= "X" | "X", <cellMinimumCharacterLength> <keypad> ::= "K" <quadrant> ::= "Q" <cellMinimumCharacterLength> ::= "1" | "2" | "3" <separator> ::= { ? any character ? }When the minimum character length is higher than the amount of actual characters, it will be padded with default characters. For X it will be padded with " " (space), for Y it will be padded with "0" (zero). When the minimum character length is lower than or equal to the amount of characters, the minimum character length has no effect. For example:
aGridBounds
- given bounds expressed in the WGS84 reference.
The values are rounded to the nearest multiple of 30 minutes.
This parameter should never be null
.aCGRSFormat
- given CGRS format, never null
NullPointerException
- if aGridBounds
or aCGRSFormat
is null.public StringBuffer format(Object aObject, StringBuffer aToAppendTo, FieldPosition aPosition)
public Optional<ILcdPoint> parseObject(String aString, ParsePosition aPosition)
ILcdPoint
with longitude latitude coordinates
in the same geodetic reference as the grid bounds that were used to construct this TLcdCGRSFormat
.
The method attempts to parse a string representing a CGRS coordinate, starting at the index given by
aPosition
.
Parsing does not necessarily use all characters up to the end of the string. If parsing succeeds,
the index of aPosition
is updated to the index after the last character used,
and the parsed object is returned. The updated aPosition
can be used to
indicate the starting point for the next call to this method.
If an error occurs, the index of aPosition
is not
changed. The error index of aPosition
is set to the index of
the character where the error occurred, and Optional.empty()
is returned.
parseObject
in class Format
aString
- A String
representing a CGRS coordinate, part of which should be parsed, never null
.aPosition
- A ParsePosition
object with index and error index information as described above, never null
.Optional
containing an ILcdPoint
parsed from the string.
In case of error, returns Optional.empty()
.NullPointerException
- if aSource
or aPosition
is null.ParsePosition
public ILcdPoint parse(String aString) throws IllegalArgumentException
String
and creates a new ILcdPoint
with longitude latitude coordinates
in the same geodetic reference as the grid bounds that were used to construct this TLcdCGRSFormat
.parse
in interface ILcdParser
aString
- the String
representing a CGRS coordinate to be parsed, never null
.ILcdPoint
NullPointerException
- if aString
is null.IllegalArgumentException
- if the String
can't be parsed.