sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Rename `getPropertyValue(String, Object)` as `getValueOrFallback(…)` for avoiding dangerous similarity with `setPropertyValue(…)`. Before this change, the two methods differed only by one letter ("g" versus "s"), which is a risk of introducing bugs by typos. The new name is also more readable and more consistent with standard Java practice such as `java.util.Map.getOrDefault(…)`.
Date Thu, 26 Nov 2020 11:50:04 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new c0bf843  Rename `getPropertyValue(String, Object)` as `getValueOrFallback(…)` for
avoiding dangerous similarity with `setPropertyValue(…)`. Before this change, the two methods
differed only by one letter ("g" versus "s"), which is a risk of introducing bugs by typos.
The new name is also more readable and more consistent with standard Java practice such as
`java.util.Map.getOrDefault(…)`.
c0bf843 is described below

commit c0bf8430da64dac0a5abb5bcc1722e857b72bca8
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Thu Nov 26 12:49:21 2020 +0100

    Rename `getPropertyValue(String, Object)` as `getValueOrFallback(…)` for avoiding dangerous
similarity with `setPropertyValue(…)`.
    Before this change, the two methods differed only by one letter ("g" versus "s"), which
is a risk of introducing bugs by typos.
    The new name is also more readable and more consistent with standard Java practice such
as `java.util.Map.getOrDefault(…)`.
---
 .../apache/sis/gui/dataset/ExpandedFeature.java    |  2 +-
 .../org/apache/sis/feature/AbstractFeature.java    | 56 +++++++++++-----------
 .../java/org/apache/sis/feature/DenseFeature.java  |  4 +-
 .../java/org/apache/sis/feature/SparseFeature.java |  4 +-
 .../apache/sis/feature/AbstractFeatureTest.java    |  2 +-
 5 files changed, 35 insertions(+), 33 deletions(-)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ExpandedFeature.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ExpandedFeature.java
