/** * Appends a date. * The {@linkplain Symbols#getSeparator() element separator} will be written before the date if needed. * * @param date the date to append to the WKT, or {@code null} if none. */ public void append(final Date date) { if (date != null) { appendSeparator(); dateFormat.format(date, buffer, dummy); } }
/** * Appends a date. * The {@linkplain Symbols#getSeparator() element separator} will be written before the date if needed. * * @param date the date to append to the WKT, or {@code null} if none. */ public void append(final Date date) { if (date != null) { appendSeparator(); dateFormat.format(date, buffer, dummy); } }
/** * Appends a boolean value. * The {@linkplain Symbols#getSeparator() element separator} will be written before the boolean if needed. * * @param value the boolean to append to the WKT. */ public void append(final boolean value) { appendSeparator(); buffer.append(value ? "TRUE" : "FALSE"); }
/** * Appends a boolean value. * The {@linkplain Symbols#getSeparator() element separator} will be written before the boolean if needed. * * @param value the boolean to append to the WKT. */ public void append(final boolean value) { appendSeparator(); buffer.append(value ? "TRUE" : "FALSE"); }
/** * Appends an integer value. * The {@linkplain Symbols#getSeparator() element separator} will be written before the number if needed. * * @param number the integer to append to the WKT. */ public void append(final long number) { appendSeparator(); /* * The check for 'isComplement' is a hack for ImmutableIdentifier.formatTo(Formatter). * We do not have a public API for controlling the integer colors (it may not be desirable). */ setColor(isComplement ? ElementKind.IDENTIFIER : ElementKind.INTEGER); numberFormat.setMaximumFractionDigits(0); numberFormat.format(number, buffer, dummy); resetColor(); }
/** * Appends the given number without any change to the {@link NumberFormat} setting. * Caller shall ensure that the following method has been invoked prior this method call: * * <ul> * <li>{@link NumberFormat#setMinimumFractionDigits(int)}</li> * <li>{@link NumberFormat#setMaximumFractionDigits(int)}</li> * <li>{@link NumberFormat#setRoundingMode(RoundingMode)}</li> * </ul> */ private void appendPreset(final double number) { appendSeparator(); setColor(ElementKind.NUMBER); numberFormat.format(number, buffer, dummy); resetColor(); }
/** * Appends an integer value. * The {@linkplain Symbols#getSeparator() element separator} will be written before the number if needed. * * @param number the integer to append to the WKT. */ public void append(final long number) { appendSeparator(); /* * The check for 'isComplement' is a hack for ImmutableIdentifier.formatTo(Formatter). * We do not have a public API for controlling the integer colors (it may not be desirable). */ setColor(isComplement ? ElementKind.IDENTIFIER : ElementKind.INTEGER); numberFormat.setMaximumFractionDigits(0); numberFormat.format(number, buffer, dummy); resetColor(); }
/** * Appends the given number without any change to the {@link NumberFormat} setting. * Caller shall ensure that the following method has been invoked prior this method call: * * <ul> * <li>{@link NumberFormat#setMinimumFractionDigits(int)}</li> * <li>{@link NumberFormat#setMaximumFractionDigits(int)}</li> * <li>{@link NumberFormat#setRoundingMode(RoundingMode)}</li> * </ul> */ private void appendPreset(final double number) { appendSeparator(); setColor(ElementKind.NUMBER); numberFormat.format(number, buffer, dummy); resetColor(); }
/** * Appends a separator if needed, then opens a new element. * * @param newLine {@code true} for invoking {@link #newLine()} first. * @param keyword the element keyword (e.g. {@code "DATUM"}, {@code "AXIS"}, <i>etc</i>). */ private void openElement(final boolean newLine, String keyword) { if (newLine && buffer.length() != elementStart) { newLine(); } appendSeparator(); if (toUpperCase != 0) { final Locale locale = symbols.getLocale(); keyword = (toUpperCase >= 0) ? keyword.toUpperCase(locale) : keyword.toLowerCase(locale); } elementStart = buffer.append(keyword).appendCodePoint(symbols.getOpeningBracket(0)).length(); }
/** * Appends a separator if needed, then opens a new element. * * @param newLine {@code true} for invoking {@link #newLine()} first. * @param keyword the element keyword (e.g. {@code "DATUM"}, {@code "AXIS"}, <i>etc</i>). */ private void openElement(final boolean newLine, String keyword) { if (newLine && buffer.length() != elementStart) { newLine(); } appendSeparator(); if (toUpperCase != 0) { final Locale locale = symbols.getLocale(); keyword = (toUpperCase >= 0) ? keyword.toUpperCase(locale) : keyword.toLowerCase(locale); } elementStart = buffer.append(keyword).appendCodePoint(symbols.getOpeningBracket(0)).length(); }
/** * Appends an object or an array of objects. * This method performs the following choices: * * <ul> * <li>If the given value is {@code null}, then this method appends the "{@code null}" string (without quotes).</li> * <li>Otherwise if the given value is an array, then this method appends the opening sequence symbol, formats all * elements by invoking this method recursively, then appends the closing sequence symbol.</li> * <li>Otherwise if the value type is assignable to the argument type of one of the {@code append(…)} methods * in this class, then the formatting will be delegated to that method.</li> * <li>Otherwise the given value is appended as a quoted text with its {@code toString()} representation.</li> * </ul> * * @param value the value to append to the WKT, or {@code null}. */ public void appendAny(final Object value) { if (value == null) { appendSeparator(); buffer.append("null"); } else if (!appendValue(value) && !appendElement(value)) { append(value.toString(), null); } }
/** * Appends an object or an array of objects. * This method performs the following choices: * * <ul> * <li>If the given value is {@code null}, then this method appends the "{@code null}" string (without quotes).</li> * <li>Otherwise if the given value is an array, then this method appends the opening sequence symbol, formats all * elements by invoking this method recursively, then appends the closing sequence symbol.</li> * <li>Otherwise if the value type is assignable to the argument type of one of the {@code append(…)} methods * in this class, then the formatting will be delegated to that method.</li> * <li>Otherwise the given value is appended as a quoted text with its {@code toString()} representation.</li> * </ul> * * @param value the value to append to the WKT, or {@code null}. */ public void appendAny(final Object value) { if (value == null) { appendSeparator(); buffer.append("null"); } else if (!appendValue(value) && !appendElement(value)) { append(value.toString(), null); } }
/** * Appends a number which is assumed to have no rounding error greater than the limit of IEEE 754 accuracy. * This method is invoked for formatting the unit conversion factors, which are defined by the Unit library * rather than specified by the user. The given number is formatted by {@link Double#toString(double)} both * for accuracy and for automatic usage of scientific notation. If the given number is an integer, then it * formatted without the trailing ".0". */ private void appendExact(final double number) { if (Locale.ROOT.equals(symbols.getLocale())) { appendSeparator(); setColor(highlightError ? ElementKind.ERROR : ElementKind.NUMBER); final int i = (int) number; if (i == number) { buffer.append(i); } else { buffer.append(number); } resetColor(); } else { append(number); } highlightError = false; }
/** * Appends a number which is assumed to have no rounding error greater than the limit of IEEE 754 accuracy. * This method is invoked for formatting the unit conversion factors, which are defined by the Unit library * rather than specified by the user. The given number is formatted by {@link Double#toString(double)} both * for accuracy and for automatic usage of scientific notation. If the given number is an integer, then it * formatted without the trailing ".0". */ private void appendExact(final double number) { if (Locale.ROOT.equals(symbols.getLocale())) { appendSeparator(); setColor(highlightError ? ElementKind.ERROR : ElementKind.NUMBER); final int i = (int) number; if (i == number) { buffer.append(i); } else { buffer.append(number); } resetColor(); } else { append(number); } highlightError = false; }
/** * Appends a character string between quotes. * The {@linkplain Symbols#getSeparator() element separator} will be written before the text if needed. * * @param text the string to format to the WKT, or {@code null} if none. * @param type the key of the colors to apply if syntax coloring is enabled, or {@code null} if none. */ public void append(final String text, final ElementKind type) { if (text != null) { appendSeparator(); if (type != ElementKind.CODE_LIST) { quote(text, type); } else { /* * Code lists have no quotes. They are normally formatted by the append(ControlledVocabulary) method, * but an important exception is the CS[type] element in which the type is defined by the interface * implemented by the CoordinateSystem rather than a CodeList instance. */ setColor(type); buffer.append(text); resetColor(); } } }
/** * Appends a character string between quotes. * The {@linkplain Symbols#getSeparator() element separator} will be written before the text if needed. * * @param text the string to format to the WKT, or {@code null} if none. * @param type the key of the colors to apply if syntax coloring is enabled, or {@code null} if none. */ public void append(final String text, final ElementKind type) { if (text != null) { appendSeparator(); if (type != ElementKind.CODE_LIST) { quote(text, type); } else { /* * Code lists have no quotes. They are normally formatted by the append(ControlledVocabulary) method, * but an important exception is the CS[type] element in which the type is defined by the interface * implemented by the CoordinateSystem rather than a CodeList instance. */ setColor(type); buffer.append(text); resetColor(); } } }
appendSeparator(); setColor(ElementKind.NUMBER); final double abs = Math.abs(number);
appendSeparator(); setColor(ElementKind.NUMBER); final double abs = Math.abs(number);
/** * Appends an enumeration or code list value. * The {@linkplain Symbols#getSeparator() element separator} will be written before the code list if needed. * * <p>For the WKT 2 format, this method uses the {@linkplain Types#getCodeName ISO name if available} * (for example {@code "northEast"}). * For the WKT 1 format, this method uses the programmatic name instead (for example {@code "NORTH_EAST"}).</p> * * @param code the code list to append to the WKT, or {@code null} if none. */ public void append(final CodeList<?> code) { if (code != null) { appendSeparator(); final String name = convention.majorVersion() == 1 ? code.name() : Types.getCodeName(code); if (CharSequences.isUnicodeIdentifier(name)) { setColor(ElementKind.CODE_LIST); buffer.append(name); resetColor(); } else { quote(name, ElementKind.CODE_LIST); setInvalidWKT(code.getClass(), null); } } }
/** * Appends an enumeration or code list value. * The {@linkplain Symbols#getSeparator() element separator} will be written before the code list if needed. * * <p>For the WKT 2 format, this method uses the {@linkplain Types#getCodeName ISO name if available} * (for example {@code "northEast"}). * For the WKT 1 format, this method uses the programmatic name instead (for example {@code "NORTH_EAST"}).</p> * * @param code the code list to append to the WKT, or {@code null} if none. */ public void append(final CodeList<?> code) { if (code != null) { appendSeparator(); final String name = convention.majorVersion() == 1 ? code.name() : Types.getCodeName(code); if (CharSequences.isUnicodeIdentifier(name)) { setColor(ElementKind.CODE_LIST); buffer.append(name); resetColor(); } else { quote(name, ElementKind.CODE_LIST); setInvalidWKT(code.getClass(), null); } } }