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 97e5b065ab939f99f410022c75a951b7c8f002f9
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Mon Jan 7 19:07:29 2019 +0100

    Make easier for external applications to extend SampleDimension.Builder.
---
 .../java/org/apache/sis/coverage/Category.java     | 45 ++++++++++++++++++----
 .../java/org/apache/sis/coverage/CategoryList.java |  2 +-
 .../org/apache/sis/coverage/SampleDimension.java   | 12 +++++-
 3 files changed, 49 insertions(+), 10 deletions(-)

diff --git 
a/core/sis-raster/src/main/java/org/apache/sis/coverage/Category.java 
b/core/sis-raster/src/main/java/org/apache/sis/coverage/Category.java
index 1f0a7e3..7f94c5b 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/Category.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/Category.java
@@ -171,20 +171,51 @@ public class Category implements Serializable {
     final Category converse;
 
     /**
-     * Creates a copy of the given category except for the {@link #toConverse} 
function which is set to identity.
-     * This is used only if a user specify a {@code ConvertedCategory} to 
{@link SampleDimension} constructor.
-     * Such converted category can only come from another {@code 
SampleDimension} and may have inconsistent
-     * information for the new sample dimension that the user is creating.
+     * Creates a copy of the given category. This constructor is provided for 
subclasses
+     * wanting to extent an existing category with custom information.
      *
      * @param copy  the category to copy.
      */
-    Category(final Category copy) {
+    protected Category(final Category copy) {
         name       = copy.name;
         range      = copy.range;
         minimum    = copy.minimum;
         maximum    = copy.maximum;
-        toConverse = identity();
-        converse   = this;
+        toConverse = copy.toConverse;
+        if (copy.converse == copy) {
+            converse = this;
+        } else {
+            converse = new Category(copy.converse, this);
+        }
+    }
+
+    /**
+     * Creates a copy of the given category except for the {@link #converse} 
and {@link #toConverse} fields.
+     * This constructor serves two purposes:
+     * <ul>
+     *   <li>If {@code caller} is null, then {@link #toConverse} is is set to 
identity.
+     *       This is used only if a user specify a {@code ConvertedCategory} 
to {@link SampleDimension} constructor.
+     *       Such converted category can only come from another {@code 
SampleDimension} and may have inconsistent
+     *       information for the new sample dimension that the user is 
creating.</li>
+     *   <li>If {@code caller} is non-null, then {@link #toConverse} is set to 
the same transform than {@code copy} and
+     *       {@link #converse} is set to {@code caller}. This is used only as 
a complement for the copy constructor.</li>
+     * </ul>
+     *
+     * @param copy    the category to copy.
+     * @param caller  the converse, or {@code null} for {@code this}.
+     */
+    Category(final Category copy, final Category caller) {
+        name    = copy.name;
+        range   = copy.range;
+        minimum = copy.minimum;
+        maximum = copy.maximum;
+        if (caller != null) {
+            toConverse = copy.toConverse;
+            converse   = caller;
+        } else {
+            toConverse = identity();
+            converse   = this;
+        }
     }
 
     /**
diff --git 
a/core/sis-raster/src/main/java/org/apache/sis/coverage/CategoryList.java 
b/core/sis-raster/src/main/java/org/apache/sis/coverage/CategoryList.java
index 13d7818..f008311 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/CategoryList.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/CategoryList.java
@@ -150,7 +150,7 @@ final class CategoryList extends AbstractList<Category> 
implements MathTransform
             for (int i=0; i<categories.length; i++) {
                 final Category c = categories[i];
                 if (c instanceof ConvertedCategory) {
-                    categories[i] = new Category(c);
+                    categories[i] = new Category(c, null);
                 }
             }
         }
diff --git 
a/core/sis-raster/src/main/java/org/apache/sis/coverage/SampleDimension.java 
b/core/sis-raster/src/main/java/org/apache/sis/coverage/SampleDimension.java
index 6294919..7cda99c 100644
--- a/core/sis-raster/src/main/java/org/apache/sis/coverage/SampleDimension.java
+++ b/core/sis-raster/src/main/java/org/apache/sis/coverage/SampleDimension.java
@@ -517,9 +517,17 @@ public class SampleDimension implements Serializable {
         private Number background;
 
         /**
-         * The categories for this sample dimension.
+         * The categories for the sample dimension to create.
+         * This list is modified by the following methods:
+         *
+         * <ul>
+         *   <li>{@link #setBackground(CharSequence, Number)}</li>
+         *   <li>{@link #addQualitative(CharSequence, NumberRange)}</li>
+         *   <li>{@link #addQuantitative(CharSequence, NumberRange, 
MathTransform1D, Unit)}</li>
+         *   <li>{@link #clear()}</li>
+         * </ul>
          */
-        private final List<Category> categories;
+        protected final List<Category> categories;
 
         /**
          * The ordinal NaN values used for this sample dimension.

Reply via email to