sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1554584 - in /sis/branches/JDK7/core: sis-referencing/src/main/java/org/apache/sis/io/wkt/ sis-referencing/src/main/java/org/apache/sis/referencing/ sis-referencing/src/main/java/org/apache/sis/referencing/datum/ sis-utility/src/main/java/...
Date Tue, 31 Dec 2013 22:31:29 GMT
Author: desruisseaux
Date: Tue Dec 31 22:31:29 2013
New Revision: 1554584

URL: http://svn.apache.org/r1554584
Log:
- getPositionVectorTransformation was assigning the 'tZ' value to the wrong matrix element.
- toString() should prefer Unicode identifier (opportunist consolidation of CharSequences
in this process).

Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifiedObjects.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/FormattableObject.java?rev=1554584&r1=1554583&r2=1554584&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/FormattableObject.java
[UTF-8] Tue Dec 31 22:31:29 2013
@@ -192,10 +192,9 @@ public class FormattableObject {
      * Formats the inner part of this <cite>Well Known Text</cite> (WKT) element
into the given formatter.
      * This method is automatically invoked by {@link WKTFormat} when a formattable element
is found.
      *
-     * <p>Element keyword and {@linkplain org.apache.sis.referencing.IdentifiedObjects#getIdentifierCode
-     * authority code} shall not be formatted here. For example if this formattable element
is for a
-     * {@code GEOGCS} element, then this method shall write the content starting at the insertion
point
-     * shows below:</p>
+     * <p>Element keyword and authority code shall not be formatted here.
+     * For example if this formattable element is for a {@code GEOGCS} element,
+     * then this method shall write the content starting at the insertion point shows below:</p>
      *
      * {@preformat text
      *     GEOGCS["WGS 84", AUTHORITY["EPSG","4326"]]

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifiedObjects.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifiedObjects.java?rev=1554584&r1=1554583&r2=1554584&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifiedObjects.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/IdentifiedObjects.java
[UTF-8] Tue Dec 31 22:31:29 2013
@@ -32,7 +32,7 @@ import org.opengis.referencing.Reference
 import org.apache.sis.util.Static;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.iso.DefaultNameSpace;
-import org.apache.sis.metadata.iso.citation.Citations;
+import org.apache.sis.metadata.iso.citation.Citations; // For javadoc.
 
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
 import static org.apache.sis.util.Characters.Filter.LETTERS_AND_DIGITS;
@@ -74,9 +74,26 @@ public final class IdentifiedObjects ext
     }
 
     /**
+     * Returns every object names and aliases according the given authority. This method
performs
+     * the same work than {@link #getName(IdentifiedObject, Citation)}, except that it does
not
+     * stop at the first match. This method is useful in the rare cases where the same authority
+     * declares more than one name, and all those names are of interest.
+     *
+     * @param  object The object to get the names and aliases from, or {@code null}.
+     * @param  authority The authority for the names to return, or {@code null} for any authority.
+     * @return The object's names and aliases, or an empty set if no name or alias matching
the
+     *         specified authority has been found.
+     */
+    public static Set<String> getNames(final IdentifiedObject object, final Citation
authority) {
+        final Set<String> names = new LinkedHashSet<>(8);
+        name(object, authority, names);
+        return names;
+    }
+
+    /**
      * Returns an object name according the given authority.
-     * This method checks first the {@linkplain IdentifiedObject#getName() primary name},
-     * then all {@linkplain IdentifiedObject#getAlias() alias} in their iteration order.
+     * This method checks first the {@linkplain AbstractIdentifiedObject#getName() primary
name},
+     * then all {@linkplain AbstractIdentifiedObject#getAlias() aliases} in their iteration
order.
      *
      * <ul>
      *   <li><p>If the name or alias implements the {@link ReferenceIdentifier}
interface,
@@ -110,23 +127,6 @@ public final class IdentifiedObjects ext
     }
 
     /**
-     * Returns every object names and aliases according the given authority. This method
performs
-     * the same work than {@link #getName(IdentifiedObject, Citation)}, except that it does
not
-     * stop at the first match. This method is useful in the rare cases where the same authority
-     * declares more than one name, and all those names are of interest.
-     *
-     * @param  object The object to get the names and aliases from, or {@code null}.
-     * @param  authority The authority for the names to return, or {@code null} for any authority.
-     * @return The object's names and aliases, or an empty set if no name or alias matching
the
-     *         specified authority has been found.
-     */
-    public static Set<String> getNames(final IdentifiedObject object, final Citation
authority) {
-        final Set<String> names = new LinkedHashSet<>(8);
-        name(object, authority, names);
-        return names;
-    }
-
-    /**
      * Returns an object name according the given authority. This method is {@code null}-safe:
      * every properties are checked for null values, even the properties that are supposed
to
      * be mandatory (not all implementation defines all mandatory values).
@@ -218,8 +218,8 @@ public final class IdentifiedObjects ext
 
     /**
      * Returns an identifier for the given object according the given authority.
-     * This method checks all {@linkplain IdentifiedObject#getIdentifiers() identifiers}
in their iteration order
-     * and returns the first identifier with an {@linkplain ReferenceIdentifier#getAuthority()
authority} citation
+     * This method checks all {@linkplain AbstractIdentifiedObject#getIdentifiers() identifiers}
in their iteration
+     * order and returns the first identifier with an {@linkplain NamedIdentifier#getAuthority()
authority} citation
      * {@linkplain Citations#identifierMatches(Citation, Citation) matching} the specified
authority.
      *
      * @param  object The object to get the identifier from, or {@code null}.
@@ -246,15 +246,11 @@ public final class IdentifiedObjects ext
     }
 
     /**
-     * Returns the declared identifier, or {@code null} if none. This method searches for
the first
-     * identifier (which is usually the main one) explicitly declared in the {@link IdentifiedObject}.
-     * At the contrary of {@link #searchIdentifierCode(IdentifiedObject, boolean)},
-     * <em>this method does not verify the identifier validity</em>.
-     *
-     * <p>More specifically, this method uses the first non-null element found in
-     * <code>object.{@linkplain IdentifiedObject#getIdentifiers() getIdentifiers()}</code>.
-     * If there is none, then it uses <code>object.{@linkplain IdentifiedObject#getName()
getName()}</code>,
-     * which is not guaranteed to be a valid identifier.</p>
+     * Returns the string representation of the first identifier, or the object name if there
is no identifier.
+     * This method searches for the first non-null element in
+     * <code>object.{@linkplain AbstractIdentifiedObject#getIdentifiers() getIdentifiers()}</code>.
If there is none,
+     * then this method fallback on <code>object.{@linkplain AbstractIdentifiedObject#getName()
getName()}</code>.
+     * The first element found is formatted by {@link #toString(Identifier)}.
      *
      * {@section Recommanded alternatives}
      * <ul>
@@ -265,12 +261,12 @@ public final class IdentifiedObjects ext
      * </ul>
      *
      * @param  object The identified object, or {@code null}.
-     * @return Identifier represented as a string for communication between systems, or {@code
null}.
+     * @return A string representation of the first identifier or name, or {@code null} if
none.
      *
      * @see #getIdentifier(IdentifiedObject, Citation)
      * @see #searchIdentifierCode(IdentifiedObject, boolean)
      */
-    public static String getIdentifierCode(final IdentifiedObject object) {
+    public static String getIdentifierOrName(final IdentifiedObject object) {
         if (object != null) {
             final Iterator<ReferenceIdentifier> it = iterator(object.getIdentifiers());
             if (it != null) while (it.hasNext()) {
@@ -288,6 +284,53 @@ public final class IdentifiedObjects ext
     }
 
     /**
+     * Returns the first name, alias or identifier which is a
+     * {@linkplain CharSequences#isUnicodeIdentifier(CharSequence) valid Unicode identifier}.
+     * This method performs the search in the following order:
+     *
+     * <ul>
+     *   <li><code>object.{@linkplain AbstractIdentifiedObject#getName() getName()}</code></li>
+     *   <li><code>object.{@linkplain AbstractIdentifiedObject#getAlias() getAlias()}</code>
in iteration order</li>
+     *   <li><code>object.{@linkplain AbstractIdentifiedObject#getIdentifiers()
getIdentifiers()}</code> in iteration order</li>
+     * </ul>
+     *
+     * @param  object The identified object, or {@code null}.
+     * @return The first name, alias or identifier which is a valid Unicode identifier, or
{@code null} if none.
+     */
+    public static String getUnicodeIdentifier(final IdentifiedObject object) {
+        if (object != null) {
+            ReferenceIdentifier identifier = object.getName();
+            if (identifier != null) { // Paranoiac check.
+                final String code = identifier.getCode();
+                if (CharSequences.isUnicodeIdentifier(code)) {
+                    return code;
+                }
+            }
+            final Iterator<GenericName> it = iterator(object.getAlias());
+            if (it != null) while (it.hasNext()) {
+                GenericName alias = it.next();
+                if (alias != null && (alias = alias.tip()) != null) {
+                    final String code = alias.toString();
+                    if (CharSequences.isUnicodeIdentifier(code)) {
+                        return code;
+                    }
+                }
+            }
+            final Iterator<ReferenceIdentifier> id = iterator(object.getIdentifiers());
+            if (id != null) while (id.hasNext()) {
+                identifier = id.next();
+                if (identifier != null) { // Paranoiac check.
+                    final String code = identifier.getCode();
+                    if (CharSequences.isUnicodeIdentifier(code)) {
+                        return code;
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
      * Returns {@code true} if either the {@linkplain AbstractIdentifiedObject#getName()
primary name} or at least
      * one {@linkplain AbstractIdentifiedObject#getAlias() alias} matches the given string
according heuristic rules.
      * If the given object is an instance of {@link AbstractIdentifiedObject}, then this
method delegates to its
@@ -409,13 +452,15 @@ public final class IdentifiedObjects ext
             return identifier.toString();
         }
         final String code = identifier.getCode();
+        final String cs;
         if (identifier instanceof ReferenceIdentifier) {
-            final String cs = ((ReferenceIdentifier) identifier).getCodeSpace();
-            if (cs != null) {
-                return cs + DefaultNameSpace.DEFAULT_SEPARATOR + code;
-            }
+            cs = ((ReferenceIdentifier) identifier).getCodeSpace();
+        } else {
+            cs = org.apache.sis.internal.util.Citations.getIdentifier(identifier.getAuthority());
+        }
+        if (cs != null && !cs.isEmpty()) {
+            return cs + DefaultNameSpace.DEFAULT_SEPARATOR + code;
         }
-        final String authority = org.apache.sis.internal.util.Citations.getIdentifier(identifier.getAuthority());
-        return (authority != null) ? (authority + DefaultNameSpace.DEFAULT_SEPARATOR + code)
: code;
+        return code;
     }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java?rev=1554584&r1=1554583&r2=1554584&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/BursaWolfParameters.java
[UTF-8] Tue Dec 31 22:31:29 2013
@@ -427,7 +427,7 @@ public class BursaWolfParameters extends
             final Matrix4 matrix = new Matrix4();
             matrix.m03 = tX;
             matrix.m13 = tY;
-            matrix.m13 = tZ;
+            matrix.m23 = tZ;
             return matrix;
         }
         /*
@@ -625,10 +625,10 @@ public class BursaWolfParameters extends
             return "TOWGS84";
         }
         String keyword = super.formatTo(formatter); // Declare the WKT as invalid.
-        final String name = IdentifiedObjects.getName(targetDatum, null);
+        final String name = IdentifiedObjects.getUnicodeIdentifier(targetDatum);
         if (name != null) {
             // We may try to build something better here in future SIS versions, if there
is a need for that.
-            keyword = "To" + name;
+            keyword = "TO" + name;
         }
         return keyword;
     }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java?rev=1554584&r1=1554583&r2=1554584&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
[UTF-8] Tue Dec 31 22:31:29 2013
@@ -66,7 +66,7 @@ import static java.lang.Character.*;
  * {@section Handling of null values}
  * Most methods in this class accept a {@code null} {@code CharSequence} argument. In such
cases
  * the method return value is either a {@code null} {@code CharSequence}, an empty array,
or a
- * {@code int} primitive type calculated as if the input was an empty string.
+ * {@code 0} or {@code false} primitive type calculated as if the input was an empty string.
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.00)
@@ -119,11 +119,12 @@ public final class CharSequences extends
     /**
      * Returns a character sequence of the specified length filled with white spaces.
      *
-     * <p>This method is typically used for performing right-alignment of text on the
+     * {@section Use case}
+     * This method is typically invoked for performing right-alignment of text on the
      * {@linkplain java.io.Console console} or other device using monospaced font.
-     * The {@code length} argument is then calculated by (<var>desired width</var>
-
-     * <var>used width</var>). Since the used width may be greater than expected,
-     * this method accepts negative {@code length} values as if they were zero.</p>
+     * Callers compute a value for the {@code length} argument by (<var>desired width</var>
- <var>used width</var>).
+     * Since the <var>used width</var> value may be greater than expected, this
method handle negative {@code length}
+     * values as if the value was zero.
      *
      * @param  length The string length. Negative values are clamped to 0.
      * @return A string of length {@code length} filled with white spaces.
@@ -314,15 +315,17 @@ public final class CharSequences extends
      * @param  toSearch  The substring for which to search.
      * @param  fromIndex The index from which to start the search.
      * @param  toIndex   The index after the last character where to perform the search.
-     * @return The index within the text of the first occurrence of the specified part,
-     *         starting at the specified index, or -1 if none.
-     * @throws NullPointerException if any of the arguments is null.
+     * @return The index within the text of the first occurrence of the specified part, starting
at the specified
+     *         index, or -1 if no occurrence has been found or if the {@code text} argument
is null.
+     * @throws NullArgumentException If the {@code toSearch} argument is null.
+     * @throws IllegalArgumentException If the {@code toSearch} argument is empty.
      *
      * @see String#indexOf(String, int)
      * @see StringBuilder#indexOf(String, int)
      * @see StringBuffer#indexOf(String, int)
      */
     public static int indexOf(final CharSequence text, final CharSequence toSearch, int fromIndex,
int toIndex) {
+        ArgumentChecks.ensureNonEmpty("toSearch", toSearch);
         if (text != null) {
             int length = text.length();
             if (toIndex > length) {
@@ -550,6 +553,7 @@ search:     for (; fromIndex <= toIndex;
      * @param  toIndex   The index after the last character where to perform the search.
      * @return The index within the text of the first occurrence of a non-space character,
starting
      *         at the specified index, or a value equals or greater than {@code toIndex}
if none.
+     * @throws NullPointerException if the {@code text} argument is null.
      *
      * @see #skipTrailingWhitespaces(CharSequence, int, int)
      * @see #trimWhitespaces(CharSequence)
@@ -586,6 +590,7 @@ search:     for (; fromIndex <= toIndex;
      * @param  toIndex   The index after the last character where to perform the search.
      * @return The index within the text of the last occurrence of a non-space character,
starting
      *         at the specified index, or a value equals or lower than {@code fromIndex}
if none.
+     * @throws NullPointerException if the {@code text} argument is null.
      *
      * @see #skipLeadingWhitespaces(CharSequence, int, int)
      * @see #trimWhitespaces(CharSequence)
@@ -1017,17 +1022,19 @@ search:     for (; fromIndex <= toIndex;
      * @param  text  The text from which to remove leading and trailing white spaces.
      * @param  lower Index of the first character to consider for inclusion in the sub-sequence.
      * @param  upper Index after the last character to consider for inclusion in the sub-sequence.
-     * @return A characters sequence with leading and trailing white spaces removed.
-     * @throws NullPointerException If {@code text} is {@code null}.
+     * @return A characters sequence with leading and trailing white spaces removed, or {@code
null}
+     *         if the {@code text} argument is null.
      * @throws IndexOutOfBoundsException If {@code lower} or {@code upper} is out of bounds.
      */
     public static CharSequence trimWhitespaces(CharSequence text, int lower, int upper) {
-        final int length = text.length();
+        final int length = length(text);
         ArgumentChecks.ensureValidIndexRange(length, lower, upper);
-        lower = skipLeadingWhitespaces (text, lower, upper);
-        upper = skipTrailingWhitespaces(text, lower, upper);
-        if (lower != 0 || upper != length) { // Safety in case subSequence doesn't make the
check.
-            text = text.subSequence(lower, upper);
+        if (text != null) {
+            lower = skipLeadingWhitespaces (text, lower, upper);
+            upper = skipTrailingWhitespaces(text, lower, upper);
+            if (lower != 0 || upper != length) { // Safety in case subSequence doesn't make
the check.
+                text = text.subSequence(lower, upper);
+            }
         }
         return text;
     }
@@ -1226,16 +1233,14 @@ searchWordBreak:    while (true) {
      * </ol>
      *
      * {@section Exception to the above rules}
-     * If the given identifier contains only upper-case letters, digits and the {@code '_'}
-     * character, then the identifier is returned "as is" except for the {@code '_'} characters
-     * which are replaced by {@code '-'}. This work well for identifiers like {@code "UTF-8"}
or
-     * {@code "ISO-LATIN-1"} for example.
+     * If the given identifier contains only upper-case letters, digits and the {@code '_'}
character,
+     * then the identifier is returned "as is" except for the {@code '_'} characters which
are replaced by {@code '-'}.
+     * This work well for identifiers like {@code "UTF-8"} or {@code "ISO-LATIN-1"} for instance.
      *
      * <p>Note that those heuristic rules may be modified in future SIS versions,
      * depending on the practical experience gained.</p>
      *
-     * @param  identifier An identifier with no space, words begin with an upper-case character,
-     *         or {@code null}.
+     * @param  identifier An identifier with no space, words begin with an upper-case character,
or {@code null}.
      * @return The identifier with spaces inserted after what looks like words, or {@code
null}
      *         if the given {@code identifier} argument was null.
      */
@@ -1403,25 +1408,26 @@ searchWordBreak:    while (true) {
      * one character from the same word may appear in the acronym, but they must always
      * be the first consecutive characters. The comparison is case-insensitive.
      *
-     * <p><b>Example:</b> given the string {@code "Open Geospatial Consortium"},
the following
-     * strings are recognized as acronyms: {@code "OGC"}, {@code "ogc"}, {@code "O.G.C."},
-     * {@code "OpGeoCon"}.</p>
+     * {@example Given the <code>"Open Geospatial Consortium"</code> words, the
following strings are
+     *           recognized as acronyms: <code>"OGC"</code>, <code>"ogc"</code>,
<code>"O.G.C."</code>,
+     *           <code>"OpGeoCon"</code>.}
      *
-     * @param  acronym A possible acronym of the sequence of words.
-     * @param  words The sequence of words.
+     * If any of the given arguments is {@code null}, this method returns {@code false}.
+     *
+     * @param  acronym A possible acronym of the sequence of words, or {@code null}.
+     * @param  words The sequence of words, or {@code null}.
      * @return {@code true} if the first string is an acronym of the second one.
-     * @throws NullPointerException if any of the arguments is null.
      */
     public static boolean isAcronymForWords(final CharSequence acronym, final CharSequence
words) {
-        final int lgc = words.length();
-        final int lga = acronym.length();
-        int ic=0, ia=0;
-        int ca, cc;
+        final int lga = length(acronym);
+        int ia=0, ca;
         do {
             if (ia >= lga) return false;
             ca = codePointAt(acronym, ia);
             ia += charCount(ca);
         } while (!isLetterOrDigit(ca));
+        final int lgc = length(words);
+        int ic=0, cc;
         do {
             if (ic >= lgc) return false;
             cc = codePointAt(words, ic);
@@ -1513,12 +1519,11 @@ cmp:    while (ia < lga) {
      * Unicode identifier start} and all remaining characters (if any) are
      * {@linkplain Character#isUnicodeIdentifierPart(int) Unicode identifier parts}.
      *
-     * @param  identifier The character sequence to test.
+     * @param  identifier The character sequence to test, or {@code null}.
      * @return {@code true} if the given character sequence is a legal Unicode identifier.
-     * @throws NullPointerException if the argument is null.
      */
     public static boolean isUnicodeIdentifier(final CharSequence identifier) {
-        final int length = identifier.length();
+        final int length = length(identifier);
         if (length == 0) {
             return false;
         }
@@ -1544,7 +1549,6 @@ cmp:    while (ia < lga) {
      *
      * @param  text The character sequence to test.
      * @return {@code true} if every character are upper-case.
-     * @throws NullPointerException if the argument is null.
      *
      * @see String#toUpperCase()
      */



Mime
View raw message