sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1785577 - in /sis/branches/JDK8: application/sis-console/src/main/java/org/apache/sis/console/ core/sis-metadata/src/main/java/org/apache/sis/io/wkt/ core/sis-utility/src/main/java/org/apache/sis/util/resources/
Date Sun, 05 Mar 2017 23:24:07 GMT
Author: desruisseaux
Date: Sun Mar  5 23:24:06 2017
New Revision: 1785577

URL: http://svn.apache.org/viewvc?rev=1785577&view=rev
Log:
Replace IndexResourceBundle.getLabel(short) by appendLabel(short, Appendable) for avoiding
String concatenations. Instead, we write directly in the Appendable.

Modified:
    sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/AboutCommand.java
    sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/IdentifierCommand.java
    sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/TransformCommand.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java

Modified: sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/AboutCommand.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/AboutCommand.java?rev=1785577&r1=1785576&r2=1785577&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/AboutCommand.java
[UTF-8] (original)
+++ sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/AboutCommand.java
[UTF-8] Sun Mar  5 23:24:06 2017
@@ -161,7 +161,7 @@ final class AboutCommand extends Command
                 out.print(X364.BOLD.sequence());
                 out.print(' ');
             }
-            out.print(Vocabulary.getResources(locale).getLabel(Vocabulary.Keys.Warnings));
+            Vocabulary.getResources(locale).appendLabel(Vocabulary.Keys.Warnings, out);
             if (colors) {
                 out.print(' ');
                 out.println(X364.RESET.sequence());

Modified: sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/IdentifierCommand.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/IdentifierCommand.java?rev=1785577&r1=1785576&r2=1785577&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/IdentifierCommand.java
[UTF-8] (original)
+++ sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/IdentifierCommand.java
[UTF-8] Sun Mar  5 23:24:06 2017
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.console;
 
+import java.io.IOException;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Set;
@@ -204,7 +205,7 @@ final class IdentifierCommand extends Fo
     /**
      * Prints all non-null rows.
      */
-    private void print(final Iterable<Row> rows) {
+    private void print(final Iterable<Row> rows) throws IOException {
         int width = 0;
         for (final Row row : rows) {
             if (row != null) {
@@ -232,7 +233,8 @@ final class IdentifierCommand extends Fo
         states.remove(State.VALID);
         if (!states.isEmpty()) {
             out.println();
-            out.println(Vocabulary.getResources(locale).getLabel(Vocabulary.Keys.Legend));
+            Vocabulary.getResources(locale).appendLabel(Vocabulary.Keys.Legend, out);
+            out.println();
             final ResourceBundle resources = ResourceBundle.getBundle("org.apache.sis.console.IdentifierState",
locale);
             for (final State state : states) {
                 final boolean warning = colors && state.text.startsWith("!");

Modified: sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/TransformCommand.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/TransformCommand.java?rev=1785577&r1=1785576&r2=1785577&view=diff
==============================================================================
--- sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/TransformCommand.java
[UTF-8] (original)
+++ sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/TransformCommand.java
[UTF-8] Sun Mar  5 23:24:06 2017
@@ -281,9 +281,9 @@ final class TransformCommand extends For
      *
      * @param  key  a {@code Vocabulary.Keys} constant for the header to print.
      */
-    private void printHeader(final short key) {
+    private void printHeader(final short key) throws IOException {
         printCommentLinePrefix();
-        outHeader.append(resources.getLabel(key));
+        resources.appendLabel(key, outHeader);
         outHeader.nextColumn();
     }
 
@@ -354,7 +354,7 @@ final class TransformCommand extends For
     /**
      * Prints the accuracy.
      */
-    private void printAccuracy(double accuracy) {
+    private void printAccuracy(double accuracy) throws IOException {
         if (accuracy >= 0) {
             if (accuracy == 0) {
                 accuracy = Formulas.LINEAR_TOLERANCE;
@@ -384,7 +384,7 @@ final class TransformCommand extends For
      *
      * <blockquote>Canada - onshore and offshore</blockquote>
      */
-    private void printDomainOfValidity(final Extent domain) {
+    private void printDomainOfValidity(final Extent domain) throws IOException {
         if (domain != null) {
             final InternationalString description = domain.getDescription();
             if (description != null) {
@@ -410,7 +410,7 @@ final class TransformCommand extends For
      * Prints the coordinate operation or math transform in Well Known Text format.
      * This information is printed only if the {@code --verbose} option was specified.
      */
-    private void printDetails() {
+    private void printDetails() throws IOException {
         final boolean debug = options.containsKey(Option.DEBUG);
         final WKTFormat f = new WKTFormat(locale, timezone);
         if (colors) f.setColors(Colors.DEFAULT);

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java?rev=1785577&r1=1785576&r2=1785577&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
[UTF-8] Sun Mar  5 23:24:06 2017
@@ -17,6 +17,7 @@
 package org.apache.sis.io.wkt;
 
 import java.io.Console;
+import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.concurrent.atomic.AtomicReference;
 import javax.xml.bind.annotation.XmlTransient;
@@ -208,6 +209,8 @@ public abstract class FormattableObject
             }
             formatter.appendWarnings();
             wkt = formatter.toWKT();
+        } catch (IOException e) {
+            throw new UnformattableObjectException(e);      // Should never happen since
we write to a StringBuffer.
         } finally {
             formatter.clear();
         }

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java?rev=1785577&r1=1785576&r2=1785577&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] Sun Mar  5 23:24:06 2017
@@ -29,6 +29,7 @@ import java.util.Date;
 import java.text.DateFormat;
 import java.text.NumberFormat;
 import java.text.FieldPosition;
+import java.io.IOException;
 import java.lang.reflect.Array;
 import java.math.RoundingMode;
 import javax.measure.Unit;
@@ -1618,7 +1619,7 @@ public class Formatter implements Locali
      * Appends the warnings after the WKT string. If there is no warnings, then this method
does nothing.
      * If this method is invoked, then it shall be the last method before {@link #toWKT()}.
      */
-    final void appendWarnings() {
+    final void appendWarnings() throws IOException {
         final Warnings warnings = this.warnings;                    // Protect against accidental
changes.
         if (warnings != null) {
             final StringBuffer buffer = this.buffer;
@@ -1627,7 +1628,7 @@ public class Formatter implements Locali
             if (colors != null) {
                 buffer.append(X364.BACKGROUND_RED.sequence()).append(X364.BOLD.sequence()).append('
');
             }
-            buffer.append(Vocabulary.getResources(locale).getLabel(Vocabulary.Keys.Warnings));
+            Vocabulary.getResources(locale).appendLabel(Vocabulary.Keys.Warnings, buffer);
             if (colors != null) {
                 buffer.append(' ').append(X364.RESET.sequence()).append(X364.FOREGROUND_RED.sequence());
             }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java?rev=1785577&r1=1785576&r2=1785577&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
[UTF-8] Sun Mar  5 23:24:06 2017
@@ -452,6 +452,25 @@ public class IndexedResourceBundle exten
     }
 
     /**
+     * Writes the localized string identified by the given key followed by a colon.
+     * The way to write the colon depends on the language.
+     *
+     * @param  key         the key for the desired string.
+     * @param  toAppendTo  where to write the localized string followed by a colon.
+     * @throws IOException if an error occurred while writing to the given destination.
+     *
+     * @since 0.8
+     */
+    public final void appendLabel(final short key, final Appendable toAppendTo) throws IOException
{
+        toAppendTo.append(getString(key));
+        if (Locale.FRENCH.getLanguage().equals(getLocale().getLanguage())) {
+            toAppendTo.append("\u00A0:");
+        } else {
+            toAppendTo.append(':');
+        }
+    }
+
+    /**
      * Gets a string for the given key and appends "…" to it.
      * This method is typically used for creating menu items.
      *
@@ -471,7 +490,10 @@ public class IndexedResourceBundle exten
      * @param  key  the key for the desired string.
      * @return the string for the given key.
      * @throws MissingResourceException if no object for the given key can be found.
+     *
+     * @deprecated Replaced by {@link #appendLabel(short, Appendable)}.
      */
+    @Deprecated
     public final String getLabel(final short key) throws MissingResourceException {
         String label = getString(key);
         if (Locale.FRENCH.getLanguage().equals(getLocale().getLanguage())) {



Mime
View raw message