sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1567022 - in /sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter: AbstractParameterValue.java DefaultParameterValue.java
Date Tue, 11 Feb 2014 10:09:11 GMT
Author: desruisseaux
Date: Tue Feb 11 10:09:10 2014
New Revision: 1567022

URL: http://svn.apache.org/r1567022
Log:
Simplification: removed an other abstract class which was not so helpful.

Removed:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/AbstractParameterValue.java
Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java?rev=1567022&r1=1567021&r2=1567022&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/DefaultParameterValue.java
[UTF-8] Tue Feb 11 10:09:10 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.parameter;
 
+import java.io.Serializable;
 import java.io.File;
 import java.net.URL;
 import java.net.URI;
@@ -28,7 +29,10 @@ import org.opengis.parameter.ParameterVa
 import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.parameter.InvalidParameterTypeException;
 import org.opengis.parameter.InvalidParameterValueException;
+import org.apache.sis.io.wkt.FormattableObject;
+import org.apache.sis.io.wkt.Formatter;
 import org.apache.sis.internal.util.Numerics;
+import org.apache.sis.util.Numbers;
 import org.apache.sis.util.resources.Errors;
 
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
@@ -36,7 +40,6 @@ import static org.apache.sis.util.Argume
 // Related to JDK7
 import java.util.Objects;
 import java.nio.file.Path;
-import org.apache.sis.util.Numbers;
 
 
 /**
@@ -94,13 +97,18 @@ import org.apache.sis.util.Numbers;
  * @see DefaultParameterDescriptor
  * @see DefaultParameterGroup
  */
-public class DefaultParameterValue<T> extends AbstractParameterValue implements ParameterValue<T>
{
+public class DefaultParameterValue<T> extends FormattableObject implements ParameterValue<T>,
Serializable, Cloneable {
     /**
      * Serial number for inter-operability with different versions.
      */
     private static final long serialVersionUID = -5837826787089486776L;
 
     /**
+     * The definition of this parameter.
+     */
+    private final ParameterDescriptor<T> descriptor;
+
+    /**
      * The value, or {@code null} if undefined.
      * Except for the constructors, the {@link #equals(Object)} and the {@link #hashCode()}
methods,
      * this field shall be read only by {@link #getValue()} and written by {@link #setValue(Object,
Unit)}.
@@ -121,9 +129,10 @@ public class DefaultParameterValue<T> ex
      * @param descriptor The abstract definition of this parameter.
      */
     public DefaultParameterValue(final ParameterDescriptor<T> descriptor) {
-        super(descriptor);
-        value = descriptor.getDefaultValue();
-        unit  = descriptor.getUnit();
+        ensureNonNull("descriptor", descriptor);
+        this.descriptor = descriptor;
+        this.value      = descriptor.getDefaultValue();
+        this.unit       = descriptor.getUnit();
     }
 
     /**
@@ -134,18 +143,20 @@ public class DefaultParameterValue<T> ex
      * @param parameter The parameter to copy values from.
      */
     public DefaultParameterValue(final ParameterValue<T> parameter) {
-        super(parameter); // Require <T>, not <? extends T>.
-        value = parameter.getValue();
-        unit  = parameter.getUnit();
+        ensureNonNull("parameter", parameter);
+        descriptor = parameter.getDescriptor();
+        value      = parameter.getValue();
+        unit       = parameter.getUnit();
     }
 
     /**
-     * Returns the abstract definition of this parameter.
+     * Returns the definition of this parameter.
+     *
+     * @return The definition of this parameter.
      */
     @Override
-    @SuppressWarnings("unchecked") // Type checked by the constructor.
     public ParameterDescriptor<T> getDescriptor() {
-        return (ParameterDescriptor<T>) super.getDescriptor();
+        return descriptor;
     }
 
     /**
@@ -524,7 +535,7 @@ public class DefaultParameterValue<T> ex
     @Override
     public void setValue(final int value) throws InvalidParameterValueException {
         Number n = Integer.valueOf(value);
-        final Class<?> valueClass = ((ParameterDescriptor<?>) descriptor).getValueClass();
+        final Class<T> valueClass = descriptor.getValueClass();
         if (Number.class.isAssignableFrom(valueClass)) {
             @SuppressWarnings("unchecked")
             final Number c = Numbers.cast(value, (Class<? extends Number>) valueClass);
@@ -570,7 +581,7 @@ public class DefaultParameterValue<T> ex
         try {
             // Use 'unit' instead than 'getUnit()' despite class Javadoc claims because units
are not expected
             // to be involved in this method. We just want the current unit setting to be
unchanged.
-            setValue(wrap(value, ((ParameterDescriptor<?>) descriptor).getValueClass()),
unit);
+            setValue(wrap(value, descriptor.getValueClass()), unit);
         } catch (IllegalArgumentException e) {
             throw new InvalidParameterValueException(e.getLocalizedMessage(), Verifier.getName(descriptor),
value);
         }
@@ -593,7 +604,7 @@ public class DefaultParameterValue<T> ex
     @Override
     public void setValue(final double value, final Unit<?> unit) throws InvalidParameterValueException
{
         try {
-            setValue(wrap(value, ((ParameterDescriptor<?>) descriptor).getValueClass()),
unit);
+            setValue(wrap(value, descriptor.getValueClass()), unit);
         } catch (IllegalArgumentException e) {
             throw new InvalidParameterValueException(e.getLocalizedMessage(), Verifier.getName(descriptor),
value);
         }
@@ -633,9 +644,8 @@ public class DefaultParameterValue<T> ex
      * @throws InvalidParameterValueException if the type of {@code value} is inappropriate
for this parameter,
      *         or if the value is illegal for some other reason (for example the value is
numeric and out of range).
      */
-    @SuppressWarnings("unchecked") // Safe because descriptor type is enforced by constructor
signature.
     protected void setValue(final Object value, final Unit<?> unit) throws InvalidParameterValueException
{
-        this.value = Verifier.ensureValidValue((ParameterDescriptor<T>) descriptor,
value, unit);
+        this.value = Verifier.ensureValidValue(descriptor, value, unit);
         this.unit  = unit; // Assign only on success.
     }
 
@@ -651,10 +661,11 @@ public class DefaultParameterValue<T> ex
             // Slight optimization
             return true;
         }
-        if (super.equals(object)) {
+        if (object != null && getClass() == object.getClass()) {
             final DefaultParameterValue<?> that = (DefaultParameterValue<?>)
object;
-            return Objects.equals(this.value, that.value) &&
-                   Objects.equals(this.unit,  that.unit);
+            return Objects.equals(descriptor, that.descriptor) &&
+                   Objects.equals(value,      that.value) &&
+                   Objects.equals(unit,       that.unit);
         }
         return false;
     }
@@ -667,7 +678,7 @@ public class DefaultParameterValue<T> ex
      */
     @Override
     public int hashCode() {
-        int code = 37 * super.hashCode();
+        int code = 37 * descriptor.hashCode();
         if (value != null) code +=   value.hashCode();
         if (unit  != null) code += 31*unit.hashCode();
         return code;
@@ -679,6 +690,15 @@ public class DefaultParameterValue<T> ex
     @Override
     @SuppressWarnings("unchecked")
     public DefaultParameterValue<T> clone() {
-        return (DefaultParameterValue<T>) super.clone();
+        try {
+            return (DefaultParameterValue<T>) super.clone();
+        } catch (CloneNotSupportedException exception) {
+            throw new AssertionError(exception); // Should not happen, since we are cloneable
+        }
+    }
+
+    @Override
+    protected String formatTo(final Formatter formatter) {
+        return null;
     }
 }



Mime
View raw message