Class FormattableObject

Object
FormattableObject
Direct Known Subclasses:
Abstract­Direct­Position, Abstract­Envelope, Abstract­Identified­Object, Abstract­Math­Transform, Bursa­Wolf­Parameters, Default­Formula, Default­Object­Domain, Default­Parameter­Value, Immutable­Identifier

public abstract class FormattableObject extends Object
Base class for objects that can be formatted as Well Known Text (WKT). WKTFormat checks for this class at formatting time for each element to format. When a Formattable­Object element is found, its format­To(Formatter) method is invoked for allowing the element to control its formatting.

This class provides two methods for getting a default Well Known Text representation of this object:

  • to­WKT() tries to return a strictly compliant WKT or throws Unformattable­Object­Exception if this object contains elements not defined by the ISO 19162 standard.
  • to­String() returns a WKT with some redundant information omitted and some constraints relaxed. This method never throw Unformattable­Object­Exception; it will rather use non-standard representation if necessary.

Syntax coloring

A convenience print() method is provided, which is roughly equivalent to System​.out​.println(this) except that syntax coloring is automatically applied if the terminal seems to support the ANSI escape codes.

Non-standard WKT

If this object cannot be formatted without violating some WKT constraints, then the behavior depends on the method invoked:
Since:
0.4
See Also:
  • Constructor Details

    • FormattableObject

      protected FormattableObject()
      Default constructor.
  • Method Details

    • toWKT

      public String toWKT() throws UnformattableObjectException
      Returns a strictly compliant Well Known Text (WKT) using the default convention, symbols and indentation. If this object cannot be represented in a standard way, then this method throws an Unformattable­Object­Exception.

      By default this method formats this object according the Convention​.WKT2 rules.

      Returns:
      the default Well Know Text representation of this object.
      Throws:
      Unformattable­Object­Exception - if this object cannot be formatted as a standard WKT.
      See Also:
    • toString

      public String toString()
      Returns a Well Known Text (WKT) or an alternative text representation for this object. If this object cannot be represented in a standard way, then this method may fallback on non-standard representation, or leave unformattable elements empty and append warnings after the WKT.

      By default this method formats this object according the Convention​.WKT2_SIMPLIFIED rules, except that Unicode characters are kept as-is (they are not converted to ASCII). Consequently, the WKT is not guaranteed to be ISO 19162 compliant. For stricter conformance, use to­WKT() instead.

      Overrides:
      to­String in class Object
      Returns:
      the Well Known Text (WKT) or an alternative representation of this object.
    • toString

      public String toString(Convention convention)
      Returns a Well Known Text (WKT) for this object using the specified convention. Unicode characters are kept as-is (they are not converted to ASCII). The returned string may contain non-standard elements or warnings if this object cannot be formatted according the given convention.

      For stricter conformance to ISO 19162 standard, use to­WKT() or WKTFormat instead.

      Parameters:
      convention - the WKT convention to use.
      Returns:
      the Well Known Text (WKT) or a pseudo-WKT representation of this object.
    • print

      @Debug public void print()
      Prints a string representation of this object to the standard output stream. If a console is attached to the running JVM (i.e. if the application is run from the command-line and the output is not redirected to a file) and if Apache SIS thinks that the console supports the ANSI escape codes (a.k.a. X3.64), then a syntax coloring will be applied.

      This is a convenience method for debugging purpose and for console applications.

    • formatTo

      protected abstract String formatTo(Formatter formatter)
      Formats the inner part of this Well Known Text (WKT) element into the given formatter. This method is automatically invoked by WKTFormat when a formattable element is found.

      Keywords, opening and closing brackets shall not be formatted here. For example if this formattable element is for a Geodetic­CRS[…] element, then this method shall write the content starting at the insertion point shown below:

         GeodeticCRS[ ]
                     ↑
             (insertion point)

      Formatting non-standard WKT

      If the implementation cannot represent this object without violating some WKT constraints, it can uses its own (non-standard) keywords but shall declare that it did so by invoking one of the Formatter​.set­Invalid­WKT(…) methods.

      Alternatively, the implementation may also have no WKT keyword for this object. This happen frequently when an abstract class defines a base implementation, while the keyword needs to be defined by the concrete subclasses. In such case, the method in the abstract class shall return null.

      Parameters:
      formatter - the formatter where to format the inner content of this WKT element.
      Returns:
      the CamelCase keyword for the WKT element, or null if unknown.
      See Also: