sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1403771 [1/3] - in /sis/branches/JDK6: ./ sis-build-helper/src/main/resources/ sis-utility/src/main/java/org/apache/sis/internal/jaxb/ sis-utility/src/main/java/org/apache/sis/internal/simple/ sis-utility/src/main/java/org/apache/sis/inter...
Date Tue, 30 Oct 2012 16:35:10 GMT
Author: desruisseaux
Date: Tue Oct 30 16:35:08 2012
New Revision: 1403771

URL: http://svn.apache.org/viewvc?rev=1403771&view=rev
Log:
Merge from the JDK7 branch.

Added:
    sis/branches/JDK6/sis-build-helper/src/main/resources/
      - copied from r1403767, sis/branches/JDK7/sis-build-helper/src/main/resources/
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleCharacterIterator.java
      - copied unchanged from r1403767, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/simple/SimpleCharacterIterator.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
      - copied unchanged from r1403767, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/Utilities.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/util/X364.java
      - copied unchanged from r1403767, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/internal/util/X364.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java
      - copied, changed from r1403767, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/FormatField.java
      - copied unchanged from r1403767, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/measure/FormatField.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/internal/util/X364Test.java
      - copied unchanged from r1403767, sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/util/X364Test.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java
      - copied, changed from r1403767, sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/io/LineFormatterTest.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/AngleTest.java
      - copied unchanged from r1403767, sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/measure/AngleTest.java
    sis/branches/JDK6/src/main/docbook/fr/utility.xml
      - copied unchanged from r1403767, sis/branches/JDK7/src/main/docbook/fr/utility.xml
Removed:
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/EndOfLineFormatter.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/ExpandedTabFormatter.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/IndentedLineFormatter.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/LineWrapFormatter.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/X364.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/io/EndOfLineFormatterTest.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/io/ExpandedTabFormatterTest.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/io/IndentedLineFormatterTest.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/io/LineWrapFormatterTest.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/io/X364Test.java
Modified:
    sis/branches/JDK6/   (props changed)
    sis/branches/JDK6/pom.xml
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/simple/package-info.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/FilteredAppendable.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/IO.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/TableFormatter.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/package-info.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/math/MathFunctions.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/Angle.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/AngleFormat.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/Latitude.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/Longitude.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/ArgumentChecks.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/Characters.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/Exceptions.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/Localized.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/LocalizedException.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/LocalizedParseException.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/Cache.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedArrayList.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedHashMap.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/CheckedHashSet.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/WeakHashSet.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/collection/WeakValueHashMap.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/resources/Loader.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/type/AbstractInternationalString.java
    sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/util/type/ResourceInternationalString.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/io/FormatterTestCase.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/io/TableFormatterTest.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/math/MathFunctionsTest.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/measure/AngleFormatTest.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/test/Assert.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/util/CharSequencesTest.java
    sis/branches/JDK6/sis-utility/src/test/java/org/apache/sis/xml/XLinkTest.java
    sis/branches/JDK6/src/main/docbook/fr.xml

Propchange: sis/branches/JDK6/
------------------------------------------------------------------------------
  Merged /sis/branches/JDK7:r1401245-1403767

Modified: sis/branches/JDK6/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/pom.xml?rev=1403771&r1=1403770&r2=1403771&view=diff
==============================================================================
--- sis/branches/JDK6/pom.xml (original)
+++ sis/branches/JDK6/pom.xml Tue Oct 30 16:35:08 2012
@@ -479,7 +479,7 @@ Apache SIS is a toolkit for describing l
             </group>
             <group>
               <title>Utilities</title>
-              <packages>org.apache.sis.math*:org.apache.sis.util*:org.apache.sis.io*:org.apache.sis.xml*</packages>
+              <packages>org.apache.sis.math*:org.apache.sis.measure*:org.apache.sis.util*:org.apache.sis.io*:org.apache.sis.xml*</packages>
             </group>
           </groups>
 
@@ -537,27 +537,6 @@ Apache SIS is a toolkit for describing l
           <effort>Default</effort>
        </configuration>
       </plugin>
