From commits-return-13919-apmail-sis-commits-archive=sis.apache.org@sis.apache.org Wed Sep 23 10:01:54 2020 Return-Path: X-Original-To: apmail-sis-commits-archive@www.apache.org Delivered-To: apmail-sis-commits-archive@www.apache.org Received: from mailroute1-lw-us.apache.org (mailroute1-lw-us.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with ESMTP id 8356F1ABFB for ; Wed, 23 Sep 2020 10:01:54 +0000 (UTC) Received: from mail.apache.org (localhost [127.0.0.1]) by mailroute1-lw-us.apache.org (ASF Mail Server at mailroute1-lw-us.apache.org) with SMTP id 31B81122EAC for ; Wed, 23 Sep 2020 10:01:54 +0000 (UTC) Received: (qmail 67016 invoked by uid 500); 23 Sep 2020 10:01:54 -0000 Delivered-To: apmail-sis-commits-archive@sis.apache.org Received: (qmail 66988 invoked by uid 500); 23 Sep 2020 10:01:53 -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 66979 invoked by uid 99); 23 Sep 2020 10:01:53 -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; Wed, 23 Sep 2020 10:01:53 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id B0E158DCA0; Wed, 23 Sep 2020 10:01:53 +0000 (UTC) Date: Wed, 23 Sep 2020 10:01:53 +0000 To: "commits@sis.apache.org" Subject: [sis] branch geoapi-4.0 updated: fix(Feature): slight improvement on feature type builder: automatically replace primitive value class of attributes by their boxed equivalent MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <160085531365.5965.16012367020060384319@gitbox.apache.org> From: amanin@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: 19057895adc19583c8d5e4d17fff935b3525c5fa X-Git-Newrev: de1ac2537b2a6dd28e79bfd00939042134076b03 X-Git-Rev: de1ac2537b2a6dd28e79bfd00939042134076b03 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. amanin 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 de1ac25 fix(Feature): slight improvement on feature type builder: automatically replace primitive value class of attributes by their boxed equivalent de1ac25 is described below commit de1ac2537b2a6dd28e79bfd00939042134076b03 Author: Alexis Manin AuthorDate: Wed Sep 23 11:31:25 2020 +0200 fix(Feature): slight improvement on feature type builder: automatically replace primitive value class of attributes by their boxed equivalent Keeping primitive value class was breaking value affectation, because only primitive values where accepted, but only boxed values could be given (as method signature accepts Object). --- .../sis/feature/builder/FeatureTypeBuilder.java | 6 ++++- .../feature/builder/AttributeTypeBuilderTest.java | 28 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java b/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java index 29ed49a..ebdd3d3 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java +++ b/core/sis-feature/src/main/java/org/apache/sis/feature/builder/FeatureTypeBuilder.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Locale; import java.util.Set; import java.util.Objects; +import org.apache.sis.util.Numbers; import org.opengis.util.NameSpace; import org.opengis.util.GenericName; import org.opengis.util.NameFactory; @@ -676,12 +677,15 @@ public class FeatureTypeBuilder extends TypeBuilder { * * @see #properties() */ - public AttributeTypeBuilder addAttribute(final Class valueClass) { + public AttributeTypeBuilder addAttribute(Class valueClass) { ensureNonNull("valueClass", valueClass); if (Feature.class.isAssignableFrom(valueClass)) { // We disallow Feature.class because that type shall be handled as association instead than attribute. throw new IllegalArgumentException(errors().getString(Errors.Keys.IllegalArgumentValue_2, "valueClass", valueClass)); } + + valueClass = (Class) Numbers.primitiveToWrapper(valueClass); + final AttributeTypeBuilder property = new AttributeTypeBuilder<>(this, valueClass); properties.add(property); clearCache(); diff --git a/core/sis-feature/src/test/java/org/apache/sis/feature/builder/AttributeTypeBuilderTest.java b/core/sis-feature/src/test/java/org/apache/sis/feature/builder/AttributeTypeBuilderTest.java index b709322..1ae4a64 100644 --- a/core/sis-feature/src/test/java/org/apache/sis/feature/builder/AttributeTypeBuilderTest.java +++ b/core/sis-feature/src/test/java/org/apache/sis/feature/builder/AttributeTypeBuilderTest.java @@ -20,6 +20,11 @@ import java.util.Arrays; import java.util.Set; import java.util.Collections; import com.esri.core.geometry.Geometry; +import org.opengis.feature.Attribute; +import org.opengis.feature.Feature; +import org.opengis.feature.FeatureType; +import org.opengis.feature.Property; +import org.opengis.feature.PropertyType; import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.apache.sis.referencing.CommonCRS; import org.apache.sis.internal.feature.AttributeConvention; @@ -240,4 +245,27 @@ public final strictfp class AttributeTypeBuilderTest extends TestCase { assertTrue("isEmpty", roles.isEmpty()); assertFalse("remove(IDENTIFIER_COMPONENT)", roles.remove(AttributeRole.IDENTIFIER_COMPONENT)); } + + @Test + public void testBoxing() { + final FeatureTypeBuilder ftb = new FeatureTypeBuilder().setName("boxing"); + final AttributeTypeBuilder boxBuilder = ftb.addAttribute(int.class).setName("boxed"); + assertEquals("Attribute value type should have been boxed", Integer.class, boxBuilder.getValueClass()); + + final FeatureType ft = ftb.build(); + final PropertyType boxedProperty = ft.getProperty("boxed"); + assertTrue(boxedProperty instanceof AttributeType); + assertEquals("Attribute value type should have been boxed", Integer.class, ((AttributeType)boxedProperty).getValueClass()); + final Feature feature = ft.newInstance(); + + final Property p = feature.getProperty("boxed"); + assertTrue(p instanceof Attribute); + assertEquals("Attribute value type should have been boxed", Integer.class, ((Attribute) p).getType().getValueClass()); + int value = 3; + ((Attribute) p).setValue(value); + assertEquals(3, p.getValue()); + + feature.setPropertyValue("boxed", Integer.valueOf(4)); + assertEquals(4, feature.getPropertyValue("boxed")); + } }