sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1652466 - in /sis/branches/JDK7: ./ core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ core/sis-metadata/src/main/java/org/apache/sis/io/wkt/ core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/ core/sis-metad...
Date Fri, 16 Jan 2015 17:28:38 GMT
Author: desruisseaux
Date: Fri Jan 16 17:28:38 2015
New Revision: 1652466

URL: http://svn.apache.org/r1652466
Log:
Merge from the JDK8 branch:
- Update for GeoAPI change in org.opengis.temporal (pending interfaces).
- ISO 19162 requires us that we replace non-ASCII characters by ASCII ones in all WKT elements
except REMARKS["..."].

Modified:
    sis/branches/JDK7/   (props changed)
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/ElementKind.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/FormatterTest.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/TimeInstant.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/TemporalUtilities.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gml/DummyInstant.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/StringBuildersTest.java

Propchange: sis/branches/JDK7/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jan 16 17:28:38 2015
@@ -1,4 +1,4 @@
 /sis/branches/Android:1430670-1480699
 /sis/branches/JDK6:1394913-1508480
-/sis/branches/JDK8:1584960-1652019
+/sis/branches/JDK8:1584960-1652464
 /sis/trunk:1394364-1508466,1519089-1519674

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java?rev=1652466&r1=1652465&r2=1652466&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/LegacyPropertyAdapter.java
[UTF-8] Fri Jan 16 17:28:38 2015
@@ -27,6 +27,9 @@ import org.apache.sis.internal.jaxb.Cont
 import org.apache.sis.util.resources.Messages;
 import org.apache.sis.util.ArgumentChecks;
 
+// Branch-dependent imports
+import java.util.Objects;
+
 
 /**
  * An adapter for collections of a legacy type replaced by an other collection.
@@ -319,4 +322,46 @@ public abstract class LegacyPropertyAdap
             }
         };
     }
+
+    /**
+     * Compares this collection with the given object for equality. This method performs
comparisons only with
+     * instances of {@code LegacyPropertyAdapter}, and returns {@code false} for all other
kinds of collection.
+     * We do <strong>not</strong> compare with arbitrary collection implementations.
+     *
+     * <p><b>Rational:</b> {@link Collection#equals(Object)} contract explicitely
forbids comparisons with
+     * {@code List} and {@code Set}. The rational explained in {@code Collection} javadoc
applies also to
+     * other kind of {@code Collection} implementations: we can not enforce {@code Collection.equals(Object)}
+     * to be symmetric in such cases.</p>
+     *
+     * @param  other The other object to compare with this collection, or {@code null}.
+     * @return {@code true} if the objects are equal, or {@code false} otherwise.
+     */
+    @Override
+    public final boolean equals(final Object other) {
+        if (!(other instanceof LegacyPropertyAdapter<?,?>)) {
+            return false;
+        }
+        final Iterator<?> ot = ((LegacyPropertyAdapter<?,?>) other).iterator();
+        final Iterator<L> it = iterator();
+        while (it.hasNext()) {
+            if (!ot.hasNext() || !Objects.equals(it.next(), ot.next())) {
+                return false;
+            }
+        }
+        return !ot.hasNext();
+    }
+
+    /**
+     * Returns a hash code value for this collection.
+     *
+     * @return A hash code value calculated from the content of this collection.
+     */
+    @Override
+    public final int hashCode() {
+        int code = 0;
+        for (final L element : this) {
+            code = code*31 + Objects.hashCode(element);
+        }
+        return code;
+    }
 }

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java?rev=1652466&r1=1652465&r2=1652466&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java
[UTF-8] Fri Jan 16 17:28:38 2015
@@ -55,7 +55,7 @@ import org.apache.sis.metadata.iso.citat
 public enum Convention {
     /**
      * The ISO 19162 format, also known as “WKT 2”.
-     * This convention follows the ISO recommendations except the following ones:
+     * This convention follows the ISO recommendations with the following exceptions:
      *
      * <ul>
      *   <li>{@code Axis} element omits the {@code Order} sub-element.</li>
@@ -144,6 +144,7 @@ public enum Convention {
      * with the following differences:
      *
      * <ul>
+     *   <li>All quoted texts (not only the remarks) preserve non-ASCII characters.</li>
      *   <li>Map projections are shown as SIS stores them internally, i.e. with the
separation between
      *       linear and non-linear steps, rather than as a single operation.</li>
      *   <li>{@code CompoundCRS} shows nested compound CRS if any (the structure is
not flattened).</li>
@@ -155,8 +156,8 @@ public enum Convention {
      *       not only CRS or coordinate operations.</li>
      *   <li>Additional attributes not defined by ISO 19162 may be formatted:
      *     <ul>
-     *       <li>{@code ImageDatum} includes the {@link org.apache.sis.referencing.datum.DefaultImageDatum#getPixelInCell()
Pixel in Cell} code.</li>
-     *       <li>{@code TemporalDatum} includes the {@link org.apache.sis.referencing.datum.DefaultTemporalDatum#getOrigin()
Origin} date.</li>
+     *       <li>{@code ImageDatum} includes the {@linkplain org.apache.sis.referencing.datum.DefaultImageDatum#getPixelInCell()
Pixel in Cell} code.</li>
+     *       <li>{@code TemporalDatum} includes the {@linkplain org.apache.sis.referencing.datum.DefaultTemporalDatum#getOrigin()
Origin} date.</li>
      *     </ul>
      *   </li>
      * </ul>

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/ElementKind.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/ElementKind.java?rev=1652466&r1=1652465&r2=1652466&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/ElementKind.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/ElementKind.java
[UTF-8] Fri Jan 16 17:28:38 2015
@@ -114,6 +114,10 @@ public enum ElementKind {
     /**
      * {@linkplain org.apache.sis.referencing.AbstractIdentifiedObject#getRemarks() Remarks},
      * often represented by {@code REMARKS[…]} elements.
+     *
+     * <p>When formatting an ISO 19162 Well Known Text, texts quoted as remarks preserve
non-ASCII characters.
+     * By contrast, quoted texts in any other {@code ElementKind} will have some non-ASCII
characters replaced
+     * by ASCII ones (e.g. "é" → "e").</p>
      */
     REMARKS,
 

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java?rev=1652466&r1=1652465&r2=1652466&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] Fri Jan 16 17:28:38 2015
@@ -168,6 +168,12 @@ public class Formatter implements Locali
     private Citation authority;
 
     /**
+     * {@code true} for preserving non-ASCII characters. The default value is {@code false},
+     * which causes replacements like "é" → "e" in all elements except {@code REMARKS["…"]}.
+     */
+    boolean isNonAsciiAllowed;
+
+    /**
      * The enclosing WKT element being formatted.
      *
      * @see #getEnclosingElement(int)
@@ -372,11 +378,12 @@ public class Formatter implements Locali
     final void configure(Convention convention, final Citation authority, final Colors colors,
             final boolean toUpperCase, final byte indentation)
     {
-        this.convention  = convention;
-        this.authority   = (authority != null) ? authority : convention.getNameAuthority();
-        this.colors      = colors;
-        this.toUpperCase = toUpperCase;
-        this.indentation = indentation;
+        this.convention   = convention;
+        this.authority    = (authority != null) ? authority : convention.getNameAuthority();
+        this.colors       = colors;
+        this.toUpperCase  = toUpperCase;
+        this.indentation  = indentation;
+        isNonAsciiAllowed = (convention == Convention.INTERNAL);
     }
 
     /**
@@ -859,7 +866,8 @@ public class Formatter implements Locali
                 final Matrix matrix = ReferencingServices.getInstance().getMatrix(transform);
                 if (matrix != null) {
                     openElement(true, "Param_MT");
-                    quote("Affine");
+                    buffer.appendCodePoint(symbols.getOpeningQuote(0)).append("Affine")
+                          .appendCodePoint(symbols.getClosingQuote(0));
                     indent(+1);
                     append(matrix);
                     indent(-1);
@@ -890,7 +898,7 @@ public class Formatter implements Locali
         boolean columns = false;
         do {
             openElement(true, "Parameter");
-            quote(columns ? "num_col" : "num_row");
+            buffer.appendCodePoint(openQuote).append(columns ? "num_col" : "num_row").appendCodePoint(closeQuote);
             append(columns ? numCol : numRow);
             closeElement(false);
         } while ((columns = !columns) == true);
@@ -932,9 +940,7 @@ public class Formatter implements Locali
             final String localized = CharSequences.trimWhitespaces(text.toString(locale));
             if (localized != null && !localized.isEmpty()) {
                 openElement(true, keyword);
-                setColor(type);
-                quote(localized);
-                resetColor();
+                quote(localized, type);
                 closeElement(true);
             }
         }
@@ -950,9 +956,7 @@ public class Formatter implements Locali
     public void append(final String text, final ElementKind type) {
         if (text != null) {
             appendSeparator();
-            setColor(type);
-            quote(text);
-            resetColor();
+            quote(text, type);
         }
     }
 
@@ -961,10 +965,16 @@ public class Formatter implements Locali
      * that character will be doubled (WKT 2) or deleted (WKT 1). We check for the closing
quote only because
      * it is the character that the parser will look for determining the text end.
      */