-
-      <!-- Checkstyle report -->
-      <plugin>
-        <artifactId>maven-checkstyle-plugin</artifactId>
-        <version>2.9.1</version>
-        <configuration>
-          <!--configLocation>checkstyle.xml</configLocation-->
-          <enableRulesSummary>false</enableRulesSummary>
-        </configuration>
-      </plugin>
-
-      <!-- PMD report -->
-      <plugin>
-        <artifactId>maven-pmd-plugin</artifactId>
-        <version>2.7.1</version>
-        <configuration>
-          <linkXref>true</linkXref>
-          <sourceEncoding>${project.build.sourceEncoding}</sourceEncoding>
-          <targetJdk>${maven.compile.target}</targetJdk>
-        </configuration>
-      </plugin>
     </plugins>
   </reporting>
 

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java?rev=1403771&r1=1403770&r2=1403771&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java
(original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/jaxb/IdentifierMapAdapter.java
Tue Oct 30 16:35:08 2012
@@ -452,7 +452,7 @@ public class IdentifierMapAdapter extend
                             this.authority = authority;
                             return;
                         }
-                        if (state == Boolean.TRUE) {
+                        if (state) {
                             // Found a duplicated entry, and user asked for the
                             // removal of that authority.
                             it.remove();

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/simple/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/simple/package-info.java?rev=1403771&r1=1403770&r2=1403771&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/simple/package-info.java
(original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/internal/simple/package-info.java
Tue Oct 30 16:35:08 2012
@@ -16,7 +16,7 @@
  */
 
 /**
- * Simple implementations of some ISO interfaces.
+ * Simple implementations of some ISO or Java interfaces.
  *
  * <STRONG>Do not use!</STRONG>
  *

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/FilteredAppendable.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/FilteredAppendable.java?rev=1403771&r1=1403770&r2=1403771&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/FilteredAppendable.java
(original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/FilteredAppendable.java
Tue Oct 30 16:35:08 2012
@@ -21,8 +21,6 @@ import java.io.CharConversionException;
 import org.apache.sis.util.Decorator;
 import org.apache.sis.util.ArgumentChecks;
 
-import static org.apache.sis.util.Characters.LINE_SEPARATOR;
-import static org.apache.sis.util.Characters.PARAGRAPH_SEPARATOR;
 import static org.apache.sis.util.Characters.isLineOrParagraphSeparator;
 
 // Related to JDK7
@@ -46,7 +44,7 @@ import org.apache.sis.internal.util.JDK7
  * {@section Flushing and closing the stream}
  * Subclasses implement the {@link java.io.Flushable} interface only if they
  * hold data in an internal buffer before to send them to the wrapped {@code Appendable}.
- * This is the case of {@link TableFormatter} and {@link LineWrapFormatter} for instance.
+ * This is the case of {@link TableFormatter} and {@link LineFormatter} for instance.
  * For unconditionally flushing or closing an {@code Appendable} and its underlying stream,
  * see {@link IO#flush(Appendable)} and {@link IO#close(Appendable)}.
  *
@@ -58,7 +56,7 @@ import org.apache.sis.internal.util.JDK7
  * @see java.io.FilterWriter
  */
 @Decorator(Appendable.class)
-public abstract class FilteredAppendable implements Appendable {
+abstract class FilteredAppendable implements Appendable {
     /**
      * The underlying character output stream or buffer.
      */
@@ -81,25 +79,6 @@ public abstract class FilteredAppendable
     }
 
     /**
-     * Returns {@code true} if the given character is a line separator in the sense of
-     * this {@code org.apache.sis.io} package. This method performs the same work than
-     * {@link org.apache.sis.util.Characters#isLineOrParagraphSeparator(int)} without
-     * using the code point API. This allows simpler and faster code in subclasses working
-     * only in the {@linkplain Character#isBmpCodePoint(int) Basic Multilingual Plane (BMP)}.
-     * However this method assumes that all line and paragraph separators are in the BMP.
-     *
-     * <p>This method provides a single item to search if we need to expand our definition
of
-     * line separator in this package. However if such extension is needed, then developers
-     * shall also search for usages of {@code LINE_SEPARATOR} and {@code PARAGRAPH_SEPARATOR}
-     * constants in this package since they are sometime used directly.</p>
-     *
-     * @see org.apache.sis.util.Characters#isLineOrParagraphSeparator(int)
-     */
-    static boolean isLineSeparator(final char c) {
-        return (c == '\n') || (c == '\r') || (c == LINE_SEPARATOR) || (c == PARAGRAPH_SEPARATOR);
-    }
-
-    /**
      * Finds the line separator used in the given character sequence portion, or returns
      * {@code null} if unknown. This method is designed for invocation at the beginning
      * of {@code append(CharSequence, ...), before the characters are effectively read.
@@ -128,15 +107,15 @@ public abstract class FilteredAppendable
      * given to the previous call of this method. This works only if this method is consistently
      * invoked for every characters.
      */
-    final int toCodePoint(final char c) throws IOException {
+    final int toCodePoint(final char c) {
         final char h = highSurrogate;
         if (h != 0) {
             highSurrogate = 0;
             if (Character.isLowSurrogate(c)) {
                 return Character.toCodePoint(h, c);
-            } else {
-                throw new CharConversionException();
             }
+            // Unpaired surrogate.  This is usually an error, but this not the fault of
+            // this class since we are processing data supplied by the user. Be lenient.
         }
         if (Character.isHighSurrogate(c)) {
             highSurrogate = c;
@@ -206,8 +185,7 @@ public abstract class FilteredAppendable
         if (sequence == null) {
             sequence = "null";
         }
-        append(sequence, 0, sequence.length());
-        return this;
+        return append(sequence, 0, sequence.length());
     }
 
     /**

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/IO.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/IO.java?rev=1403771&r1=1403770&r2=1403771&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/IO.java (original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/IO.java Tue Oct 30 16:35:08
2012
@@ -43,10 +43,10 @@ public final class IO extends Static {
 
     /**
      * If the given {@code out} argument implements {@link Flushable}, or is a chain
-     * of {@link FilteredAppendable} wrappers around a flushable object, invokes the
+     * of wrappers defined in this package around a flushable object, invokes the
      * {@link Flushable#flush() flush()} method on that object. Otherwise do nothing.
      *
-     * <p>Chains of {@code FilteredAppendable} instances are followed until a {@code
Flushable}
+     * <p>Chains of wrappers are followed until a {@code Flushable}
      * instance is found, if any. The search stops at the first occurrence found.</p>
      *
      * @param  out The stream or buffer to flush, or {@code null}.
@@ -64,10 +64,10 @@ public final class IO extends Static {
 
     /**
      * If the given {@code out} argument implements {@link Closeable}, or is a chain
-     * of {@link FilteredAppendable} wrappers around a closeable object, invokes the
+     * of wrappers defined in this package around a closeable object, invokes the
      * {@link Closeable#close() close()} method on that object. Otherwise do nothing.
      *
-     * <p>Chains of {@code FilteredAppendable} instances are followed until a {@code
Closeable}
+     * <p>Chains of wrappers are followed until a {@code Closeable}
      * instance is found, if any. The first {@link Flushable} instance found <em>before</em>
the
      * {@code Closeable} one, if any, is {@linkplain Flushable#flush() flushed}. The search
stops
      * at the first {@code Closeable} occurrence found.</p>
@@ -92,7 +92,7 @@ public final class IO extends Static {
 
     /**
      * If the given {@code out} argument implements {@link CharSequence}, or is a
-     * chain of {@link FilteredAppendable} wrappers around a {@code CharSequence},
+     * chain of wrappers defined in this package around a {@code CharSequence},
      * returns that character sequence. Otherwise returns {@code null}.
      *
      * <p>Special cases:</p>
@@ -111,13 +111,12 @@ public final class IO extends Static {
      *
      * <p>It may be necessary to invoke {@link #flush(Appendable)} before this method
in order
      * to get proper content. In particular, this is necessary if the chain of {@code Appendable}s
-     * contains {@link TableFormatter} or {@link LineWrapFormatter} instances.</p>
+     * contains {@link TableFormatter} or {@link LineFormatter} instances.</p>
      *
      * @param  out The stream or buffer from which to get the content, or {@code null}.
      * @return The content of the given stream of buffer, or {@code null} if unavailable.
      *
      * @see #flush(Appendable)
-     * @see FilteredAppendable#toString()
      */
     public static CharSequence content(Appendable out) {
         while (!(out instanceof CharSequence)) {

Copied: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java (from
r1403767, sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java?p2=sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java&p1=sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java&r1=1403767&r2=1403771&rev=1403771&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java (original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/LineFormatter.java Tue Oct
30 16:35:08 2012
@@ -24,6 +24,9 @@ import org.apache.sis.util.CharSequences
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.internal.util.X364;
 
+// Related to JDK7
+import org.apache.sis.internal.util.JDK7;
+
 
 /**
  * An {@link Appendable} which can apply different kinds of reformatting that depend on the
@@ -299,7 +302,7 @@ public class LineFormatter extends Filte
      */
     private void writeLineSeparator() throws IOException {
         if (lineSeparator == null) {
-            lineSeparator = System.lineSeparator();
+            lineSeparator = JDK7.lineSeparator();
         }
         out.append(lineSeparator);
     }

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/TableFormatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/TableFormatter.java?rev=1403771&r1=1403770&r2=1403771&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/TableFormatter.java (original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/TableFormatter.java Tue
Oct 30 16:35:08 2012
@@ -23,9 +23,9 @@ import java.util.StringTokenizer;
 import java.io.Flushable;
 import java.io.IOException;
 import org.apache.sis.util.Decorator;
-import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
+import org.apache.sis.internal.util.X364;
 
 import static org.apache.sis.util.Arrays.EMPTY_INT;
 import static org.apache.sis.util.Characters.isLineOrParagraphSeparator;
@@ -129,7 +129,7 @@ public class TableFormatter extends Filt
     };
 
     /**
-     * Default character for space.
+     * The character for empty spaces to insert between columns.
      */
     private static final char SPACE = ' ';
 
@@ -206,41 +206,62 @@ public class TableFormatter extends Filt
     private boolean skipLF;
 
     /**
-     * Creates a new table formatter with a default column separator. The default is a double
-     * vertical line for the left and right table borders, and a single horizontal line
-     * between the columns.
+     * Sets to {@code true} at construction time if {@link #out} has been created by the
+     * constructor rather than supplied by the user.
+     */
+    private boolean ownOut;
+
+    /**
+     * Creates a new table formatter writing in an internal buffer with a default column
separator.
+     * The default is a vertical double line for the left and right table borders, and a
single
+     * line between the columns.
+     */
+    public TableFormatter() {
+        this(new StringBuilder(256));
+        ownOut = true;
+    }
+
+    /**
+     * Creates a new table formatter writing in an internal buffer with the specified column
separator.
      *
-     * @param out The underlying stream or buffer to write to.
+     * @param separator String to write between columns.
      */
-    public TableFormatter(final Appendable out) {
-        super(out);
-        leftBorder      =  "║ ";
-        rightBorder     = " ║" ;
-        columnSeparator = " │ ";
+    public TableFormatter(final String separator) {
+        this(new StringBuilder(256), separator);
+        ownOut = true;
     }
 
     /**
-     * Creates a new table formatter with the specified amount of spaces as column separator.
+     * Creates a new table formatter writing in the given output with a default column separator.
+     * The default is a vertical double line for the left and right table borders, and a
single
+     * line between the columns.
      *
-     * @param out    The underlying stream or buffer to write to.
-     * @param spaces Amount of white spaces to use as column separator.
+     * @param out The underlying stream or buffer to write to.
      */
-    public TableFormatter(final Appendable out, final int spaces) {
+    public TableFormatter(final Appendable out) {
         super(out);
-        ArgumentChecks.ensurePositive("spaces", spaces);
-        leftBorder      = "";
-        rightBorder     = "";
-        columnSeparator = CharSequences.spaces(spaces);
+        leftBorder      =  "║ ";
+        rightBorder     = " ║" ;
+        columnSeparator = " │ ";
     }
 
     /**
-     * Creates a new table writer with the specified column separator.
+     * Creates a new table formatter writing in the given output with the specified column
separator.
      *
      * @param out The underlying stream or buffer to write to.
      * @param separator String to write between columns.
      */
     public TableFormatter(final Appendable out, final String separator) {
         super(out);
+        /*
+         * Use Character.isSpaceChar(…) instead of Character.isWhitespace(…) because
the former
+         * does not consider control characters (tabulation, group separator, etc.) as spaces.
+         * We presume that if the user wants to put such characters in the border, he has
reasons.
+         *
+         * If this policy is changed, search for other occurrences of 'isSpaceChar' in this
class
+         * for ensuring consistency. Note however that the same policy is not necessarily
applied
+         * everywhere.
+         */
         final int length = separator.length();
         int lower = 0;
         int upper = length;
@@ -294,8 +315,10 @@ public class TableFormatter extends Filt
         }
         assert (verticalBorder >= -1) && (verticalBorder <= +1) : verticalBorder;
         /*
-         * Remplaces spaces by the horizontal lines,
-         * and vertical lines by an intersection.
+         * Remplaces spaces by the horizontal lines, and vertical lines by an intersection.
+         * Use Character.isSpaceChar(…) instead of Character.isWhitespace(…) for
consistency
+         * with the policy used in the constructor, since we work on the same object (namely
+         * the border strings).
          */
         final int index = (horizontalBorder+1) + (verticalBorder+1)*3;
         final int borderLength = border.length();
@@ -437,10 +460,9 @@ public class TableFormatter extends Filt
      * </ul>
      *
      * @param  c Character to write.
-     * @throws IOException If an I/O error occurs.
      */
     @Override
-    public Appendable append(final char c) throws IOException {
+    public TableFormatter append(final char c) {
         final int cp = toCodePoint(c);
         if (!multiLinesCells) {
             if (cp == '\t') {
@@ -467,22 +489,41 @@ public class TableFormatter extends Filt
     }
 
     /**
+     * Appends the specified character sequence.
+     *
+     * @param  sequence The character sequence to append, or {@code null}.
+     * @return A reference to this {@code Appendable}.
+     */
+    @Override
+    public TableFormatter append(CharSequence sequence) {
+        if (sequence == null) {
+            sequence = "null";
+        }
+        return append(sequence, 0, sequence.length());
+    }
+
+    /**
      * Writes a portion of a character sequence. Tabulations and line separators are
-     * interpreted as by {@link #append(c)}.
+     * interpreted as by {@link #append(char)}.
      *
      * @param  sequence The character sequence to be written.
      * @param  start    Index from which to start reading characters.
      * @param  end      Index of the character following the last character to read.
-     * @throws IOException If an I/O error occurs.
      */
     @Override
     @SuppressWarnings("fallthrough")
-    public Appendable append(final CharSequence sequence, int start, int end) throws IOException
{
+    public TableFormatter append(final CharSequence sequence, int start, int end) {
         ArgumentChecks.ensureValidIndexRange(sequence.length(), start, end);
         if (lineSeparator == null) {
             lineSeparator = lineSeparator(sequence, start, end);
         }
-        start = appendSurrogate(sequence, start, end);
+        try {
+            start = appendSurrogate(sequence, start, end);
+        } catch (IOException e) {
+            // Should never happen, because appendSurrogate(…) delegates to append(char)
+            // which is overriden without 'throws IOException' clause in this class.
+            throw new AssertionError(e);
+        }
         if (start != end) {
             if (skipLF && sequence.charAt(start) == '\n') {
                 start++;
@@ -593,7 +634,7 @@ public class TableFormatter extends Filt
             nextColumn(fill);
         }
         assert buffer.length() == 0;
-        cells.add(!Character.isSpaceChar(fill) ? new Cell(null, alignment, fill) : null);
+        cells.add((fill != SPACE) ? new Cell(null, alignment, fill) : null);
         currentColumn = 0;
         currentRow++;
     }
@@ -610,7 +651,9 @@ public class TableFormatter extends Filt
             nextLine();
             assert buffer.length() == 0;
         }
-        writeTable();
+        if (!ownOut) {
+            writeTable();
+        }
         cells.clear();
         currentRow    = 0;
         currentColumn = 0;
@@ -624,6 +667,33 @@ public class TableFormatter extends Filt
     }
 
     /**
+     * Returns the content of this {@code TableFormatter} as a string if possible.
+     *
+     * <ul>
+     *   <li>If this {@code TableFormatter} has been created without explicit {@link
Appendable},
+     *       then this method always returns the current table content formatted as a string.</li>
+     *   <li>Otherwise, if {@link #out} implements {@link CharSequence} or is directly
or
+     *       indirectly a wrapper around a {@code CharSequence}, returns its {@code toString()}
+     *       representation. The string will contain this table content only if {@link #flush()}
+     *       has been invoked prior this {@code toString()} method.</li>
+     *   <li>Otherwise returns the localized "<cite>Unavailable content</cite>"
string.</li>
+     * </ul>
+     */
+    @Override
+    public String toString() {
+        if (ownOut) {
+            ((StringBuilder) out).setLength(0);
+            try {
+                writeTable();
+            } catch (IOException e) {
+                // Should never happen because we are writing in a StringBuilder.
+                throw new AssertionError(e);
+            }
+        }
+        return super.toString();
+    }
+
+    /**
      * Writes the table without clearing the {@code TableFormatter} content.
      * Invoking this method many time would result in the same table being
      * repeated.
@@ -688,8 +758,14 @@ public class TableFormatter extends Filt
                             if (c == '\r' && (next < textLength) && cellText.charAt(next)
== '\n') {
                                 next++;
                             }
-                            // Verify if the remaining contains only whitespaces, but do
not skip
-                            // those whitespaces if there is at least one non-white character.
+                            /*
+                             * Verify if the remaining contains only white spaces. If so,
those spaces
+                             * will be ignored. But if there is at least one non-white character,
then
+                             * we will not skip those spaces. We use Character.isWhitespace(…)
instead
+                             * of Character.isSpaceChar(…) in order to consider non-breaking
spaces as
+                             * non-white characters. This is similar to the use of &nbsp;
in HTML tables,
+                             * which can be used for forcing the insertion of an otherwise
ignored space.
+                             */
                             for (int i=next; i<textLength; i += Character.charCount(c))
{
                                 c = cellText.codePointAt(i);
                                 if (!Character.isWhitespace(c)) {
@@ -728,7 +804,8 @@ public class TableFormatter extends Filt
                     if (isFirstColumn) {
                         out.append(leftBorder);
                     }
-                    final Appendable tabExpander = (cellText.indexOf('\t') >= 0) ? new
ExpandedTabFormatter(out) : out;
+                    final Appendable tabExpander = (cellText.indexOf('\t') >= 0)
+                            ? new LineFormatter(out, Integer.MAX_VALUE, true) : out;
                     switch (cell.alignment) {
                         default: {
                             throw new AssertionError(cell.alignment);
@@ -744,10 +821,10 @@ public class TableFormatter extends Filt
                             break;
                         }
                         case ALIGN_CENTER: {
-                            final int rightMargin = (cellWidth-textLength)/2;
+                            final int rightMargin = (cellWidth - textLength) / 2;
                             repeat(tabExpander, cell.fill, rightMargin);
                             tabExpander.append(cellText);
-                            repeat(tabExpander, cell.fill, (cellWidth-rightMargin)-textLength);
+                            repeat(tabExpander, cell.fill, (cellWidth - rightMargin) - textLength);
                             break;
                         }
                     }

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/package-info.java?rev=1403771&r1=1403770&r2=1403771&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/package-info.java (original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/io/package-info.java Tue Oct
30 16:35:08 2012
@@ -19,8 +19,8 @@
  * Extensions to standard Java I/O ({@link java.io.Reader}, {@link java.io.Writer},
  * {@link java.lang.Appendable}).
  * Many classes defined in this package are filters applying on-the-fly formatting while
writing
- * text to the output device. For example {@link org.apache.sis.io.IndentedLineFormatter}
adds
- * indentation at the beginning of every new line, and {@link org.apache.sis.io.TableFormatter}
+ * text to the output device. For example {@link org.apache.sis.io.LineFormatter} can wrap
lines
+ * to some maximal line length (e.g. 80 characters), and {@link org.apache.sis.io.TableFormatter}
  * replaces all occurrence of {@code '\t'} by the amount of spaces needed for producing a
tabular
  * output.
  *

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/math/MathFunctions.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/math/MathFunctions.java?rev=1403771&r1=1403770&r2=1403771&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/math/MathFunctions.java (original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/math/MathFunctions.java Tue
Oct 30 16:35:08 2012
@@ -163,7 +163,7 @@ public final class MathFunctions extends
      *         or less in magnitude than the given value.
      */
     public static double truncate(final double value) {
-        return (value < 0) ? Math.ceil(value) : Math.floor(value);
+        return (doubleToRawLongBits(value) & SIGN_BIT_MASK) == 0 ? Math.floor(value)
: Math.ceil(value);
     }
 
     /**
@@ -215,6 +215,91 @@ public final class MathFunctions extends
     }
 
     /**
+     * Returns the number of fraction digits needed for formatting in base 10 numbers of
the given
+     * accuracy. If the {@code strict} argument is {@code true}, then for any given {@code
accuracy}
+     * this method returns a value <var>n</var> such as the difference between
adjacent numbers
+     * formatted in base 10 with <var>n</var> fraction digits will always be
equals or smaller
+     * than {@code accuracy}. Examples:
+     *
+     * <ul>
+     *   <li>{@code fractionDigitsForDelta(0.001, true)} returns 3.</li>
+     *   <li>{@code fractionDigitsForDelta(0.009, true)} returns 3.</li>
+     *   <li>{@code fractionDigitsForDelta(0.010, true)} returns 2.</li>
+     *   <li>{@code fractionDigitsForDelta(0.099, true)} returns 3 (special case).</li>
+     * </ul>
+     *
+     * <p>Special cases:</p>
+     * <ul>
+     *   <li>If {@code accuracy} is 0, {@link Double#NaN NaN} or infinity,
+     *       then this method returns 0.</li>
+     *   <li>If {@code accuracy} is greater than 1, then this method returns
+     *       the number of "unnecessary" trailing zeros as a negative number.
+     *       For example {@code fractionDigitsForDelta(100, …)} returns -2.</li>
+     *   <li>If the first non-zero digits of {@code accuracy} are equal or greater
than 95
+     *       (e.g. 0.00099) and the {@code strict} argument is {@code true}, then this method
+     *       increases the number of needed fraction digits in order to prevent the rounded
+     *       number to be collapsed into the next integer value.
+     *
+     *       <blockquote><font size="-1"><b>Example:</b>
+     *       If {@code accuracy} is 0.95, then a return value of 1 is not sufficient since
the
+     *       rounded value of 0.95 with 1 fraction digit would be 1.0. Such value would be
a
+     *       violation of this method contract since the difference between 0 and that formatted
+     *       value would be greater than the accuracy. Note that this is not an artificial
rule;
+     *       this is related to the fact that 0.9999… is mathematically strictly equals
to 1.
+     *       </font></blockquote></li>
+     * </ul>
+     *
+     * <p>Invoking this method is equivalent to computing <code>(int)
+     * -{@linkplain Math#floor(double) floor}({@linkplain Math#log10(double) log10}(accuracy))</code>
+     * except for the 0, {@code NaN}, infinities and {@code 0.…95} special cases.</p>
+     *
+     * @param  accuracy The desired accuracy of numbers to format in base 10.
+     * @param  strict {@code true} for checking the {@code 0.…95} special case.
+     *         If {@code false}, then the difference between adjacent formatted numbers is
not
+     *         guaranteed to be smaller than {@code accuracy} in every cases.
+     * @return Number of fraction digits needed for formatting numbers with the given accuracy.
+     *         May be negative.
+     *
+     * @see java.text.NumberFormat#setMaximumFractionDigits(int)
+     */
+    public static int fractionDigitsForDelta(double accuracy, final boolean strict) {
+        accuracy = Math.abs(accuracy);
+        final boolean isFraction = (accuracy < 1);
+        /*
+         * Compute (int) Math.log10(x) with opportunist use of the POW10 array.
+         * We use the POW10 array because accurate calculation of log10 is relatively costly,
+         * while we only want the integer part. A micro-benchmarking on JDK7 suggested that
a
+         * binary search on POW10 is about 30% faster than invoking (int) Math.log10(x).
+         */
+        int i = Arrays.binarySearch(POW10, isFraction ? 1/accuracy : accuracy);
+        if (i >= 0) {
+            return isFraction ? i : -i;
+        }
+        i = ~i;
+        double scale;
+        if (i < POW10.length) {
+            scale = POW10[i];
+            if (!isFraction) {
+                i = -(i-1);
+                scale = 10 / scale;
+            }
+        } else { // 'x' is out of range or NaN.
+            final double y = Math.log10(accuracy);
+            if (Double.isInfinite(y)) {
+                return 0;
+            }
+            i = -((int) Math.floor(y));
+            scale = pow10(i);
+        }
+        while ((accuracy *= scale) >= 9.5) {
+            i++; // The 0.…95 special case.
+            accuracy -= Math.floor(accuracy);
+            scale = 10;
+        }
+        return i;
+    }
+
+    /**
      * Computes 10 raised to the power of <var>x</var>. This method delegates
to
      * <code>{@linkplain #pow10(int) pow10}((int) x)</code> if <var>x</var>
is an
      * integer, or to <code>{@linkplain Math#pow(double, double) Math.pow}(10, x)</code>

Modified: sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/Angle.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/Angle.java?rev=1403771&r1=1403770&r2=1403771&view=diff
==============================================================================
--- sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/Angle.java (original)
+++ sis/branches/JDK6/sis-utility/src/main/java/org/apache/sis/measure/Angle.java Tue Oct
30 16:35:08 2012
@@ -17,12 +17,15 @@
 package org.apache.sis.measure;
 
 import java.util.Locale;
+import java.util.Formatter;
+import java.util.Formattable;
+import java.util.FormattableFlags;
 import java.text.Format;
 import java.text.ParseException;
 import java.io.Serializable;
 import net.jcip.annotations.Immutable;
-
 import org.apache.sis.util.Utilities;
+import org.apache.sis.math.MathFunctions;
 
 
 /**
@@ -30,6 +33,12 @@ import org.apache.sis.util.Utilities;
  * plane into coincidence with another, generally measured in degrees, sexagesimal degrees
or
  * grads.
  *
+ * {@section Formatting angles}
+ * The recommended way to format angles is to instantiate an {@link AngleFormat} once, then
to
+ * reuse it many times. As a convenience, {@code Angle} objects can also be formatted by
the
+ * {@code "%s"} conversion specifier of {@link Formatter}, but this is less efficient for
this
+ * class.
+ *
  * @author  Martin Desruisseaux (MPO, IRD, Geomatys)
  * @since   0.3 (derived from geotk-1.0)
  * @version 0.3
@@ -40,7 +49,7 @@ import org.apache.sis.util.Utilities;
  * @see AngleFormat
  */
 @Immutable
-public class Angle implements Comparable<Angle>, Serializable {
+public class Angle implements Comparable<Angle>, Formattable, Serializable {
     /**
      * Serial number for inter-operability with different versions.
      */
@@ -100,7 +109,8 @@ public class Angle implements Comparable
             e.initCause(exception);
             throw e;
         }
-        if (getClass().isAssignableFrom(angle.getClass())) {
+        final Class<?> type = angle.getClass();
+        if (type == Angle.class || getClass().isAssignableFrom(type)) {
             this.θ = ((Angle) angle).θ;
         } else {
             throw new NumberFormatException(string);
@@ -164,18 +174,52 @@ public class Angle implements Comparable
     }
 
     /**
+     * Upper threshold before to format an angle as an ordinary number.
+     * This is set to 90° in the case of latitude numbers.
+     */
+    double maximum() {
+        return 360;
+    }
+
+    /**
+     * Returns the hemisphere character for an angle of the given sign.
+     * This is used only by {@link #toString()}, not by {@link AngleFormat}.
+     */
+    char hemisphere(final boolean negative) {
+        return 0;
+    }
+
+    /**
      * Returns a string representation of this {@code Angle} object.
      * This is a convenience method mostly for debugging purpose, since it uses a fixed locale.
      * Developers should consider using {@link AngleFormat} for end-user applications
instead
      * than this method.
      *
-     * @see AngleFormat#format(Angle)
+     * @see AngleFormat#format(double)
      */
     @Override
     public String toString() {
         StringBuffer buffer = new StringBuffer(16);
-        synchronized (Angle.class) {
-            buffer = getAngleFormat().format(this, buffer, null);
+        double m = Math.abs(θ);
+        final boolean isSmall = m <= (1 / 3600E+3); // 1E-3 arc-second.
+        if (isSmall || m > maximum()) {
+            final char h = hemisphere(MathFunctions.isNegative(θ));
+            if (h == 0) {
+                m = θ;  // Restore the sign.
+            }
+            char symbol = '°';
+            if (isSmall) {
+                symbol = '″';
+                m *= 3600;
+            }
+            buffer.append(m).append(symbol);
+            if (h != 0) {
+                buffer.append(h);
+            }
+        } else {
+            synchronized (Angle.class) {
+                buffer = getAngleFormat().format(this, buffer, null);
+            }
         }
         return buffer.toString();
     }
@@ -200,4 +244,46 @@ public class Angle implements Comparable
         }
         return format;
     }
+
+    /**
+     * Formats this angle using the provider formatter. This method is invoked when an
+     * {@code Angle} object is formatted using the {@code "%s"} conversion specifier of
+     * {@link Formatter}. Users don't need to invoke this method explicitely.
+     *
+     * <p>Special cases:</p>
+     * <ul>
+     *   <li>If the precision is 0, then this method formats an empty string.</li>
+     *   <li>If the precision is 1 and this angle is a {@link Latitude} or {@link Longitude},
+     *       then this method formats only the hemisphere symbol.</li>
+     *   <li>Otherwise the precision, if positive, is given to {@link AngleFormat#setMaximumWidth(int)}.
+     *       That formatter will try to respect the precision limit, but the formatted angle
may
+     *       still be wider if the precision is too small or the angle magnitude too large.</li>
+     * </ul>
+     *
+     * @param formatter The formatter in which to format this angle.
+     * @param flags     {@link FormattableFlags#LEFT_JUSTIFY} for left alignment, or 0 for
right alignment.
+     * @param width     Minimal number of characters to write, padding with {@code ' '} if
necessary.
+     * @param precision Maximal number of characters to write, or -1 if no limit.
+     */
+    @Override
+    public void formatTo(final Formatter formatter, final int flags, final int width, int
precision) {
+        final String value;
+        if (precision == 0) {
+            value = "";
+        } else {
+            if (precision > 0) {
+                final char h = hemisphere(MathFunctions.isNegative(θ));
+                if (h != 0 && --precision == 0) {
+                    formatter.format("%c", h);
+                    return;
+                }
+            }
+            final AngleFormat format = new AngleFormat(formatter.locale());
+            if (precision > 0) {
+                format.setMaximumWidth(precision);
+            }
+            value = format.format(this, new StringBuffer(16), null).toString();
+        }
+        org.apache.sis.internal.util.Utilities.formatTo(formatter, flags, width, value);
+    }
 }



Mime
View raw message