sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1626012 - in /sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter: DefaultParameterValue.java DefaultParameterValueGroup.java
Date Thu, 18 Sep 2014 15:56:18 GMT
Author: desruisseaux
Date: Thu Sep 18 15:56:18 2014
New Revision: 1626012

URL: http://svn.apache.org/r1626012
Log:
ParameterValueGroup implements LenientComparable.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java?rev=1626012&r1=1626011&r2=1626012&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
[UTF-8] Thu Sep 18 15:56:18 2014
@@ -36,9 +36,12 @@ import org.apache.sis.io.wkt.ElementKind
 import org.apache.sis.internal.referencing.WKTUtilities;
 import org.apache.sis.internal.util.Numerics;
 import org.apache.sis.util.Numbers;
+import org.apache.sis.util.ComparisonMode;
+import org.apache.sis.util.LenientComparable;
 import org.apache.sis.util.resources.Errors;
 
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
+import static org.apache.sis.util.Utilities.deepEquals;
 
 // Branch-dependent imports
 import java.util.Objects;
@@ -110,7 +113,9 @@ import java.nio.file.Path;
  * @see DefaultParameterDescriptor
  * @see DefaultParameterValueGroup
  */
-public class DefaultParameterValue<T> extends FormattableObject implements ParameterValue<T>,
Serializable, Cloneable {
+public class DefaultParameterValue<T> extends FormattableObject implements ParameterValue<T>,
+        LenientComparable, Serializable, Cloneable
+{
     /**
      * Serial number for inter-operability with different versions.
      */
@@ -228,7 +233,7 @@ public class DefaultParameterValue<T> ex
     public boolean booleanValue() throws IllegalStateException {
         final T value = getValue();
         if (value instanceof Boolean) {
-            return ((Boolean) value).booleanValue();
+            return (Boolean) value;
         }
         throw incompatibleValue(value);
     }
@@ -680,26 +685,55 @@ public class DefaultParameterValue<T> ex
 
     /**
      * Compares the specified object with this parameter for equality.
+     * The strictness level is controlled by the second argument.
      *
      * @param  object The object to compare to {@code this}.
-     * @return {@code true} if both objects are equal.
+     * @param  mode The strictness level of the comparison.
+     * @return {@code true} if both objects are equal according the given comparison mode.
      */
     @Override
-    public boolean equals(final Object object) {
+    public boolean equals(final Object object, final ComparisonMode mode) {
         if (object == this) {
             // Slight optimization
             return true;
         }
-        if (object != null && getClass() == object.getClass()) {
-            final DefaultParameterValue<?> that = (DefaultParameterValue<?>)
object;
-            return Objects.equals(descriptor, that.descriptor) &&
-                   Objects.equals(value,      that.value) &&
-                   Objects.equals(unit,       that.unit);
+        if (object != null) {
+            if (mode == ComparisonMode.STRICT) {
+                if (getClass() == object.getClass()) {
+                    final DefaultParameterValue<?> that = (DefaultParameterValue<?>)
object;
+                    return Objects.equals(descriptor, that.descriptor) &&
+                           Objects.equals(value,      that.value) &&
+                           Objects.equals(unit,       that.unit);
+                }
+            } else if (object instanceof ParameterValue<?>) {
+                final ParameterValue<?> that = (ParameterValue<?>) object;
+                return deepEquals(getDescriptor(), that.getDescriptor(), mode) &&
+                       Objects.equals(getValue(),  that.getValue()) &&
+                       Objects.equals(getUnit(),   that.getUnit());
+            }
         }
         return false;
     }
 
     /**
+     * Compares the specified object with this parameter for equality.
+     * This method is implemented as below:
+     *
+     * {@preformat java
+     *     return equals(other, ComparisonMode.STRICT);
+     * }
+     *
+     * Subclasses shall override {@link #equals(Object, ComparisonMode)} instead than this
method.
+     *
+     * @param  object The object to compare to {@code this}.
+     * @return {@code true} if both objects are equal.
+     */
+    @Override
+    public final boolean equals(final Object object) {
+        return equals(object, ComparisonMode.STRICT);
+    }
+
+    /**
      * Returns a hash value for this parameter.
      *
      * @return The hash code value. This value doesn't need to be the same

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java?rev=1626012&r1=1626011&r2=1626012&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValueGroup.java
[UTF-8] Thu Sep 18 15:56:18 2014
@@ -27,10 +27,13 @@ import org.opengis.parameter.GeneralPara
 import org.opengis.parameter.GeneralParameterDescriptor;
 import org.opengis.parameter.ParameterNotFoundException;
 import org.opengis.parameter.InvalidParameterCardinalityException;
+import org.apache.sis.util.LenientComparable;
+import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.Debug;
 
+import static org.apache.sis.util.Utilities.deepEquals;
 import static org.apache.sis.referencing.IdentifiedObjects.isHeuristicMatchForName;
 
 // Branch-dependent imports
@@ -100,7 +103,9 @@ import java.util.Objects;
  * @see DefaultParameterDescriptorGroup
  * @see DefaultParameterValue
  */
-public class DefaultParameterValueGroup implements ParameterValueGroup, Serializable, Cloneable
{
+public class DefaultParameterValueGroup implements ParameterValueGroup,
+        LenientComparable, Serializable, Cloneable
+{
     /**
      * Serial number for inter-operability with different versions.
      */
@@ -318,24 +323,53 @@ public class DefaultParameterValueGroup 
 
     /**
      * Compares the specified object with this parameter for equality.
+     * The strictness level is controlled by the second argument.
      *
      * @param  object The object to compare to {@code this}.
-     * @return {@code true} if both objects are equal.
+     * @param  mode The strictness level of the comparison.
+     * @return {@code true} if both objects are equal according the given comparison mode.
      */
     @Override
-    public boolean equals(final Object object) {
+    public boolean equals(final Object object, final ComparisonMode mode) {
         if (object == this) {
+            // Slight optimization
             return true;
         }
-        if (object != null && getClass() == object.getClass()) {
-            final DefaultParameterValueGroup that = (DefaultParameterValueGroup) object;
-            return Objects.equals(values.descriptor, that.values.descriptor) &&
-                   Objects.equals(values, that.values);
+        if (object != null) {
+            if (mode == ComparisonMode.STRICT) {
+                if (getClass() == object.getClass()) {
+                    final DefaultParameterValueGroup that = (DefaultParameterValueGroup)
object;
+                    return Objects.equals(values.descriptor, that.values.descriptor) &&
+                           Objects.equals(values, that.values);
+                }
+            } else if (object instanceof ParameterValueGroup) {
+                final ParameterValueGroup that = (ParameterValueGroup) object;
+                return deepEquals(getDescriptor(), that.getDescriptor(), mode) &&
+                       deepEquals(values(), that.values(), mode);
+            }
         }
         return false;
     }
 
     /**
+     * Compares the specified object with this parameter for equality.
+     * This method is implemented as below:
+     *
+     * {@preformat java
+     *     return equals(other, ComparisonMode.STRICT);
+     * }
+     *
+     * Subclasses shall override {@link #equals(Object, ComparisonMode)} instead than this
method.
+     *
+     * @param  object The object to compare to {@code this}.
+     * @return {@code true} if both objects are equal.
+     */
+    @Override
+    public final boolean equals(final Object object) {
+        return equals(object, ComparisonMode.STRICT);
+    }
+
+    /**
      * Returns a hash value for this parameter.
      *
      * @return The hash code value. This value doesn't need to be the same



Mime
View raw message