-    private void quote(final String text) {
+    private void quote(final String text, final ElementKind type) {
+        setColor(type);
         final int base = buffer.appendCodePoint(symbols.getOpeningQuote(0)).length();
-        buffer.append(text);
+        if (isNonAsciiAllowed || (type == ElementKind.REMARKS)) {
+            buffer.append(text);
+        } else {
+            buffer.append(CharSequences.toASCII(text));
+        }
         closeQuote(base);
+        resetColor();
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/WKTFormat.java?rev=1652466&r1=1652465&r2=1652466&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
[UTF-8] Fri Jan 16 17:28:38 2015
@@ -78,7 +78,7 @@ import org.apache.sis.util.resources.Err
  * @author  Martin Desruisseaux (Geomatys)
  * @author  Rémi Eve (IRD)
  * @since   0.4 (derived from geotk-3.20)
- * @version 0.4
+ * @version 0.5
  * @module
  */
 public class WKTFormat extends CompoundFormat<Object> {
@@ -146,6 +146,12 @@ public class WKTFormat extends CompoundF
     private KeywordCase keywordCase;
 
     /**
+     * {@code true} for preserving non-ASCII characters. The default value is {@code false},
+     * which causes replacements like "é" → "e" in all elements except {@code REMARKS["…"]}.
+     */
+    private boolean isNonAsciiAllowed;
+
+    /**
      * The amount of spaces to use in indentation, or {@value #SINGLE_LINE} if indentation
is disabled.
      * The same value is also stored in the {@linkplain #formatter}.
      * It appears here for serialization purpose.
@@ -218,6 +224,34 @@ public class WKTFormat extends CompoundF
     }
 
     /**
+     * Returns whether non-ASCII characters are preserved. The default value is {@code false},
+     * which causes replacements like "é" → "e" in all elements except {@link ElementKind#REMARKS}.
+     *
+     * <p>This value is always {@code true} when the WKT {@linkplain #getConvention()
convention}
+     * is set to {@link Convention#INTERNAL}.</p>
+     *
+     * @return Whether non-ASCII characters are preserved.
+     *
+     * @since 0.5
+     */
+    public boolean isNonAsciiAllowed() {
+        return isNonAsciiAllowed || (convention == Convention.INTERNAL);
+    }
+
+    /**
+     * Sets whether non-ASCII characters shall be preserved. The default value is {@code
false},
+     * which causes replacements like "é" → "e" in all elements except {@link ElementKind#REMARKS}.
+     * Setting this property to {@code true} will disable such replacements.
+     *
+     * @param allowed Whether non-ASCII characters shall be preserved.
+     *
+     * @since 0.5
+     */
+    public void setNonAsciiAllowed(final boolean allowed) {
+        isNonAsciiAllowed = allowed;
+    }
+
+    /**
      * Returns whether WKT keywords should be written with upper cases or camel cases.
      *
      * @return The case to use for formatting keywords.
@@ -347,6 +381,7 @@ public class WKTFormat extends CompoundF
                 default: toUpperCase = (convention.majorVersion() == 1); break;
             }
             formatter.configure(convention, authority, colors, toUpperCase, indentation);
+            formatter.isNonAsciiAllowed |= isNonAsciiAllowed;
         }
     }
 

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java?rev=1652466&r1=1652465&r2=1652466&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultTemporalExtent.java
[UTF-8] Fri Jan 16 17:28:38 2015
@@ -168,7 +168,7 @@ public class DefaultTemporalExtent exten
         } else {
             return null;
         }
-        return instant.getPosition().getDate();
+        return instant.getDate();
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/FormatterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/FormatterTest.java?rev=1652466&r1=1652465&r2=1652466&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/FormatterTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/io/wkt/FormatterTest.java
[UTF-8] Fri Jan 16 17:28:38 2015
@@ -55,6 +55,22 @@ public final strictfp class FormatterTes
     }
 
     /**
+     * Tests (indirectly) {@link Formatter#quote(String)}.
+     */
+    @Test
+    public void testQuote() {
+        assertWktEquals(Convention.WKT2,
+                "“A “quote”” to double”",               // Expect doubling quotes.
+                 "A “quote” to double");
+        assertWktEquals(Convention.WKT2,
+                "“Nouvelle Triangulation Francaise”",   // Expect replacement of non-latin
characters.
+                 "Nouvelle Triangulation Française");
+        assertWktEquals(Convention.INTERNAL,
+                "“Nouvelle Triangulation Française”",   // Non-latin characters shall
be preserved in internal mode.
+                 "Nouvelle Triangulation Française");
+    }
+
+    /**
      * Tests (indirectly) {@link Formatter#append(GeographicBoundingBox, int)}.
      */
     @Test

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java?rev=1652466&r1=1652465&r2=1652466&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/DefaultMetadataTest.java
[UTF-8] Fri Jan 16 17:28:38 2015
@@ -238,7 +238,9 @@ public final strictfp class DefaultMetad
         final DefaultMetadata metadata = new DefaultMetadata();
         assertTrue("hierarchyLevelNames", metadata.getHierarchyLevelNames().isEmpty());
         assertTrue("hierarchyLevels",     metadata.getHierarchyLevels().isEmpty());
-
+        /*
+         * Tests the setter and verify immediately with the getter methods.
+         */
         metadata.setHierarchyLevelNames(Arrays.asList(names));
         metadata.setHierarchyLevels(Arrays.asList(levels));
         assertArrayEquals("hierarchyLevelNames", names,  metadata.getHierarchyLevelNames().toArray());
@@ -255,7 +257,7 @@ public final strictfp class DefaultMetad
         assertEquals("metadataScopes[1].name", "Golden Gate Bridge", scope.getName().toString());
         assertEquals("metadataScopes[1].resourceScope", ScopeCode.FEATURE, scope.getResourceScope());
         /*
-         * Changes in the MetadataScope object shall be relfected immediately on the scope
collection.
+         * Changes in the MetadataScope object shall be reflected immediately on the scope
collection.
          * Verify that.
          */
         it.remove();
@@ -266,6 +268,17 @@ public final strictfp class DefaultMetad
         assertTrue(scopes.add(c));
         assertArrayEquals("hierarchyLevelNames", names,  metadata.getHierarchyLevelNames().toArray());
         assertArrayEquals("hierarchyLevels",     levels, metadata.getHierarchyLevels().toArray());
+        /*
+         * Test the customized equals(Object) and hashCode() implementations.
+         * Note: the 'assertNotSame' check is not a contract requirement. It is just that
if
+         * 'n1' and 'n2' are the same, then the test become pointless and should be removed.
+         */
+        Collection<String> n1 = metadata.getHierarchyLevelNames();
+        Collection<String> n2 = metadata.getHierarchyLevelNames();
+        assertNotSame("Remove this test.", n1, n2); // See above comment.
+        assertTrue("equals", n1.equals(n2));
+        assertTrue("equals", n2.equals(n1));
+        assertEquals("hashCode", n1.hashCode(), n2.hashCode());
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/TimeInstant.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/TimeInstant.java?rev=1652466&r1=1652465&r2=1652466&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/TimeInstant.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gml/TimeInstant.java
[UTF-8] Fri Jan 16 17:28:38 2015
@@ -16,13 +16,13 @@
  */
 package org.apache.sis.internal.jaxb.gml;
 
+import java.util.Date;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.datatype.XMLGregorianCalendar;
 import javax.xml.datatype.DatatypeConfigurationException;
 import org.opengis.temporal.Instant;
-import org.opengis.temporal.Position;
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.internal.jaxb.XmlUtilities;
 
@@ -78,14 +78,14 @@ public final class TimeInstant extends G
      */
     static XMLGregorianCalendar toXML(final Instant instant) {
         if (instant != null) {
-            final Position position = instant.getPosition();
-            if (position != null) {
+            final Date date = instant.getDate();
+            if (date != null) {
                 final Context context = Context.current();
                 try {
-                    final XMLGregorianCalendar date = XmlUtilities.toXML(context, position.getDate());
-                    if (date != null) {
-                        XmlUtilities.trimTime(date, false);
-                        return date;
+                    final XMLGregorianCalendar gc = XmlUtilities.toXML(context, date);
+                    if (gc != null) {
+                        XmlUtilities.trimTime(gc, false);
+                        return gc;
                     }
                 } catch (DatatypeConfigurationException e) {
                     Context.warningOccured(context, TimeInstant.class, "toXML", e, true);

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/TemporalUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/TemporalUtilities.java?rev=1652466&r1=1652465&r2=1652466&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/TemporalUtilities.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/TemporalUtilities.java
[UTF-8] Fri Jan 16 17:28:38 2015
@@ -60,7 +60,7 @@ public final class TemporalUtilities ext
      * Creates an instant for the given date using the given factory.
      */
     private static Instant createInstant(final TemporalFactory factory, final Date date)
{
-        return factory.createInstant(factory.createPosition(date));
+        return factory.createInstant(date);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java?rev=1652466&r1=1652465&r2=1652466&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/StringBuilders.java
[UTF-8] Fri Jan 16 17:28:38 2015
@@ -212,21 +212,38 @@ public final class StringBuilders extend
      */
     static CharSequence toASCII(CharSequence text, StringBuilder buffer) {
         if (text != null) {
-            final int length = text.length();
-            for (int i=0; i<length;) {
-                final int c = codePointAt(text, i);
+            /*
+             * Scan the buffer in reverse order because we may suppress some characters.
+             */
+            int i = text.length();
+            while (i > 0) {
+                final int c = codePointBefore(text, i);
+                final int n = charCount(c);
                 final int r = c - 0xC0;
-                if (r >= 0 && r<ASCII.length()) {
-                    final char ac = ASCII.charAt(r);
+                i -= n; // After this line, 'i' is the index of character 'c'.
+                if (r >= 0) {
+                    final char cr; // The character replacement.
+                    if (r < ASCII.length()) {
+                        cr = ASCII.charAt(r);
+                    } else {
+                        switch (getType(c)) {
+                            case SPACE_SEPARATOR: cr = ' '; break;
+                            case PARAGRAPH_SEPARATOR: // Fall through
+                            case LINE_SEPARATOR: cr = '\n'; break;
+                            default: continue;
+                        }
+                    }
                     if (buffer == null) {
                         buffer = new StringBuilder(text.length()).append(text);
                         text = buffer;
                     }
-                    // Nothing special do to about codepoint here, since 'c' is
-                    // in the basic plane (verified by the r<ASCII.length() check).
-                    buffer.setCharAt(i, ac);
+                    if (n == 2) {
+                        buffer.deleteCharAt(i + 1); // Remove the low surrogate of a surrogate
pair.
+                    }
+                    // Nothing special to do about codepoint here, since 'c' is in
+                    // the basic plane (verified by the r < ASCII.length() check).
+                    buffer.setCharAt(i, cr);
                 }
-                i += charCount(c);
             }
         }
         return text;

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gml/DummyInstant.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gml/DummyInstant.java?rev=1652466&r1=1652465&r2=1652466&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gml/DummyInstant.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gml/DummyInstant.java
[UTF-8] Fri Jan 16 17:28:38 2015
@@ -16,19 +16,13 @@
  */
 package org.apache.sis.internal.jaxb.gml;
 
-import java.sql.Time;
 import java.util.Date;
-import java.util.Collection;
-import java.util.Collections;
 import org.opengis.temporal.Instant;
-import org.opengis.temporal.Period;
 import org.opengis.temporal.Duration;
-import org.opengis.temporal.Position;
 import org.opengis.temporal.RelativePosition;
 import org.opengis.temporal.TemporalPosition;
 import org.opengis.temporal.TemporalPrimitive;
 import org.opengis.temporal.TemporalGeometricPrimitive;
-import org.opengis.util.InternationalString;
 import org.apache.sis.internal.simple.SimpleIdentifiedObject;
 
 
@@ -42,7 +36,7 @@ import org.apache.sis.internal.simple.Si
  * @module
  */
 @SuppressWarnings("serial")
-final class DummyInstant extends SimpleIdentifiedObject implements Instant, Position {
+final class DummyInstant extends SimpleIdentifiedObject implements Instant {
     /**
      * The time, in milliseconds elapsed since January 1st, 1970.
      */
@@ -64,26 +58,10 @@ final class DummyInstant extends SimpleI
     }
 
     /**
-     * Returns the position, which is {@code this}.
-     */
-    @Override
-    public Position getPosition() {
-        return this;
-    }
-
-    /**
-     * Empty properties.
-     */
-    @Override public Time                getTime()     {return null;}
-    @Override public InternationalString getDateTime() {return null;}
-    @Override public TemporalPosition    anyOther()    {return null;}
-    @Override public Collection<Period>  getBegunBy()  {return Collections.emptySet();}
-    @Override public Collection<Period>  getEndedBy()  {return Collections.emptySet();}
-    @Override public Duration            length()      {return null;}
-
-    /**
      * Unsupported operations.
      */
+    @Override public Duration         length()                                   {throw new
UnsupportedOperationException();}
     @Override public RelativePosition relativePosition(TemporalPrimitive  other) {throw new
UnsupportedOperationException();}
     @Override public Duration         distance(TemporalGeometricPrimitive other) {throw new
UnsupportedOperationException();}
+    @Override public TemporalPosition getTemporalPosition()                      {throw new
UnsupportedOperationException();}
 }

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/StringBuildersTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/StringBuildersTest.java?rev=1652466&r1=1652465&r2=1652466&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/StringBuildersTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/StringBuildersTest.java
[UTF-8] Fri Jan 16 17:28:38 2015
@@ -97,8 +97,8 @@ public final strictfp class StringBuilde
      */
     @Test
     public void testToASCII() {
-        final StringBuilder metre = new StringBuilder("mètre");
+        final StringBuilder metre = new StringBuilder("mètres" + Characters.PARAGRAPH_SEPARATOR);
         toASCII(metre);
-        assertEquals("metre", metre.toString());
+        assertEquals("metres\n", metre.toString());
     }
 }



Mime
View raw message