sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1566582 - in /sis/branches/JDK7/core: sis-referencing/src/main/java/org/apache/sis/parameter/ sis-referencing/src/main/java/org/apache/sis/referencing/ sis-utility/src/main/java/org/apache/sis/util/
Date Mon, 10 Feb 2014 11:14:04 GMT
Author: desruisseaux
Date: Mon Feb 10 11:14:04 2014
New Revision: 1566582

URL: http://svn.apache.org/r1566582
Log:
DefaultParameterDescriptor.equals was not comparing 'valueClass'.
Also clarified javadoc.

Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/AbstractParameterDescriptor.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/AbstractIdentifiedObject.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/LenientComparable.java

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/AbstractParameterDescriptor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/AbstractParameterDescriptor.java?rev=1566582&r1=1566581&r2=1566582&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/AbstractParameterDescriptor.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/AbstractParameterDescriptor.java
[UTF-8] Mon Feb 10 11:14:04 2014
@@ -164,12 +164,10 @@ public abstract class AbstractParameterD
 
     /**
      * Compares the specified object with this parameter for equality.
+     * The strictness level is controlled by the second argument.
+     * See {@link AbstractIdentifiedObject#equals(Object, ComparisonMode)} for more information.
      *
-     * @param  object The object to compare to {@code this}.
-     * @param  mode {@link ComparisonMode#STRICT STRICT} for performing a strict comparison,
or
-     *         {@link ComparisonMode#IGNORE_METADATA IGNORE_METADATA} for comparing only
properties
-     *         relevant to transformations.
-     * @return {@code true} if both objects are equal.
+     * @return {@inheritDoc}
      */
     @Override
     public boolean equals(final Object object, final ComparisonMode mode) {

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java?rev=1566582&r1=1566581&r2=1566582&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterDescriptor.java
[UTF-8] Mon Feb 10 11:14:04 2014
@@ -25,7 +25,6 @@ import javax.measure.unit.Unit;
 import org.opengis.util.CodeList;
 import org.opengis.parameter.ParameterValue;
 import org.opengis.parameter.ParameterDescriptor;
-import org.opengis.referencing.IdentifiedObject;
 
 import org.apache.sis.util.Debug;
 import org.apache.sis.util.Classes;
@@ -333,15 +332,24 @@ public class DefaultParameterDescriptor<
 
     /**
      * Compares the specified object with this parameter for equality.
+     * The strictness level is controlled by the second argument.
+     * This method compares the following properties in every cases:
      *
-     * @param  object The object to compare to {@code this}.
-     * @param  mode {@link ComparisonMode#STRICT STRICT} for performing a strict comparison,
or
-     *         {@link ComparisonMode#IGNORE_METADATA IGNORE_METADATA} for comparing only
properties
-     *         relevant to transformations.
-     * @return {@code true} if both objects are equal.
+     * <ul>
+     *   <li>{@link #getName()}</li>
+     *   <li>{@link #getMinimumOccurs()}</li>
+     *   <li>{@link #getMaximumOccurs()}</li>
+     *   <li>{@link #getValueClass()}</li>
+     *   <li>{@link #getDefaultValue()}</li>
+     *   <li>{@link #getUnit()}</li>
+     * </ul>
+     *
+     * All other properties (minimum, maximum and valid values) are compared only
+     * for modes stricter than {@link ComparisonMode#IGNORE_METADATA}.
+     *
+     * @return {@inheritDoc}
      */
     @Override
-    @SuppressWarnings("fallthrough")
     public boolean equals(final Object object, final ComparisonMode mode) {
         if (object == this) {
             return true;
@@ -355,17 +363,17 @@ public class DefaultParameterDescriptor<
                      * except the name. We do not perform this comparison if the user asked
for metadata
                      * comparison, because in such case the names have already been compared
by the super-class.
                      */
-                    final IdentifiedObject that = (IdentifiedObject) object;
-                    if (!isHeuristicMatchForName(that. getName().getCode()) &&
-                        !IdentifiedObjects.isHeuristicMatchForName(that, getName().getCode()))
-                    {
-                        return false;
-                    }
-                    // Fall through
+                    final ParameterDescriptor<?> that = (ParameterDescriptor<?>)
object;
+                    return getValueClass() == that.getValueClass() &&
+                           Objects.deepEquals(getDefaultValue(), that.getDefaultValue())
&&
+                           Objects.equals(getUnit(), that.getUnit()) &&
+                           (isHeuristicMatchForName(that.getName().getCode()) ||
+                            IdentifiedObjects.isHeuristicMatchForName(that, getName().getCode()));
                 }
                 case BY_CONTRACT: {
                     final ParameterDescriptor<?> that = (ParameterDescriptor<?>)
object;
-                    return Objects.    equals(getValidValues(),  that.getValidValues()) 
&&
+                    return                    getValueClass() == that.getValueClass()   
&&
+                           Objects.    equals(getValidValues(),  that.getValidValues()) 
&&
                            Objects.deepEquals(getDefaultValue(), that.getDefaultValue())
&&
                            Objects.    equals(getMinimumValue(), that.getMinimumValue())
&&
                            Objects.    equals(getMaximumValue(), that.getMaximumValue())
&&
@@ -373,7 +381,8 @@ public class DefaultParameterDescriptor<
                 }
                 case STRICT: {
                     final DefaultParameterDescriptor<?> that = (DefaultParameterDescriptor<?>)
object;
-                    return Objects.    equals(this.validValues,  that.validValues)  &&
+                    return                    this.valueClass == that.valueClass    &&
+                           Objects.    equals(this.validValues,  that.validValues)  &&
                            Objects.deepEquals(this.defaultValue, that.defaultValue) &&
                            Objects.    equals(this.minimum,      that.minimum)      &&
                            Objects.    equals(this.maximum,      that.maximum)      &&

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=1566582&r1=1566581&r2=1566582&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] Mon Feb 10 11:14:04 2014
@@ -743,23 +743,28 @@ public class AbstractIdentifiedObject ex
     }
 
     /**
-     * Compares this object with the specified object for equality.
-     * The strictness level is controlled by the second argument:
-     *
-     * <ul>
-     *   <li>If {@code mode} is {@link ComparisonMode#STRICT STRICT}, then this method
verifies if the two
-     *       objects are of the same {@linkplain #getClass() class} and compares all public
properties,
-     *       including SIS-specific (non standard) properties.</li>
-     *   <li>If {@code mode} is {@link ComparisonMode#BY_CONTRACT BY_CONTRACT}, then
this method verifies if the two
-     *       objects implement the same {@linkplain #getInterface() GeoAPI interface} and
compares all properties
-     *       defined by that interface ({@linkplain #getName() name}, {@linkplain #getRemarks()
remarks},
-     *       {@linkplain #getIdentifiers() identifiers}, <i>etc</i>).</li>
-     *   <li>If {@code mode} is {@link ComparisonMode#IGNORE_METADATA IGNORE_METADATA},
-     *       then this method compares only the properties needed for computing transformations.
-     *       In other words, {@code sourceCRS.equals(targetCRS, IGNORE_METADATA)} returns
{@code true}
-     *       if the transformation from {@code sourceCRS} to {@code targetCRS} would be the
-     *       identity transform, no matter what {@link #getName()} said.</li>
-     * </ul>
+     * Compares this object with the given object for equality.
+     * The strictness level is controlled by the second argument,
+     * from stricter to more permissive values:
+     *
+     * <blockquote><table class="compact">
+     *   <tr><td>{@link ComparisonMode#STRICT STRICT} –</td>
+     *        <td>Verifies if the two objects are of the same {@linkplain #getClass()
class}
+     *            and compares all public properties, including SIS-specific (non standard)
properties.</td></tr>
+     *   <tr><td>{@link ComparisonMode#BY_CONTRACT BY_CONTRACT} –</td>
+     *       <td>Verifies if the two objects implement the same {@linkplain #getInterface()
GeoAPI interface}
+     *           and compares all properties defined by that interface: {@linkplain #getName()
name},
+     *           {@linkplain #getRemarks() remarks}, {@linkplain #getIdentifiers() identifiers},
<i>etc</i>.</td></tr>
+     *   <tr><td>{@link ComparisonMode#IGNORE_METADATA IGNORE_METADATA} –</td>
+     *       <td>Compares only the properties needed for computing transformations.
+     *           In other words, {@code sourceCRS.equals(targetCRS, IGNORE_METADATA)} returns
{@code true}
+     *           if the transformation from {@code sourceCRS} to {@code targetCRS} would
be the
+     *           identity transform, no matter what {@link #getName()} said.</td></tr>
+     *   <tr><td>{@link ComparisonMode#APPROXIMATIVE APPROXIMATIVE} –</td>
+     *       <td>Same as {@code IGNORE_METADATA}, with some tolerance threshold on
numerical values.</td></tr>
+     *   <tr><td>{@link ComparisonMode#DEBUG DEBUG} –</td>
+     *        <td>Special mode for figuring out why two objects expected to be equal
are not.</td></tr>
+     * </table></blockquote>
      *
      * {@section Exceptions to the above rules}
      * Some subclasses (especially
@@ -772,9 +777,14 @@ public class AbstractIdentifiedObject ex
      * The name comparison may be lenient however, i.e. the rules may accept a name matching
an alias.
      * See {@link #isHeuristicMatchForName(String)} for more information.
      *
+     * {@section Conformance to the <code>equals(Object)</code> method contract}
+     * {@link ComparisonMode#STRICT} is the only mode compliant with the {@link Object#equals(Object)}
contract.
+     * For all other modes, the comparison is not guaranteed to be <cite>symmetric</cite>
neither
+     * <cite>transitive</cite>. See {@link LenientComparable#equals(Object, ComparisonMode)}
for more information.
+     *
      * @param  object The object to compare to {@code this}.
      * @param  mode The strictness level of the comparison.
-     * @return {@code true} if both objects are equal.
+     * @return {@code true} if both objects are equal according the given comparison mode.
      *
      * @see #computeHashCode()
      * @see org.apache.sis.util.Utilities#deepEquals(Object, Object, ComparisonMode)

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/LenientComparable.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/LenientComparable.java?rev=1566582&r1=1566581&r2=1566582&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/LenientComparable.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/LenientComparable.java
[UTF-8] Mon Feb 10 11:14:04 2014
@@ -108,30 +108,40 @@ public interface LenientComparable {
     /**
      * Compares this object with the given object for equality.
      * The strictness level is controlled by the second argument,
-     * for stricter to more permissive values:
+     * from stricter to more permissive values:
      *
-     * <ol>
-     *   <li>{@link ComparisonMode#STRICT STRICT} –
-     *        All attributes of the compared objects shall be strictly equal.</li>
-     *   <li>{@link ComparisonMode#BY_CONTRACT BY_CONTRACT} –
-     *       Only the attributes published in the interface contract need to be compared.</li>
-     *   <li>{@link ComparisonMode#IGNORE_METADATA IGNORE_METADATA} –
-     *       Only the attributes relevant to the object functionality are compared.</li>
-     *   <li>{@link ComparisonMode#APPROXIMATIVE APPROXIMATIVE} –
-     *       Only the attributes relevant to the object functionality are compared,
-     *       with some tolerance threshold on numerical values.</li>
-     *   <li>{@link ComparisonMode#DEBUG DEBUG} –
-     *        special mode for figuring out why two objects expected to be equal are not.</li>
-     * </ol>
-     *
-     * Note that {@code this.equals(other, mode)} is <strong>not</strong> guaranteed
to be equal
-     * to {@code other.equals(this, mode)}.  In particular, the {@code BY_CONTRACT} level
and all
-     * levels below it will typically compare only the properties known to {@code this} instance,
-     * ignoring any properties that may be known only by the {@code other} instance.
+     * <blockquote><table class="compact">
+     *   <tr><td>{@link ComparisonMode#STRICT STRICT} –</td>
+     *        <td>All attributes of the compared objects shall be strictly equal.</td></tr>
+     *   <tr><td>{@link ComparisonMode#BY_CONTRACT BY_CONTRACT} –</td>
+     *       <td>Only the attributes published in the interface contract need to be
compared.</td></tr>
+     *   <tr><td>{@link ComparisonMode#IGNORE_METADATA IGNORE_METADATA} –</td>
+     *       <td>Only the attributes relevant to the object functionality are compared.</td></tr>
+     *   <tr><td>{@link ComparisonMode#APPROXIMATIVE APPROXIMATIVE} –</td>
+     *       <td>Only the attributes relevant to the object functionality are compared,
+     *           with some tolerance threshold on numerical values.</td></tr>
+     *   <tr><td>{@link ComparisonMode#DEBUG DEBUG} –</td>
+     *        <td>Special mode for figuring out why two objects expected to be equal
are not.</td></tr>
+     * </table></blockquote>
+     *
+     * {@section Conformance to the <code>equals(Object)</code> method contract}
+     * {@link ComparisonMode#STRICT} is the only mode compliant with the {@link Object#equals(Object)}
contract.
+     * For all other modes, the comparison is not guaranteed to be <cite>symmetric</cite>
neither
+     * <cite>transitive</cite>:
+     *
+     * <ul>
+     *   <li>{@code x.equals(y, mode)} is <strong>not</strong> guaranteed
to be equal to {@code y.equals(x, mode)}.
+     *       In particular, the {@code BY_CONTRACT} mode and all modes below it will typically
compare only the
+     *       properties known to {@code this} instance, ignoring any properties that may
be known only by the other
+     *       instance.</li>
+     *   <li>{@code x.equals(y, mode)} and {@code y.equals(z, mode)} does <strong>not</strong>
implies
+     *       {@code x.equals(z, mode)}. In particular, the use of a comparison threshold
for the
+     *       {@code APPROXIMATIVE} mode is incompatible with the transitivity contract.</li>
+     * </ul>
      *
      * @param  other The object to compare to {@code this}.
      * @param  mode The strictness level of the comparison.
-     * @return {@code true} if both objects are equal.
+     * @return {@code true} if both objects are equal according the given comparison mode.
      *
      * @see Utilities#deepEquals(Object, Object, ComparisonMode)
      */



Mime
View raw message