You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2013/11/26 03:55:03 UTC
svn commit: r1545518 - in /sis/branches/JDK7/core:
sis-metadata/src/main/java/org/apache/sis/metadata/iso/
sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/
sis-referencing/src/main/java/org/apache/sis/referencing/
sis-referencing/src/ma...
Author: desruisseaux
Date: Tue Nov 26 02:55:03 2013
New Revision: 1545518
URL: http://svn.apache.org/r1545518
Log:
Consolidation of IdentifiedObject.nameMatches specification.
Added:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/IdentifiedObjectsTest.java (with props)
Modified:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/Citations.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.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/NamedIdentifier.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultAffineCS.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Citations.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/CharSequences.java
sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/IdentifiedObjectMock.java
sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java
Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java?rev=1545518&r1=1545517&r2=1545518&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java [UTF-8] Tue Nov 26 02:55:03 2013
@@ -37,6 +37,7 @@ import org.apache.sis.internal.jaxb.gco.
import org.apache.sis.internal.simple.SimpleIdentifiedObject;
import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
+import static org.apache.sis.util.CharSequences.trimWhitespaces;
import static org.apache.sis.util.collection.Containers.property;
import static org.opengis.referencing.IdentifiedObject.REMARKS_KEY;
@@ -246,8 +247,8 @@ public class ImmutableIdentifier impleme
*/
public ImmutableIdentifier(final Map<String,?> properties) throws IllegalArgumentException {
ensureNonNull("properties", properties);
- code = property(properties, CODE_KEY, String.class);
- version = property(properties, VERSION_KEY, String.class);
+ code = trimWhitespaces(property(properties, CODE_KEY, String.class));
+ version = trimWhitespaces(property(properties, VERSION_KEY, String.class));
remarks = Types.toInternationalString(properties, REMARKS_KEY);
/*
* Map String authority to one of the pre-defined constants (typically EPSG or OGC).
@@ -270,7 +271,7 @@ public class ImmutableIdentifier impleme
if (value == null && !properties.containsKey(CODESPACE_KEY)) {
codeSpace = getCodeSpace(authority);
} else if (value instanceof String) {
- codeSpace = (String) value;
+ codeSpace = trimWhitespaces((String) value);
} else {
throw illegalPropertyType(CODESPACE_KEY, value);
}
@@ -358,7 +359,7 @@ public class ImmutableIdentifier impleme
* @see Citations#getIdentifier(Citation)
*/
private static String getCodeSpace(final Citation authority) {
- final String codeSpace = Citations.getIdentifier(authority);
+ final String codeSpace = Citations.getIdentifier(authority); // Whitespaces trimed by Citations.
if (codeSpace != null) {
final int length = codeSpace.length();
if (length != 0) {
@@ -468,9 +469,8 @@ public class ImmutableIdentifier impleme
* Returns a string representation of this identifier.
* The default implementation returns a pseudo-WKT format.
*
- * {@note The <code>NamedIdentifier</code> subclass overrides this method with a different
- * behavior, in order to be compliant with the contract of the <code>GenericName</code>
- * interface.}
+ * {@note The <code>NamedIdentifier</code> subclass overrides this method with a different behavior,
+ * in order to be compliant with the contract of the <code>GenericName</code> interface.}
*
* @see org.apache.sis.referencing.IdentifiedObjects#toString(Identifier)
* @see org.apache.sis.referencing.NamedIdentifier#toString()
Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/Citations.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/Citations.java?rev=1545518&r1=1545517&r2=1545518&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/Citations.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/citation/Citations.java [UTF-8] Tue Nov 26 02:55:03 2013
@@ -187,8 +187,7 @@ public final class Citations extends Sta
if (title == null || ((title = CharSequences.trimWhitespaces(title)).isEmpty())) {
return null;
}
- for (int i=0; i<AUTHORITIES.length; i++) {
- final Citation citation = AUTHORITIES[i];
+ for (final Citation citation : AUTHORITIES) {
if (titleMatches(citation, title)) {
return citation;
}
@@ -289,12 +288,15 @@ public final class Citations extends Sta
* <li>Otherwise this method returns {@code null}.</li>
* </ul>
*
- * This method searches in alternate titles as a fallback because ISO specification said
- * that those titles are often used for abbreviations.
+ * {@note This method searches in alternate titles as a fallback because ISO specification said
+ * that those titles are often used for abbreviations.}
+ *
+ * This method ignores leading and trailing whitespaces of every character sequences.
+ * Null references, empty character sequences and sequences of whitespaces only are ignored.
*
* @param citation The citation for which to get the identifier, or {@code null}.
- * @return An identifier for the given citation, or {@code null} if the given citation is null
- * or does not declare any identifier or title.
+ * @return A non-empty identifier for the given citation without leading or trailing whitespaces,
+ * or {@code null} if the given citation is null or does not declare any identifier or title.
*/
public static String getIdentifier(final Citation citation) {
return org.apache.sis.internal.util.Citations.getIdentifier(citation);
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java?rev=1545518&r1=1545517&r2=1545518&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java [UTF-8] Tue Nov 26 02:55:03 2013
@@ -479,15 +479,44 @@ public class AbstractIdentifiedObject ex
/**
* Returns {@code true} if either the {@linkplain #getName() primary name} or at least
- * one {@linkplain #getAlias() alias} matches the specified string.
- * This method returns {@code true} if the given name is equal to one of the following names,
- * regardless of any authority:
+ * one {@linkplain #getAlias() alias} "ends" with the specified string. More specifically
+ * this method returns {@code true} if the given {@code name} is equal, ignoring aspects
+ * documented below, to one of the following names:
*
* <ul>
- * <li>The {@linkplain #getName() primary name} of this object.</li>
- * <li>The {@linkplain org.opengis.util.GenericName#toFullyQualifiedName() fully qualified name} of an alias.</li>
- * <li>The {@linkplain org.opengis.util.ScopedName#tail() tail} of an alias.</li>
- * <li>The tail of the previous tail, recursively up to the {@linkplain org.opengis.util.ScopedName#tip() tip}.</li>
+ * <li>The {@linkplain #getName() primary name}'s {@linkplain NamedIdentifier#getCode() code}
+ * (ignoring {@linkplain NamedIdentifier#getCodeSpace() codespace}).</li>
+ * <li>Any {@linkplain #getAlias() alias}'s {@linkplain NamedIdentifier#tip() tip}
+ * (ignoring {@linkplain NamedIdentifier#scope() scope} and namespace).</li>
+ * </ul>
+ *
+ * The comparison ignores the following aspects:
+ * <ul>
+ * <li>Lower/Upper cases</li>
+ * <li>Some Latin diacritical signs (e.g. {@code "Réunion"} and {@code "Reunion"} are considered equal).</li>
+ * <li>All characters that are not {@linkplain Character#isLetterOrDigit(int) letters or digits}
+ * (e.g. {@code "Mercator (1SP)"} and {@code "Mercator_1SP"} are considered equal).</li>
+ * </ul>
+ *
+ * {@section Usage}
+ * This method is invoked by SIS when comparing in {@code IGNORE_METADATA} mode two objects that can be
+ * differentiated only by their name, like coordinate system axes, datum, parameters and operation methods.
+ * See {@link #equals(Object, ComparisonMode)} for more information.
+ *
+ * <p>This method is also invoked when searching a parameter or operation method for a given name.
+ * For example the same projection is known as {@code "Mercator (variant A)"} (the primary name according EPSG)
+ * and {@code "Mercator (1SP)"} (the legacy name prior EPSG 7.6). Since the later is still in frequent use, SIS
+ * accepts it as an alias of the <cite>Mercator (variant A)</cite> projection.</p>
+ *
+ * {@section Overriding by subclasses}
+ * Some subclasses relax further the comparison criterion:
+ * <ul>
+ * <li>{@linkplain org.apache.sis.referencing.cs.DefaultCoordinateSystemAxis#nameMatches(String) Comparisons
+ * of coordinate system axis names} consider “Lat”, “Latitude” and “Geodetic latitude” as synonymous, and
+ * likewise for longitude.</li>
+ * <li>{@linkplain org.apache.sis.referencing.datum.DefaultGeodeticDatum#nameMatches(String) Comparisons
+ * of geodetic datum} ignore the {@code "D_"} prefix, if any. This prefix appears in ESRI datum name
+ * (e.g. {@code "D_WGS_1984"}).</li>
* </ul>
*
* @param name The name to compare with the object name or aliases.
@@ -515,12 +544,15 @@ public class AbstractIdentifiedObject ex
* </ul>
*
* {@section Exceptions to the above rules}
- * Some subclasses (especially {@link org.apache.sis.referencing.datum.AbstractDatum}
- * and {@link org.apache.sis.parameter.AbstractParameterDescriptor}) will test for the
- * {@linkplain #getName() name}, since objects with different name have completely
- * different meaning. For example nothing differentiate the {@code "semi_major"} and
- * {@code "semi_minor"} parameters except the name. The name comparison may be loose
- * however, i.e. we may accept a name matching an alias.
+ * Some subclasses (especially
+ * {@link org.apache.sis.referencing.cs.DefaultCoordinateSystemAxis},
+ * {@link org.apache.sis.referencing.datum.AbstractDatum} and
+ * {@link org.apache.sis.parameter.AbstractParameterDescriptor}) will compare the
+ * {@linkplain #getName() name} even in {@code IGNORE_METADATA} mode,
+ * because objects of those types with different names have completely different meaning.
+ * For example nothing differentiate the {@code "semi_major"} and {@code "semi_minor"} parameters except the name.
+ * The name comparison may be lenient however, i.e. the rules may accept a name matching an alias.
+ * See {@link #nameMatches(String)} for more information.
*
* @param object The object to compare to {@code this}.
* @param mode {@link ComparisonMode#STRICT STRICT} for performing a strict comparison, or
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=1545518&r1=1545517&r2=1545518&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 Nov 26 02:55:03 2013
@@ -23,7 +23,6 @@ import java.util.Iterator;
import java.util.Collection;
import org.opengis.util.NameSpace;
-import org.opengis.util.ScopedName;
import org.opengis.util.GenericName;
import org.opengis.metadata.Identifier;
import org.opengis.metadata.citation.Citation;
@@ -35,7 +34,8 @@ import org.apache.sis.util.iso.DefaultNa
import org.apache.sis.metadata.iso.citation.Citations;
import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
-import static org.apache.sis.util.CharSequences.trimWhitespaces;
+import static org.apache.sis.util.CharSequences.equalsFiltered;
+import static org.apache.sis.util.Characters.Filter.LETTERS_AND_DIGITS;
import static org.apache.sis.internal.util.Citations.iterator;
import static org.apache.sis.internal.util.Citations.identifierMatches;
@@ -288,16 +288,24 @@ public final class IdentifiedObjects ext
}
/**
- * Returns {@code true} if either the {@linkplain IdentifiedObject#getName() primary name} or
- * at least one {@linkplain IdentifiedObject#getAlias() alias} matches the specified string.
- * This method returns {@code true} if the given name is equal to one of the following names,
- * regardless of any authority:
+ * Returns {@code true} if either the {@linkplain AbstractIdentifiedObject#getName() primary name} or
+ * at least one {@linkplain AbstractIdentifiedObject#getAlias() alias} "ends" with the specified string.
+ * More specifically this method returns {@code true} if the given {@code name} is equal,
+ * ignoring aspects documented below, to one of the following names:
*
* <ul>
- * <li>The {@linkplain IdentifiedObject#getName() primary name} of the object.</li>
- * <li>The {@linkplain GenericName#toFullyQualifiedName() fully qualified name} of an alias.</li>
- * <li>The {@linkplain ScopedName#tail() tail} of an alias.</li>
- * <li>The tail of the previous tail, recursively up to the {@linkplain ScopedName#tip() tip}.</li>
+ * <li>The {@linkplain AbstractIdentifiedObject#getName() primary name}'s {@linkplain NamedIdentifier#getCode() code}
+ * (ignoring {@linkplain NamedIdentifier#getCodeSpace() codespace}).</li>
+ * <li>Any {@linkplain AbstractIdentifiedObject#getAlias() alias}'s {@linkplain NamedIdentifier#tip() tip}
+ * (ignoring {@linkplain NamedIdentifier#scope() scope} and namespace).</li>
+ * </ul>
+ *
+ * The comparison ignores the following aspects:
+ * <ul>
+ * <li>Lower/Upper cases</li>
+ * <li>Some Latin diacritical signs (e.g. {@code "Réunion"} and {@code "Reunion"} are considered equal).</li>
+ * <li>All characters that are not {@linkplain Character#isLetterOrDigit(int) letters or digits}
+ * (e.g. {@code "Mercator (1SP)"} and {@code "Mercator_1SP"} are considered equal).</li>
* </ul>
*
* If the given object is an instance of {@link AbstractIdentifiedObject}, then this method delegates
@@ -321,24 +329,9 @@ public final class IdentifiedObjects ext
}
/**
- * Returns {@code true} if the {@linkplain IdentifiedObject#getName() primary name} of an
- * object matches the primary name or one {@linkplain IdentifiedObject#getAlias() alias}
- * of the other object.
- *
- * @param o1 The first object to compare by name.
- * @param o2 The second object to compare by name.
- * @return {@code true} if both objects have a common name.
- */
- public static boolean nameMatches(final IdentifiedObject o1, final IdentifiedObject o2) {
- ensureNonNull("o1", o1);
- ensureNonNull("o2", o2);
- return nameMatches(o1, o2.getName().getCode()) ||
- nameMatches(o2, o1.getName().getCode());
- }
-
- /**
- * Returns {@code true} if the {@linkplain #getName() primary name} of the given object
- * or one of the given alias matches the given name.
+ * Returns {@code true} if the {@linkplain AbstractIdentifiedObject#getName() primary name} of the given object
+ * or one of the given alias matches the given name. The comparison ignores case, Some Latin diacritical signs
+ * and any characters that are not letters or digits.
*
* @param object The object to check.
* @param alias The list of alias in {@code object} (may be {@code null}).
@@ -347,23 +340,22 @@ public final class IdentifiedObjects ext
* @param name The name for which to check for equality.
* @return {@code true} if the primary name or at least one alias matches the given {@code name}.
*/
- static boolean nameMatches(final IdentifiedObject object, final Collection<GenericName> alias, String name) {
- name = trimWhitespaces(name);
- if (name.equalsIgnoreCase(trimWhitespaces(object.getName().getCode()))) {
- return true;
+ static boolean nameMatches(final IdentifiedObject object, final Collection<GenericName> alias, final String name) {
+ final ReferenceIdentifier id = object.getName();
+ if (id != null) { // Paranoiac check.
+ final String code = id.getCode();
+ if (code != null) { // Paranoiac check.
+ if (equalsFiltered(name, code, LETTERS_AND_DIGITS, true)) {
+ return true;
+ }
+ }
}
if (alias != null) {
for (GenericName asName : alias) {
if (asName != null) { // Paranoiac check.
- asName = asName.toFullyQualifiedName();
- while (asName != null) {
- if (name.equalsIgnoreCase(trimWhitespaces(asName.toString()))) {
- return true;
- }
- if (!(asName instanceof ScopedName)) {
- break;
- }
- asName = ((ScopedName) asName).tail();
+ asName = asName.tip();
+ if (equalsFiltered(name, asName.toString(), LETTERS_AND_DIGITS, true)) {
+ return true;
}
}
}
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/NamedIdentifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/NamedIdentifier.java?rev=1545518&r1=1545517&r2=1545518&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/NamedIdentifier.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/NamedIdentifier.java [UTF-8] Tue Nov 26 02:55:03 2013
@@ -186,12 +186,12 @@ public class NamedIdentifier extends Imm
if (authority == null) {
return factory.createLocalName(null, code);
}
- final CharSequence title;
+ final String title;
final String codeSpace = super.getCodeSpace();
if (codeSpace != null) {
- title = codeSpace;
+ title = codeSpace; // Whitespaces trimed by constructor.
} else {
- title = Citations.getIdentifier(authority);
+ title = Citations.getIdentifier(authority); // Whitespaces trimed by Citations.
}
NameSpace scope;
synchronized (SCOPES) {
@@ -309,6 +309,8 @@ public class NamedIdentifier extends Imm
* is local-independent. It contains all elements listed by {@link #getParsedNames()}
* separated by an arbitrary character (usually {@code :} or {@code /}).
*
+ * @return A local-independent string representation of this generic name.
+ *
* @see IdentifiedObjects#toString(Identifier)
*/
@Override
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultAffineCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultAffineCS.java?rev=1545518&r1=1545517&r2=1545518&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultAffineCS.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultAffineCS.java [UTF-8] Tue Nov 26 02:55:03 2013
@@ -33,14 +33,14 @@ import org.apache.sis.util.ComparisonMod
* A 2- or 3-dimensional coordinate system with straight axes that are not necessarily orthogonal.
*
* <table class="sis"><tr>
- * <th>Used with CRS types</th>
+ * <th>Used with</th>
* <th>Permitted axis names</th>
* </tr><tr>
- * <td>{@linkplain org.geotoolkit.referencing.crs.DefaultEngineeringCRS Engineering}</td>
- * <td>(unspecified)</td>
+ * <td>{@linkplain org.geotoolkit.referencing.crs.DefaultEngineeringCRS Engineering CRS}</td>
+ * <td>unspecified</td>
* </tr><tr>
- * <td>{@linkplain org.geotoolkit.referencing.crs.DefaultImageCRS Image}</td>
- * <td>(unspecified)</td>
+ * <td>{@linkplain org.geotoolkit.referencing.crs.DefaultImageCRS Image CRS}</td>
+ * <td>unspecified</td>
* </tr></table>
*
* @author Martin Desruisseaux (IRD, Geomatys)
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java?rev=1545518&r1=1545517&r2=1545518&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java [UTF-8] Tue Nov 26 02:55:03 2013
@@ -33,20 +33,20 @@ import org.apache.sis.util.Immutable;
* same linear unit of measure.
*
* <table class="sis"><tr>
- * <th>Used with CRS types</th>
+ * <th>Used with</th>
* <th>Permitted axis names</th>
* </tr><tr>
- * <td>{@linkplain org.geotoolkit.referencing.crs.DefaultGeocentricCRS Geocentric}</td>
+ * <td>{@linkplain org.geotoolkit.referencing.crs.DefaultGeocentricCRS Geocentric CRS}</td>
* <td>“Geocentric X”, “Geocentric Y”, “Geocentric Z”</td>
* </tr><tr>
- * <td>{@linkplain org.geotoolkit.referencing.crs.DefaultProjectedCRS Projected}</td>
+ * <td>{@linkplain org.geotoolkit.referencing.crs.DefaultProjectedCRS Projected CRS}</td>
* <td>“Easting” or “Westing”, “Northing” or “Southing”</td>
* </tr><tr>
- * <td>{@linkplain org.geotoolkit.referencing.crs.DefaultEngineeringCRS Engineering}</td>
- * <td>(unspecified)</td>
+ * <td>{@linkplain org.geotoolkit.referencing.crs.DefaultEngineeringCRS Engineering CRS}</td>
+ * <td>unspecified</td>
* </tr><tr>
- * <td>{@linkplain org.geotoolkit.referencing.crs.DefaultImageCRS Image}</td>
- * <td>(unspecified)</td>
+ * <td>{@linkplain org.geotoolkit.referencing.crs.DefaultImageCRS Image CRS}</td>
+ * <td>unspecified</td>
* </tr></table>
*
* @author Martin Desruisseaux (IRD, Geomatys)
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java?rev=1545518&r1=1545517&r2=1545518&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCoordinateSystemAxis.java [UTF-8] Tue Nov 26 02:55:03 2013
@@ -18,6 +18,7 @@ package org.apache.sis.referencing.cs;
import java.util.Map;
import java.util.HashMap;
+import java.util.Locale;
import javax.measure.unit.Unit;
import javax.measure.unit.NonSI;
import javax.measure.quantity.Angle;
@@ -50,7 +51,7 @@ import java.util.Objects;
/**
- * Definition of a coordinate system axis. This is used to label axes and indicate their orientation.
+ * Coordinate system axis name, direction, unit and range of values.
*
* {@section Axis names}
* In some case, the axis name is constrained by ISO 19111 depending on the
@@ -407,8 +408,8 @@ public class DefaultCoordinateSystemAxis
* generic. We test them only in the 'equals' method, which has the extra-safety
* of units comparison (so less risk to treat incompatible axes as equivalent).
*/
- final Object type = ALIASES.get(trimWhitespaces(name).toLowerCase());
- return (type != null) && (type == ALIASES.get(trimWhitespaces(getName().getCode()).toLowerCase()));
+ final Object type = ALIASES.get(trimWhitespaces(name).toLowerCase(Locale.US)); // Our ALIASES are in English.
+ return (type != null) && (type == ALIASES.get(trimWhitespaces(getName().getCode()).toLowerCase(Locale.US)));
}
/**
@@ -500,8 +501,9 @@ public class DefaultCoordinateSystemAxis
if (!nameMatches(thatName)) {
/*
* The above test checked for special cases ("Lat" / "Lon" aliases, etc.).
- * The next line may not, but is tested anyway in case the user overridden
- * the 'that.nameMatches(...)' method.
+ * The next line may repeat the same check, so we may have a partial waste
+ * of CPU. But we do it anyway for checking the 'that' aliases, and also
+ * because the user may have overridden the 'that.nameMatches(...)' method.
*/
final String thisName = getName().getCode();
if (!IdentifiedObjects.nameMatches(that, thisName)) {
Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java?rev=1545518&r1=1545517&r2=1545518&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/AbstractIdentifiedObjectTest.java [UTF-8] Tue Nov 26 02:55:03 2013
@@ -37,7 +37,7 @@ import static org.apache.sis.metadata.is
* @version 0.4
* @module
*/
-@DependsOn(NamedIdentifierTest.class)
+@DependsOn({IdentifiedObjectsTest.class, NamedIdentifierTest.class})
public final strictfp class AbstractIdentifiedObjectTest extends TestCase {
/**
* Tests the {@link AbstractIdentifiedObject#AbstractIdentifiedObject(Map)} constructor.
Added: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/IdentifiedObjectsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/IdentifiedObjectsTest.java?rev=1545518&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/IdentifiedObjectsTest.java (added)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/IdentifiedObjectsTest.java [UTF-8] Tue Nov 26 02:55:03 2013
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.referencing;
+
+import org.opengis.util.GenericName;
+import org.opengis.referencing.IdentifiedObject;
+import org.apache.sis.internal.system.DefaultFactories;
+import org.apache.sis.test.mock.IdentifiedObjectMock;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link IdentifiedObjects}.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.4
+ * @version 0.4
+ * @module
+ */
+public final strictfp class IdentifiedObjectsTest extends TestCase {
+ /**
+ * Tests {@link IdentifiedObjects#nameMatches(IdentifiedObject, IdentifiedObject)}.
+ */
+ @Test
+ public void testNameMatches() {
+ final GenericName name = DefaultFactories.SIS_NAMES.createGenericName(null, "myScope", "myName");
+ final IdentifiedObjectMock object = new IdentifiedObjectMock("myCode ", name); // Intentional trailing space.
+
+ // Test the code.
+ assertFalse(IdentifiedObjects.nameMatches(object, "other"));
+ assertTrue (IdentifiedObjects.nameMatches(object, "myCode"));
+ assertTrue (IdentifiedObjects.nameMatches(object, " my_code "));
+ assertFalse(IdentifiedObjects.nameMatches(object, "testmyCode"));
+ assertFalse(IdentifiedObjects.nameMatches(object, "other:myCode"));
+ assertFalse(IdentifiedObjects.nameMatches(object, "test"));
+
+ // Test the alias.
+ assertTrue (IdentifiedObjects.nameMatches(object, "myName"));
+ assertTrue (IdentifiedObjects.nameMatches(object, " My_name "));
+ assertFalse(IdentifiedObjects.nameMatches(object, "myScope"));
+ assertFalse(IdentifiedObjects.nameMatches(object, "other:myName"));
+ assertFalse(IdentifiedObjects.nameMatches(object, "myScope:other"));
+ assertFalse(IdentifiedObjects.nameMatches(object, "other:myScope:myName"));
+ }
+}
Propchange: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/IdentifiedObjectsTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/IdentifiedObjectsTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1545518&r1=1545517&r2=1545518&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java [UTF-8] Tue Nov 26 02:55:03 2013
@@ -47,6 +47,7 @@ import org.junit.BeforeClass;
org.apache.sis.io.wkt.ConventionTest.class,
org.apache.sis.io.wkt.SymbolsTest.class,
org.apache.sis.io.wkt.FormatterTest.class,
+ org.apache.sis.referencing.IdentifiedObjectsTest.class,
org.apache.sis.referencing.NamedIdentifierTest.class,
org.apache.sis.referencing.AbstractIdentifiedObjectTest.class,
org.apache.sis.referencing.AbstractReferenceSystemTest.class,
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Citations.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Citations.java?rev=1545518&r1=1545517&r2=1545518&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Citations.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/util/Citations.java [UTF-8] Tue Nov 26 02:55:03 2013
@@ -257,12 +257,15 @@ public final class Citations extends Sta
* <li>Otherwise this method returns {@code null}.</li>
* </ul>
*
- * This method searches in alternate titles as a fallback because ISO specification said
- * that those titles are often used for abbreviations.
+ * {@note This method searches in alternate titles as a fallback because ISO specification said
+ * that those titles are often used for abbreviations.}
+ *
+ * This method ignores leading and trailing whitespaces of every character sequences.
+ * Null references, empty character sequences and sequences of whitespaces only are ignored.
*
* @param citation The citation for which to get the identifier, or {@code null}.
- * @return An identifier for the given citation, or {@code null} if the given citation is null
- * or does not declare any identifier or title.
+ * @return A non-empty identifier for the given citation without leading or trailing whitespaces,
+ * or {@code null} if the given citation is null or does not declare any identifier or title.
*/
public static String getIdentifier(final Citation citation) {
boolean isUnicode = false; // Whether 'identifier' is a Unicode identifier.
@@ -291,7 +294,7 @@ public final class Citations extends Sta
* often used for abbreviations.
*/
if (identifier == null) {
- identifier = toString(citation.getTitle());
+ identifier = toString(citation.getTitle()); // Whitepaces removed by toString(…).
if (identifier != null) {
if (identifier.isEmpty()) {
identifier = null;
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=1545518&r1=1545517&r2=1545518&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 Nov 26 02:55:03 2013
@@ -1573,8 +1573,8 @@ cmp: while (ia < lga) {
* assert equalsFiltered("WGS84", "WGS_84", Characters.Filter.LETTERS_AND_DIGITS, true) == true;
* }
*
- * @param s1 The first string to compare, or {@code null}.
- * @param s2 The second string to compare, or {@code null}.
+ * @param s1 The first characters sequence to compare, or {@code null}.
+ * @param s2 The second characters sequence to compare, or {@code null}.
* @param filter The subset of characters to compare, or {@code null} for comparing all characters.
* @param ignoreCase {@code true} for comparing cases, or {@code false} for requiring exact match.
* @return {@code true} if or if both arguments are {@code null} or if the two given texts are equal,
@@ -1594,10 +1594,10 @@ cmp: while (ia < lga) {
}
final int lg1 = s1.length();
final int lg2 = s2.length();
- int i2 = 0, n;
- for (int i1=0; i1<lg1; i1+=n) {
+ int i1 = 0, i2 = 0;
+ while (i1 < lg1) {
int c1 = codePointAt(s1, i1);
- n = charCount(c1);
+ final int n = charCount(c1);
if (filter.contains(c1)) {
// Fetch the next significant character from the second string.
int c2;
@@ -1614,6 +1614,7 @@ cmp: while (ia < lga) {
return false;
}
}
+ i1 += n;
}
while (i2 < lg2) {
final int s = codePointAt(s2, i2);
Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/IdentifiedObjectMock.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/IdentifiedObjectMock.java?rev=1545518&r1=1545517&r2=1545518&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/IdentifiedObjectMock.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/IdentifiedObjectMock.java [UTF-8] Tue Nov 26 02:55:03 2013
@@ -86,9 +86,11 @@ public strictfp class IdentifiedObjectMo
* Creates an identified object of the given alias.
* Callers are free to assign new value to the {@link #alias} field directly.
*
- * @param alias The initial {@link #alias} value (can be {@code null}).
+ * @param code The initial {@link #getCode()} value, or {@code null} if none.
+ * @param alias The initial {@link #alias} value, or {@code null} if none.
*/
- public IdentifiedObjectMock(final GenericName alias) {
+ public IdentifiedObjectMock(final String code, final GenericName alias) {
+ this.code = code;
this.alias = alias;
}
Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java?rev=1545518&r1=1545517&r2=1545518&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java [UTF-8] Tue Nov 26 02:55:03 2013
@@ -63,7 +63,7 @@ public final strictfp class NameMarshall
pool = new MarshallerPool(JAXBContext.newInstance(IdentifiedObjectMock.class), null);
}
final Marshaller marshaller = pool.acquireMarshaller();
- final String xml = marshal(marshaller, new IdentifiedObjectMock(name));
+ final String xml = marshal(marshaller, new IdentifiedObjectMock(null, name));
pool.recycle(marshaller);
return xml;
}