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 976898a Add a Features.getLinkTarget(…) method for determining if a PropertyType is a link. 976898a is described below commit 976898a4f2dbcf7d6e129158ec4db98e9b9fc406 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Tue Mar 24 10:56:27 2020 +0100 Add a Features.getLinkTarget(…) method for determining if a PropertyType is a link. --- .../org/apache/sis/feature/FeatureOperations.java | 2 ++ .../main/java/org/apache/sis/feature/Features.java | 20 +++++++++++++ .../java/org/apache/sis/feature/LinkOperation.java | 9 ++++-- .../java/org/apache/sis/feature/package-info.java | 2 +- .../sis/internal/feature/AttributeConvention.java | 6 ++-- .../sis/internal/feature/FeatureUtilities.java | 33 +--------------------- 6 files changed, 34 insertions(+), 38 deletions(-) diff --git a/core/sis-feature/src/main/java/org/apache/sis/feature/FeatureOperations.java b/core/sis-feature/src/main/java/org/apache/sis/feature/FeatureOperations.java index ad190ec..c3b481c 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/feature/FeatureOperations.java +++ b/core/sis-feature/src/main/java/org/apache/sis/feature/FeatureOperations.java @@ -155,6 +155,8 @@ public final class FeatureOperations extends Static { * @param identification the name and other information to be given to the operation. * @param referent the referenced attribute or feature association. * @return an operation which is an alias for the {@code referent} property. + * + * @see Features#getLinkTarget(PropertyType) */ public static Operation link(final Map<String,?> identification, final PropertyType referent) { ArgumentChecks.ensureNonNull("referent", referent); diff --git a/core/sis-feature/src/main/java/org/apache/sis/feature/Features.java b/core/sis-feature/src/main/java/org/apache/sis/feature/Features.java index 16f1b7d..73c81dc 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/feature/Features.java +++ b/core/sis-feature/src/main/java/org/apache/sis/feature/Features.java @@ -256,6 +256,26 @@ public final class Features extends Static { } /** + * If the given property is a link, returns the name of the referenced property. + * A link is an operation created by a call to {@link FeatureOperations#link(Map, PropertyType)}, + * in which case the value returned by this method is the name of the {@link PropertyType} argument + * which has been given to that {@code link(…)} method. + * + * @param property the property to test, or {@code null} if none. + * @return the referenced property name if {@code property} is a link, or an empty value otherwise. + * + * @see FeatureOperations#link(Map, PropertyType) + * + * @since 1.1 + */ + public static Optional<String> getLinkTarget(final PropertyType property) { + if (property instanceof LinkOperation) { + return Optional.of(((LinkOperation) property).referentName); + } + return Optional.empty(); + } + + /** * Ensures that all characteristics and property values in the given feature are valid. * An attribute is valid if it contains a number of values between the * {@linkplain DefaultAttributeType#getMinimumOccurs() minimum} and diff --git a/core/sis-feature/src/main/java/org/apache/sis/feature/LinkOperation.java b/core/sis-feature/src/main/java/org/apache/sis/feature/LinkOperation.java index 7e9e7fb..e009f39 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/feature/LinkOperation.java +++ b/core/sis-feature/src/main/java/org/apache/sis/feature/LinkOperation.java @@ -38,7 +38,7 @@ import org.opengis.feature.PropertyType; * The operation acts like a reference to another property. * * @author Johann Sorel (Geomatys) - * @version 0.8 + * @version 1.1 * @since 0.6 * @module */ @@ -49,6 +49,11 @@ final class LinkOperation extends AbstractOperation { private static final long serialVersionUID = 765096861589501215L; /** + * The parameter descriptor for the "Link" operation, which does not take any parameter. + */ + private static final ParameterDescriptorGroup PARAMETERS = FeatureUtilities.parameters("Link"); + + /** * The type of the result. */ private final PropertyType result; @@ -84,7 +89,7 @@ final class LinkOperation extends AbstractOperation { */ @Override public ParameterDescriptorGroup getParameters() { - return FeatureUtilities.LINK_PARAMS; + return PARAMETERS; } /** diff --git a/core/sis-feature/src/main/java/org/apache/sis/feature/package-info.java b/core/sis-feature/src/main/java/org/apache/sis/feature/package-info.java index 7cba32d..8bf008b 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/feature/package-info.java +++ b/core/sis-feature/src/main/java/org/apache/sis/feature/package-info.java @@ -93,7 +93,7 @@ * @author Travis L. Pinney * @author Johann Sorel (Geomatys) * @author Martin Desruisseaux (Geomatys) - * @version 1.0 + * @version 1.1 * @since 0.5 * @module */ diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/AttributeConvention.java b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/AttributeConvention.java index f2400a3..9756f50 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/AttributeConvention.java +++ b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/AttributeConvention.java @@ -403,9 +403,9 @@ public final class AttributeConvention extends Static { * @return the default value of the named characteristic in the given property, or {@code null} if none. */ private static Object getCharacteristic(final FeatureType feature, PropertyType property, final String characteristic) { - final String referent = FeatureUtilities.linkOf(property); - if (referent != null && feature != null) { - property = feature.getProperty(referent); + final Optional<String> referent = Features.getLinkTarget(property); + if (referent.isPresent() && feature != null) { + property = feature.getProperty(referent.get()); } if (property instanceof AttributeType<?>) { final AttributeType<?> type = ((AttributeType<?>) property).characteristics().get(characteristic); diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureUtilities.java b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureUtilities.java index f37c3ec..9bed7a3 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureUtilities.java +++ b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/FeatureUtilities.java @@ -27,8 +27,6 @@ import org.opengis.parameter.ParameterDescriptor; import org.opengis.parameter.ParameterDescriptorGroup; import org.apache.sis.parameter.DefaultParameterDescriptorGroup; import org.apache.sis.metadata.iso.citation.Citations; -import org.apache.sis.feature.AbstractOperation; -import org.apache.sis.internal.util.CollectionsExt; import org.apache.sis.util.Static; // Branch-dependent imports @@ -40,19 +38,12 @@ import org.opengis.feature.PropertyType; * * @author Johann Sorel (Geomatys) * @author Martin Desruisseaux (Geomatys) - * @version 1.0 + * @version 1.1 * @since 0.8 * @module */ public final class FeatureUtilities extends Static { /** - * The parameter descriptor for the "Link" operation, which does not take any parameter. - * We use those parameters as a way to identify the link operation without making the - * {@code LinkOperation} class public. - */ - public static final ParameterDescriptorGroup LINK_PARAMS = parameters("Link"); - - /** * Do not allow instantiation of this class. */ private FeatureUtilities() { @@ -74,28 +65,6 @@ public final class FeatureUtilities extends Static { } /** - * If the given property is a link, returns the name of the referenced property. - * Otherwise returns {@code null}. - * - * @param property the property to test, or {@code null} if none. - * @return the referenced property name, or {@code null} if none. - */ - static String linkOf(final PropertyType property) { - if (property instanceof AbstractOperation) { - final AbstractOperation op = (AbstractOperation) property; - if (op.getParameters() == LINK_PARAMS) { - /* - * The dependencies collection contains exactly one element on Apache SIS implementation. - * However the user could define his own operation with the same parameter descriptor name. - * This is unlikely since it would probably be a bug, but we are paranoiac. - */ - return CollectionsExt.first(op.getDependencies()); - } - } - return null; - } - - /** * Gets the name of all given properties. If any property is null or has a null name, * then the corresponding entry in the returned array will be null. *