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 8e1df6f18cb38e9f0c1f73a8573af8907084f3da Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Tue Oct 19 17:05:43 2021 +0200 Provide an extension mechanism for allowing users to provide their own solution for https://github.com/apache/sis/pull/24 --- .../org/apache/sis/coverage/SampleDimension.java | 33 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 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 f8308c4..ce4e432 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 @@ -200,7 +200,7 @@ public class SampleDimension implements Serializable { * @see #forConvertedValues(boolean) */ private SampleDimension converted() { - // Transfer function shall never be null if 'converse' is non-null. + // Transfer function shall never be null if `converse` is non-null. return (converse != null && !transferFunction.isIdentity()) ? converse : this; } @@ -439,7 +439,7 @@ public class SampleDimension implements Serializable { * @see org.apache.sis.coverage.grid.GridCoverage#forConvertedValues(boolean) */ public SampleDimension forConvertedValues(final boolean converted) { - // Transfer function shall never be null if 'converse' is non-null. + // Transfer function shall never be null if `converse` is non-null. if (converse != null && transferFunction.isIdentity() != converted) { return converse; } @@ -543,6 +543,7 @@ public class SampleDimension implements Serializable { * subclasses can override. * * @author Martin Desruisseaux (IRD, Geomatys) + * @author Alexis Manin (Geomatys) * @version 1.2 * @since 1.0 * @module @@ -655,7 +656,7 @@ public class SampleDimension implements Serializable { case Numbers.FLOAT: { final float min = minimum.floatValue(); final float max = maximum.floatValue(); - if (!Float.isNaN(min) || !Float.isNaN(max)) { // Let 'create' throws an exception if only one value is NaN. + if (!Float.isNaN(min) || !Float.isNaN(max)) { // Let `create` throws an exception if only one value is NaN. return NumberRange.create(min, true, max, true); } if (minimum.getClass() != Float.class) minimum = min; @@ -665,7 +666,7 @@ public class SampleDimension implements Serializable { default: { final double min = minimum.doubleValue(); final double max = maximum.doubleValue(); - if (!Double.isNaN(min) || !Double.isNaN(max)) { // Let 'create' throws an exception if only one value is NaN. + if (!Double.isNaN(min) || !Double.isNaN(max)) { // Let `create` throws an exception if only one value is NaN. return NumberRange.create(min, true, max, true); } if (minimum.getClass() != Double.class) minimum = min; @@ -679,6 +680,25 @@ public class SampleDimension implements Serializable { } /** + * Returns the background value to use by default if none were explicitly defined. + * This method is invoked at {@linkplain #build() build} time + * if the {@link #setBackground(CharSequence, Number)} method has never been invoked + * since {@code Builder} construction or since the last call to {@link #clear()}. + * The background value returned by this method is not associated to any category. + * + * <p>The default implementation returns {@code null}. + * Subclasses can override this method and compute a background value + * for example by analyzing the content of {@link #categories()} list.</p> + * + * @return the default background value, or {@code null} if none. + * + * @since 1.2 + */ + protected Number defaultBackground() { + return null; + } + + /** * Adds a qualitative category and marks that category as the background value. * This is the value to be returned by {@link SampleDimension#getBackground()}. * If this method is invoked more than once, then the last specified value prevails @@ -695,7 +715,7 @@ public class SampleDimension implements Serializable { name = Vocabulary.formatInternational(Vocabulary.Keys.FillValue); } final NumberRange<?> samples = range(sample.getClass(), sample, sample); - // Use of 'getMinValue()' below shall be consistent with ToNaN.remove(Category). + // Use of `getMinValue()` below shall be consistent with ToNaN.remove(Category). toNaN.background = samples.getMinValue(); add(new Category(name, samples, null, null, toNaN)); return this; @@ -1153,6 +1173,9 @@ defName: if (name == null) { } name = createLocalName(Vocabulary.formatInternational(Vocabulary.Keys.Untitled)); } + if (toNaN.background == null) { + toNaN.background = defaultBackground(); + } return new SampleDimension(name, toNaN.background, UnmodifiableArrayList.wrap(categories, 0, count)); }