public class Formatter extends Object implements Localized
Formatter
instances are created by WKTFormat
and given to the
FormattableObject.formatTo(Formatter)
method of the object to format.
Formatter
provides the following services:
append(…)
methods to be invoked by the formatTo(Formatter)
implementations.Defined in the sis-metadata
module
Constructor and Description |
---|
Formatter()
Creates a new formatter instance with the default configuration.
|
Formatter(Convention convention,
Symbols symbols,
int indentation)
Creates a new formatter instance with the specified convention, symbols and indentation.
|
Modifier and Type | Method and Description |
---|---|
<Q extends Quantity> |
addContextualUnit(Unit<Q> unit)
Adds a unit to use for the next measurements of the quantity
Q . |
void |
append(boolean value)
Appends a boolean value.
|
void |
append(CodeList<?> code)
Appends an enumeration or code list value.
|
void |
append(Date date)
Appends a date.
|
void |
append(double number)
Appends an floating point value.
|
void |
append(FormattableObject object)
Appends the given
FormattableObject . |
void |
append(GeographicBoundingBox bbox,
int fractionDigits)
Appends the given geographic bounding box in a
BBOX[…] element. |
void |
append(long number)
Appends an integer value.
|
void |
append(MathTransform transform)
Appends the given math transform, typically (but not necessarily) in a
PARAM_MT[…] element. |
void |
append(Matrix matrix)
Appends the given matrix as a sequence of
PARAMETER[…] elements. |
void |
append(String text,
ElementKind type)
Appends a character string between quotes.
|
void |
append(Unit<?> unit)
Appends a unit in a
UNIT[…] element or one of the specialized elements. |
void |
appendAny(Object value)
Appends an object or an array of objects.
|
String |
delegateTo(Object other)
Delegates the formatting to another
FormattableObject implementation. |
Convention |
getConvention()
Returns the convention to use for formatting the WKT.
|
FormattableObject |
getEnclosingElement(int depth)
Returns the enclosing WKT element, or
null if element being formatted is the root. |
Locale |
getLocale()
Returns the locale to use for localizing
InternationalString instances. |
Citation |
getNameAuthority()
Returns the preferred authority for choosing the projection and parameter names.
|
boolean |
hasContextualUnit(int depth)
Returns
true if the element at the given depth specified a contextual unit. |
void |
indent(int amount)
Increases or decreases the indentation.
|
boolean |
isInvalidWKT()
Returns
true if the WKT written by this formatter is not strictly compliant to the WKT specification. |
void |
newLine()
Request a line separator before the next element to format.
|
void |
removeContextualUnit(Unit<?> unit)
Removes the unit previously added by a call to
addContextualUnit(unit) . |
void |
setInvalidWKT(Class<?> unformattable,
Exception cause)
Marks the current WKT representation of the given class as not strictly compliant to the WKT specification.
|
void |
setInvalidWKT(IdentifiedObject unformattable,
Exception cause)
Marks the current WKT representation of the given object as not strictly compliant to the WKT specification.
|
<Q extends Quantity> |
toContextualUnit(Unit<Q> unit)
Returns the unit to use instead than the given one, or
null if there is no replacement
for unit . |
String |
toString()
Returns a string representation of this formatter for debugging purpose.
|
String |
toWKT()
Returns the WKT formatted by this object.
|
public Formatter()
public Formatter(Convention convention, Symbols symbols, int indentation)
convention
- The convention to use.symbols
- The symbols.indentation
- The amount of spaces to use in indentation for WKT formatting,
or WKTFormat.SINGLE_LINE
for formatting the whole WKT on a single line.public final Convention getConvention()
Convention.WKT2
.null
).WKTFormat.setConvention(Convention)
,
FormattableObject.toString(Convention)
public final Citation getNameAuthority()
The preferred authority can be set by the WKTFormat.setNameAuthority(Citation)
method.
This is not necessarily the authority who created the object to format.
EPSG:6326
datum is "World Geodetic System 1984".
However if the preferred authority is OGC, then the formatted datum name will rather look like
"WGS84" (the exact string depends on the object aliases).WKTFormat.getNameAuthority()
,
IdentifiedObjects.getName(IdentifiedObject, Citation)
public final Locale getLocale()
InternationalString
instances.
This is not the locale for formatting dates and numbers.getLocale
in interface Localized
CompoundFormat.getLocale()
public void newLine()
append(…)
method call will cause the next element to appear on the next line.
This method has no effect in any of the following cases:
append(…)
.WKTFormat.SINGLE_LINE
.public void indent(int amount)
+1
increases
the indentation by the amount of spaces specified at construction time,
and a value of -1
reduces it by the same amount.amount
- +1 for increasing the indentation, or -1 for decreasing it, or 0 for no-op.public void append(FormattableObject object)
FormattableObject
.
This method performs the following steps:
object.formatTo(this)
."GEOCS"
).IdentifiedObject
, then append complementary information:
Complementary WKT elements WKT 2 element WKT 1 element For types Anchor[…]
Datum
Scope[…]
ReferenceSystem
,Datum
,CoordinateOperation
Area[…]
ReferenceSystem
,Datum
,CoordinateOperation
BBox[…]
ReferenceSystem
,Datum
,CoordinateOperation
VerticalExtent[…]
ReferenceSystem
,Datum
,CoordinateOperation
TimeExtent[…]
ReferenceSystem
,Datum
,CoordinateOperation
Id[…]
Authority[…]
IdentifiedObject
Remarks[…]
ReferenceSystem
,CoordinateOperation
object
- The formattable object to append to the WKT, or null
if none.public void append(GeographicBoundingBox bbox, int fractionDigits)
BBOX[…]
element.
Longitude and latitude values will be formatted in decimal degrees.
Longitudes are relative to the Greenwich meridian, with values increasing toward East.
Latitudes values are increasing toward North.
GeographicBoundingBox
does not specify the datum, so this box
is an approximative information only.bbox
- The geographic bounding box to append to the WKT, or null
.fractionDigits
- The number of fraction digits to use. The recommended value is 2.public void append(MathTransform transform)
PARAM_MT[…]
element.transform
- The transform object to append to the WKT, or null
if none.public void append(Matrix matrix)
PARAMETER[…]
elements.
Only elements different than the default values are appended.
The default values are 1 on the matrix diagonal and 0 elsewhere.matrix
- The matrix to append to the WKT, or null
if none.public void append(String text, ElementKind type)
text
- The string to format to the WKT, or null
if none.type
- The key of the colors to apply if syntax coloring is enabled.public void append(CodeList<?> code)
code
- The code list to append to the WKT, or null
if none.public void append(Date date)
date
- The date to append to the WKT, or null
if none.public void append(boolean value)
value
- The boolean to append to the WKT.public void append(long number)
number
- The integer to append to the WKT.public void append(double number)
number
- The floating point value to append to the WKT.public void append(Unit<?> unit)
UNIT[…]
element or one of the specialized elements. Specialized elements are
ANGLEUNIT
, LENGTHUNIT
, SCALEUNIT
, PARAMETRICUNIT
and TIMEUNIT
.
Specialization is used in WKT 2 format except the simplified WKT 2 one.
append(SI.KILOMETRE)
will append "LENGTHUNIT["km", 1000]
" to the WKT.unit
- The unit to append to the WKT, or null
if none.public void appendAny(Object value)
null
, then this method appends the "null
" string (without quotes).append(…)
methods
in this class, then the formatting will be delegated to that method.toString()
representation.value
- The value to append to the WKT, or null
.public String delegateTo(Object other) throws UnformattableObjectException
FormattableObject
implementation.
Invoking this method is equivalent to first verifying the other
class,
then delegating as below:
This method is useful forreturn other.formatTo(this);
FormattableObject
which are wrapper around another object.
It allows to delegate the WKT formatting to the wrapped object.other
- The object to format with this formatter.FormattableObject.formatTo(Formatter)
.UnformattableObjectException
public FormattableObject getEnclosingElement(int depth)
null
if element being formatted is the root.
This method can be invoked by child elements having some aspects that depend on the enclosing element.depth
- 1 for the immediate parent, 2 for the parent of the parent, etc.null
.public boolean hasContextualUnit(int depth)
true
if the element at the given depth specified a contextual unit.
This method returns true
if the formattable object given by getEnclosingElement(depth)
has invoked addContextualUnit(Unit)
with a non-null unit at least once.
AXIS[…]
elements to determine if they should
inherit the unit specified by the enclosing CRS, or if they should specify their unit explicitly.depth
- 1 for the immediate parent, 2 for the parent of the parent, etc.addContextualUnit(…)
at least once.public <Q extends Quantity> Unit<Q> addContextualUnit(Unit<Q> unit)
Q
. The given unit will apply to
all WKT elements containing a value of quantity Q
without their own UNIT[…]
element,
until the removeContextualUnit(Unit)
method is invoked with a unit of the same quantity.
If the given unit is null, then this method does nothing and returns null
.
WKT1_COMMON_UNITS
, then this method ignores the given unit
and returns null
. See Convention.WKT1_COMMON_UNITS
javadoc for more information.Q
- The unit quantity.unit
- The contextual unit to add, or null
if none.Q
, or null
if none.public void removeContextualUnit(Unit<?> unit)
addContextualUnit(unit)
.
If the given unit is null, then this method does nothing.unit
- The contextual unit to remove, or null
if none.public <Q extends Quantity> Unit<Q> toContextualUnit(Unit<Q> unit)
null
if there is no replacement
for unit
. This method searches for a unit specified by addContextualUnit(Unit)
which is compatible with the given unit.Q
- The quantity of the unit.unit
- The unit to replace by the contextual unit, or null
.unit
if no contextual unit has been found.public boolean isInvalidWKT()
true
if the WKT written by this formatter is not strictly compliant to the WKT specification.
This method returns true
if setInvalidWKT(IdentifiedObject, Exception)
has been invoked at
least once. The action to take regarding invalid WKT is caller-dependent.
For example FormattableObject.toString()
will accepts loose WKT formatting and ignore
this flag, while FormattableObject.toWKT()
requires strict WKT formatting and will
thrown an exception if this flag is set.true
if the WKT is invalid.public void setInvalidWKT(IdentifiedObject unformattable, Exception cause)
FormattableObject.formatTo(Formatter)
when the object
to format is more complex than what the WKT specification allows.
Applications can test isInvalidWKT()
later for checking WKT validity.
If any setInvalidWKT(…)
method is invoked more than once during formatting,
then only information about the first failure will be retained.
unformattable
- The object that can not be formatted,cause
- The cause for the failure to format, or null
if the cause is not an exception.public void setInvalidWKT(Class<?> unformattable, Exception cause)
setInvalidWKT(IdentifiedObject, Exception)
when the
problematic object is not an instance of IdentifiedObject
.
If any setInvalidWKT(…)
method is invoked more than once during formatting,
then only information about the first failure will be retained.
unformattable
- The class of the object that can not be formatted,cause
- The cause for the failure to format, or null
if the cause is not an exception.public String toWKT()
Copyright © 2010–2015 The Apache Software Foundation. All rights reserved.