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 125396eed4 Move into NilReasonMap the decision about whether to create NilObject or not. The rational for the removal of NilReason.isSupported(Class) is that we want an exception to be thrown when trying to use NilReason on an illegal type. 125396eed4 is described below commit 125396eed491e56c8cc7f7d286f61bc0e3014d14 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Mon Nov 20 14:05:53 2023 +0100 Move into NilReasonMap the decision about whether to create NilObject or not. The rational for the removal of NilReason.isSupported(Class) is that we want an exception to be thrown when trying to use NilReason on an illegal type. --- .../main/org/apache/sis/metadata/NilReasonMap.java | 23 ++++++++++++++++++++- .../main/org/apache/sis/xml/NilReason.java | 24 +--------------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/NilReasonMap.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/NilReasonMap.java index 0645f92f18..056cd3807a 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/NilReasonMap.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/NilReasonMap.java @@ -16,6 +16,7 @@ */ package org.apache.sis.metadata; +import java.util.Set; import java.util.Map; import java.util.HashMap; import java.util.Iterator; @@ -41,6 +42,15 @@ import org.apache.sis.xml.NilObject; * @see MetadataStandard#asNilReasonMap(Object, Class, KeyNamePolicy) */ final class NilReasonMap extends PropertyMap<NilReason> { + /** + * Classes of objects to represent as {@link NilObject}. + * Interfaces are not included in this list. + * + * @see #asNilObject(Class) + */ + private static final Set<Class<?>> AS_OBJECTS = Set.of( + Double.class, Float.class, String.class, java.net.URI.class); + /** * The metadata object to wrap. */ @@ -171,13 +181,24 @@ final class NilReasonMap extends PropertyMap<NilReason> { return oldReason; } final Class<?> type = accessor.type(index, TypeValuePolicy.PROPERTY_TYPE); - final Object nilObject = NilReason.isSupported(type) ? value.createNilObject(type) : null; + final Object nilObject = asNilObject(type) ? value.createNilObject(type) : null; final Object oldObject = accessor.set(index, metadata, nilObject, PropertyAccessor.RETURN_PREVIOUS); final NilReason oldReason = NilReason.forObject(oldObject); final NilReason oldStored = (nilObject == null) ? nilReasons.put(index, value) : nilReasons.remove(index); return (oldReason != null) ? oldReason : oldStored; } + /** + * Returns whether to handle nil instances of the given type as nil objects. + * The set of accepted types is implementation-dependent and may change in any future Apache SIS version. + * + * @param type the class or interface to test, or {@code null}. + * @return {@code true} if instances of the given type can be represented as nil objects. + */ + private static boolean asNilObject(final Class<?> type) { + return type.isInterface() || AS_OBJECTS.contains(type); + } + /** * Returns an iterator over the entries contained in this map. */ diff --git a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/NilReason.java b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/NilReason.java index 39bc587a38..acbed45a90 100644 --- a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/NilReason.java +++ b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/xml/NilReason.java @@ -17,7 +17,6 @@ package org.apache.sis.xml; import java.util.Map; -import java.util.Set; import java.net.URI; import java.net.URISyntaxException; import java.io.Serializable; @@ -413,21 +412,6 @@ public final class NilReason implements Serializable { return false; } - /** - * Returns whether the given class is accepted by {@code createNilObject(Class)}. - * The set of accepted types is implementation-dependent and may change in any future Apache SIS version. - * - * @param type the class or interface to test, or {@code null}. - * @return {@code true} if the given type is non-null and is accepted by {@link #createNilObject(Class)}. - * - * @since 1.5 - */ - public static boolean isSupported(final Class<?> type) { - if (type == null) return false; - if (type.isInterface()) return !NilObjectHandler.isIgnoredInterface(type); - return ACCEPTED_CLASSES.contains(type); - } - /** * Returns an object of the given type which is nil for the reason represented by this instance. * The {@code type} argument can be one of the following cases: @@ -508,17 +492,11 @@ public final class NilReason implements Serializable { return type.cast(object); } - /** - * Classes that are handled in a special way by {@link #createNilInstance(Class)}. - */ - private static final Set<Class<?>> ACCEPTED_CLASSES = Set.of( - Double.class, Float.class, String.class, URI.class); - /** * Returns a new {@code Float}, {@code Double} or {@code String} instance to be considered as a nil value. * * <p><b>Reminder:</b> If more special cases are added, - * do not forget to update the {@link #forObject(Object)} method and the {@link #ACCEPTED_CLASSES} set, + * do not forget to update the {@link #forObject(Object)} method and the {@code NilReasonMap.AS_OBJECTS} set, * then to update the {@link #createNilObject(Class)} and {@link #forObject(Object)} documentation.</p> * * @throws IllegalArgumentException if the given type is not a supported type.