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

commit c818b11f080b1bd35f8f464f99ef735b889ae363
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Sat Apr 2 17:23:45 2022 +0200

    Provide a default "data" name in `SampleDimension.Builder`.
    Add a missing method call chaining in `GridCoverageBuilder`.
---
 .../java/org/apache/sis/coverage/SampleDimension.java    | 16 ++++++++++++----
 .../apache/sis/coverage/grid/GridCoverageBuilder.java    |  6 ++++--
 .../org/apache/sis/internal/coverage/j2d/Colorizer.java  |  3 +--
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/coverage/SampleDimension.java 
b/core/sis-feature/src/main/java/org/apache/sis/coverage/SampleDimension.java
index 3d0af60..a8063f6 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/coverage/SampleDimension.java
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/coverage/SampleDimension.java
@@ -1014,7 +1014,8 @@ public class SampleDimension implements Serializable {
          * <div class="note"><b>Implementation note:</b>
          * this convenience method delegates to {@link 
#addQuantitative(CharSequence, NumberRange, MathTransform1D, Unit)}.</div>
          *
-         * @param  name        the category name as a {@link String} or {@link 
InternationalString} object.
+         * @param  name        the category name as a {@link String} or {@link 
InternationalString} object,
+         *                     or {@code null} for a default "data" name.
          * @param  samples     the minimum and maximum sample values in the 
category. Element class is usually
          *                     {@link Integer}, but {@link Float} and {@link 
Double} values are accepted as well.
          * @param  converted   the range of real values for this category, as 
an instance of {@link MeasurementRange}
@@ -1052,7 +1053,8 @@ public class SampleDimension implements Serializable {
          * <div class="note"><b>Implementation note:</b>
          * this convenience method delegates to {@link 
#addQuantitative(CharSequence, NumberRange, MathTransform1D, Unit)}.</div>
          *
-         * @param  name     the category name as a {@link String} or {@link 
InternationalString} object.
+         * @param  name     the category name as a {@link String} or {@link 
InternationalString} object,
+         *                  or {@code null} for a default "data" name.
          * @param  minimum  the minimum value (inclusive) in the given units.
          * @param  maximum  the maximum value (inclusive) in the given units.
          * @param  units    the units of measurement, or {@code null} if 
unknown or not applicable.
@@ -1070,7 +1072,8 @@ public class SampleDimension implements Serializable {
          * <div class="note"><b>Implementation note:</b>
          * this convenience method delegates to {@link 
#addQuantitative(CharSequence, NumberRange, MathTransform1D, Unit)}.</div>
          *
-         * @param  name     the category name as a {@link String} or {@link 
InternationalString} object.
+         * @param  name     the category name as a {@link String} or {@link 
InternationalString} object,
+         *                  or {@code null} for a default "data" name.
          * @param  minimum  the minimum value (inclusive) in the given units.
          * @param  maximum  the maximum value (inclusive) in the given units.
          * @param  units    the units of measurement, or {@code null} if 
unknown or not applicable.
@@ -1093,6 +1096,7 @@ public class SampleDimension implements Serializable {
          * this convenience method delegates to {@link 
#addQuantitative(CharSequence, NumberRange, MathTransform1D, Unit)}.</div>
          *
          * @param  name    the category name as a {@link String} or {@link 
InternationalString} object.
+         *                 or {@code null} for a default "data" name.
          * @param  lower   the lower sample value, inclusive.
          * @param  upper   the upper sample value, exclusive.
          * @param  scale   the scale value which is multiplied to sample 
values for the category. Must be different than zero.
@@ -1119,7 +1123,8 @@ public class SampleDimension implements Serializable {
          * <p>This is the most generic method for adding a quantitative 
category.
          * All other {@code addQuantitative(name, …)} methods are convenience 
methods delegating their work to this method.</p>
          *
-         * @param  name     the category name as a {@link String} or {@link 
InternationalString} object.
+         * @param  name     the category name as a {@link String} or {@link 
InternationalString} object,
+         *                  or {@code null} for a default "data" name.
          * @param  samples  the minimum and maximum sample values in the 
category. Element class is usually
          *                  {@link Integer}, but {@link Float} and {@link 
Double} types are accepted as well.
          * @param  toUnits  the transfer function from sample values to real 
values in the specified units.
@@ -1133,6 +1138,9 @@ public class SampleDimension implements Serializable {
          */
         public Builder addQuantitative(CharSequence name, NumberRange<?> 
samples, MathTransform1D toUnits, Unit<?> units) {
             ArgumentChecks.ensureNonNull("toUnits", toUnits);
+            if (name == null) {
+                name = Vocabulary.formatInternational(Vocabulary.Keys.Data);
+            }
             add(new Category(name, samples, toUnits, units, toNaN));
             return this;
         }
diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java
 
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java
index 9e1c9c0..5a83745 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java
@@ -86,7 +86,7 @@ import org.apache.sis.util.resources.Errors;
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.1
+ * @version 1.2
  *
  * @see GridCoverage2D
  * @see SampleDimension.Builder
@@ -410,12 +410,13 @@ public class GridCoverageBuilder {
      *
      * @param  key    key of the property to set.
      * @param  value  value to associate to the given key.
+     * @return {@code this} for method invocation chaining.
      * @throws IllegalArgumentException if a value is already associated to 
the given key.
      *
      * @since 1.1
      */
     @SuppressWarnings("UseOfObsoleteCollectionType")
-    public void addImageProperty(final String key, final Object value) {
+    public GridCoverageBuilder addImageProperty(final String key, final Object 
value) {
         ArgumentChecks.ensureNonNull("key",   key);
         ArgumentChecks.ensureNonNull("value", value);
         if (properties == null) {
@@ -424,6 +425,7 @@ public class GridCoverageBuilder {
         if (properties.putIfAbsent(key, value) != null) {
             throw new 
IllegalArgumentException(Errors.format(Errors.Keys.ElementAlreadyPresent_1, 
key));
         }
+        return this;
     }
 
     /**
diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/Colorizer.java
 
b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/Colorizer.java
index 83468e2..c39cadb 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/Colorizer.java
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/Colorizer.java
@@ -285,8 +285,7 @@ public final class Colorizer {
         defaultRange = NumberRange.create(minimum, true, maximum, true);
         target = new SampleDimension.Builder()
                 .setBackground(null, 0)
-                
.addQuantitative(Vocabulary.formatInternational(Vocabulary.Keys.Data),
-                        NumberRange.create(1, true, MAX_VALUE, true), 
defaultRange).build();
+                .addQuantitative(null, NumberRange.create(1, true, MAX_VALUE, 
true), defaultRange).build();
 
         source = target.forConvertedValues(true);
         final List<Category> categories = source.getCategories();

Reply via email to