From commits-return-13402-apmail-sis-commits-archive=sis.apache.org@sis.apache.org Tue Mar 24 10:00:00 2020 Return-Path: X-Original-To: apmail-sis-commits-archive@www.apache.org Delivered-To: apmail-sis-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id 0124C19C29 for ; Tue, 24 Mar 2020 09:59:59 +0000 (UTC) Received: (qmail 45652 invoked by uid 500); 24 Mar 2020 09:59:59 -0000 Delivered-To: apmail-sis-commits-archive@sis.apache.org Received: (qmail 45629 invoked by uid 500); 24 Mar 2020 09:59:59 -0000 Mailing-List: contact commits-help@sis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sis-dev@sis.apache.org Delivered-To: mailing list commits@sis.apache.org Received: (qmail 45620 invoked by uid 99); 24 Mar 2020 09:59:59 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Mar 2020 09:59:59 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id DB6A6819F7; Tue, 24 Mar 2020 09:59:58 +0000 (UTC) Date: Tue, 24 Mar 2020 09:59:58 +0000 To: "commits@sis.apache.org" Subject: =?utf-8?q?=5Bsis=5D_branch_geoapi-4=2E0_updated=3A_Add_a_Feature?= =?utf-8?q?s=2EgetLinkTarget=28=E2=80=A6=29_method_for_determining_if_a_Pr?= =?utf-8?q?opertyType_is_a_link=2E?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <158504399865.19515.1232446210216410667@gitbox.apache.org> From: desruisseaux@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: sis X-Git-Refname: refs/heads/geoapi-4.0 X-Git-Reftype: branch X-Git-Oldrev: e1988800464b8ad4b0f06c49c1f4f7fd7f03b212 X-Git-Newrev: 976898a4f2dbcf7d6e129158ec4db98e9b9fc406 X-Git-Rev: 976898a4f2dbcf7d6e129158ec4db98e9b9fc406 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 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 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 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 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. *