index fe0550a..32e7254 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ExpandedFeature.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ExpandedFeature.java
@@ -174,7 +174,7 @@ final class ExpandedFeature implements Feature {
      * Synonymous of {@link #getPropertyValue(String)} since we do not check property existence.
      */
     @Override
-    public Object getPropertyValue(final String name, final Object missingPropertyFallback)
{
+    public Object getValueOrFallback(final String name, final Object missingPropertyFallback)
{
         return getPropertyValue(name);
     }
 
diff --git a/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractFeature.java b/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractFeature.java
index 77687b9..b7754e8 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractFeature.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/feature/AbstractFeature.java
@@ -94,7 +94,7 @@ public abstract class AbstractFeature implements Feature, Serializable {
     /**
      * Sentinel value for missing property.
      *
-     * @see #getPropertyValue(String, Object)
+     * @see #getValueOrFallback(String, Object)
      */
     static final Object MISSING = new Object();
 
@@ -333,7 +333,8 @@ public abstract class AbstractFeature implements Feature, Serializable
{
      * }
      *
      * @param  name  the property name.
-     * @return the value for the specified property, or {@code null} if none.
+     * @return value of the specified property, or the
+     *         {@linkplain DefaultAttributeType#getDefaultValue() default value} (which may
be {@code null}} if none.
      * @throws PropertyNotFoundException if the given argument is not an attribute or association
name of this feature.
      *
      * @see AbstractAttribute#getValue()
@@ -342,8 +343,28 @@ public abstract class AbstractFeature implements Feature, Serializable
{
     public abstract Object getPropertyValue(final String name) throws PropertyNotFoundException;
 
     /**
+     * Sets the value for the property of the given name.
+     *
+     * <h4>Validation</h4>
+     * The amount of validation performed by this method is implementation dependent.
+     * Usually, only the most basic constraints are verified. This is so for performance
reasons
+     * and also because some rules may be temporarily broken while constructing a feature.
+     * A more exhaustive verification can be performed by invoking the {@link #quality()}
method.
+     *
+     * @param  name   the attribute name.
+     * @param  value  the new value for the given attribute (may be {@code null}).
+     * @throws PropertyNotFoundException if the given name is not an attribute or association
name of this feature.
+     * @throws ClassCastException if the value is not assignable to the expected value class.
+     * @throws InvalidPropertyValueException if the given value is not valid for a reason
other than its type.
+     *
+     * @see AbstractAttribute#setValue(Object)
+     */
+    @Override
+    public abstract void setPropertyValue(final String name, final Object value) throws IllegalArgumentException;
+
+    /**
      * Returns the value for the property of the given name if that property exists, or a
fallback value otherwise.
-     * This method is equivalent to the following code, but potentially more efficient:
+     * This method is equivalent to the following code, but potentially more efficient when
the property does not exist:
      *
      * {@preformat java
      *     try {
@@ -353,39 +374,20 @@ public abstract class AbstractFeature implements Feature, Serializable
{
      *     }
      * }
      *
-     * Note that if a property of the given name exists but has no value, then this method
returns {@code null}.
+     * Note that if a property of the given name exists but has no value, then this method
returns the
+     * {@linkplain DefaultAttributeType#getDefaultValue() default value} (which may be {@code
null}).
      * <cite>Property without value</cite> is not equivalent to <cite>non-existent
property</cite>.
      *
      * @param  name  the property name.
      * @param  missingPropertyFallback  the (potentially {@code null}) value to return
      *         if no attribute or association of the given name exists.
-     * @return the value for the specified property, or the fallback value if no attribute
or association
-     *         of that name exists. This value may be {@code null}.
+     * @return value or default value of the specified property, or {@code missingPropertyFallback}
+     *         if no attribute or association of that name exists. This value may be {@code
null}.
      *
      * @since 1.1
      */
     @Override
-    public abstract Object getPropertyValue(final String name, Object missingPropertyFallback);
-
-    /**
-     * Sets the value for the property of the given name.
-     *
-     * <h4>Validation</h4>
-     * The amount of validation performed by this method is implementation dependent.
-     * Usually, only the most basic constraints are verified. This is so for performance
reasons
-     * and also because some rules may be temporarily broken while constructing a feature.
-     * A more exhaustive verification can be performed by invoking the {@link #quality()}
method.
-     *
-     * @param  name   the attribute name.
-     * @param  value  the new value for the given attribute (may be {@code null}).
-     * @throws PropertyNotFoundException if the given name is not an attribute or association
name of this feature.
-     * @throws ClassCastException if the value is not assignable to the expected value class.
-     * @throws InvalidPropertyValueException if the given value is not valid for a reason
other than its type.
-     *
-     * @see AbstractAttribute#setValue(Object)
-     */
-    @Override
-    public abstract void setPropertyValue(final String name, final Object value) throws IllegalArgumentException;
+    public abstract Object getValueOrFallback(final String name, Object missingPropertyFallback);
 
     /**
      * Executes the parameterless operation of the given name and returns the value of its
result.
diff --git a/core/sis-feature/src/main/java/org/apache/sis/feature/DenseFeature.java b/core/sis-feature/src/main/java/org/apache/sis/feature/DenseFeature.java
index e45b6f5..f54948a 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/feature/DenseFeature.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/feature/DenseFeature.java
@@ -180,7 +180,7 @@ final class DenseFeature extends AbstractFeature implements Cloneable
{
      */
     @Override
     public Object getPropertyValue(final String name) throws PropertyNotFoundException {
-        final Object value = getPropertyValue(name, MISSING);
+        final Object value = getValueOrFallback(name, MISSING);
         if (value != MISSING) return value;
         throw new PropertyNotFoundException(propertyNotFound(type, getName(), name));
     }
@@ -195,7 +195,7 @@ final class DenseFeature extends AbstractFeature implements Cloneable
{
      * @since 1.1
      */
     @Override
-    public final Object getPropertyValue(final String name, final Object missingPropertyFallback)
{
+    public final Object getValueOrFallback(final String name, final Object missingPropertyFallback)
{
         ArgumentChecks.ensureNonNull("name", name);
         final Integer index = indices.get(name);
         if (index == null) {
diff --git a/core/sis-feature/src/main/java/org/apache/sis/feature/SparseFeature.java b/core/sis-feature/src/main/java/org/apache/sis/feature/SparseFeature.java
index 67bb4d9..8b3a051 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/feature/SparseFeature.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/feature/SparseFeature.java
@@ -228,7 +228,7 @@ final class SparseFeature extends AbstractFeature implements Cloneable
{
      */
     @Override
     public Object getPropertyValue(final String name) throws PropertyNotFoundException {
-        final Object value = getPropertyValue(name, MISSING);
+        final Object value = getValueOrFallback(name, MISSING);
         if (value != MISSING) return value;
         throw new PropertyNotFoundException(propertyNotFound(type, getName(), name));
     }
@@ -243,7 +243,7 @@ final class SparseFeature extends AbstractFeature implements Cloneable
{
      * @since 1.1
      */
     @Override
-    public final Object getPropertyValue(final String name, final Object missingPropertyFallback)
{
+    public final Object getValueOrFallback(final String name, final Object missingPropertyFallback)
{
         ArgumentChecks.ensureNonNull("name", name);
         final Integer index = indices.get(name);
         if (index == null) {
diff --git a/core/sis-feature/src/test/java/org/apache/sis/feature/AbstractFeatureTest.java
b/core/sis-feature/src/test/java/org/apache/sis/feature/AbstractFeatureTest.java
index 0abda30..592838a 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/feature/AbstractFeatureTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/feature/AbstractFeatureTest.java
@@ -105,7 +105,7 @@ public final strictfp class AbstractFeatureTest extends FeatureTestCase
{
          * Synonymous of {@link #getPropertyValue(String)} for this test.
          */
         @Override
-        public Object getPropertyValue(final String name, final Object missingPropertyFallback)
{
+        public Object getValueOrFallback(final String name, final Object missingPropertyFallback)
{
             return getPropertyValue(name);
         }
 


Mime
View raw message