Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 4927D200BDC for ; Wed, 14 Dec 2016 07:49:56 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 47C4E160B33; Wed, 14 Dec 2016 06:49:56 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6BEBA160B13 for ; Wed, 14 Dec 2016 07:49:55 +0100 (CET) Received: (qmail 68216 invoked by uid 500); 14 Dec 2016 06:49:54 -0000 Mailing-List: contact commits-help@beam.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@beam.incubator.apache.org Delivered-To: mailing list commits@beam.incubator.apache.org Received: (qmail 68206 invoked by uid 99); 14 Dec 2016 06:49:54 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Dec 2016 06:49:54 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id E5C05180A48 for ; Wed, 14 Dec 2016 06:49:53 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.219 X-Spam-Level: X-Spam-Status: No, score=-6.219 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id Sl6EstPDIPz7 for ; Wed, 14 Dec 2016 06:49:52 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with SMTP id D0D4E60E3B for ; Wed, 14 Dec 2016 06:49:51 +0000 (UTC) Received: (qmail 65874 invoked by uid 99); 14 Dec 2016 06:48:02 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Dec 2016 06:48:02 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 24DD8F2DCD; Wed, 14 Dec 2016 06:48:02 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: lcwik@apache.org To: commits@beam.incubator.apache.org Date: Wed, 14 Dec 2016 06:48:03 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/3] incubator-beam git commit: Better comments and cleanup archived-at: Wed, 14 Dec 2016 06:49:56 -0000 Better comments and cleanup Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/a0a1fea3 Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/a0a1fea3 Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/a0a1fea3 Branch: refs/heads/master Commit: a0a1fea366849dec8c5dba868a71a1ccdce902eb Parents: ae1d2a3 Author: Vikas Kedigehalli Authored: Tue Dec 13 14:16:16 2016 -0800 Committer: Luke Cwik Committed: Tue Dec 13 22:37:23 2016 -0800 ---------------------------------------------------------------------- .../sdk/options/PipelineOptionsFactory.java | 50 ++++++++++---------- .../sdk/options/PipelineOptionsFactoryTest.java | 1 - 2 files changed, 26 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/a0a1fea3/sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsFactory.java ---------------------------------------------------------------------- diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsFactory.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsFactory.java index 2d013fd..42e1092 100644 --- a/sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsFactory.java +++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsFactory.java @@ -1652,9 +1652,11 @@ public class PipelineOptionsFactory { return convertedOptions; } + /** - * Returns true if the given type is a SIMPLE_TYPES, enum or any of these types in a - * parameterized ValueProvider. + * Returns true if the given type is one of {@code SIMPLE_TYPES} or an enum, or if the given type + * is a {@link ValueProvider ValueProvider<T>} and {@code T} is one of {@code SIMPLE_TYPES} + * or an enum. */ private static boolean isSimpleType(Class type, JavaType genericType) { Class unwrappedType = type.equals(ValueProvider.class) @@ -1663,23 +1665,23 @@ public class PipelineOptionsFactory { } /** - * Returns true if the given type is a any Array or Collection of SIMPLE_TYPES or enum, or - * any of these types in a parameterized ValueProvider. + * Returns true if the given type is an array or {@link Collection} of {@code SIMPLE_TYPES} or + * enums, or if the given type is a {@link ValueProvider ValueProvider<T>} and {@code T} is + * an array or {@link Collection} of {@code SIMPLE_TYPES} or enums. */ private static boolean isCollectionOrArrayOfAllowedTypes(Class type, JavaType genericType) { - Class containerType = type.equals(ValueProvider.class) - ? genericType.containedType(0).getRawClass() : type; + JavaType containerType = type.equals(ValueProvider.class) + ? genericType.containedType(0) : genericType; // Check if it is an array of simple types or enum. - if (containerType.isArray() && (SIMPLE_TYPES.contains(containerType.getComponentType()) - || containerType.getComponentType().isEnum())) { + if (containerType.getRawClass().isArray() + && (SIMPLE_TYPES.contains(containerType.getRawClass().getComponentType()) + || containerType.getRawClass().getComponentType().isEnum())) { return true; } // Check if it is Collection of simple types or enum. - if (Collection.class.isAssignableFrom(containerType)) { - JavaType innerType = type.equals(ValueProvider.class) - ? genericType.containedType(0).containedType(0) - : genericType.containedType(0); + if (Collection.class.isAssignableFrom(containerType.getRawClass())) { + JavaType innerType = containerType.containedType(0); // Note that raw types are allowed, hence the null check. if (innerType == null || SIMPLE_TYPES.contains(innerType.getRawClass()) || innerType.getRawClass().isEnum()) { @@ -1692,8 +1694,10 @@ public class PipelineOptionsFactory { /** * Ensures that empty string value is allowed for a given type. * - *

Empty strings are only allowed for String, String Array, Collection of Strings or any of - * these types in a parameterized ValueProvider. + *

Empty strings are only allowed for {@link String}, {@link String String[]}, + * {@link Collection Collection<String>}, or {@link ValueProvider ValueProvider<T>} + * and {@code T} is of type {@link String}, {@link String String[]}, + * {@link Collection Collection<String>}. * * @param type class object for the type under check. * @param genericType complete type information for the type under check. @@ -1701,16 +1705,14 @@ public class PipelineOptionsFactory { */ private static void checkEmptyStringAllowed(Class type, JavaType genericType, String genericTypeName) { - Class unwrappedType = type.equals(ValueProvider.class) - ? genericType.containedType(0).getRawClass() : type; - - Class containedType = unwrappedType; - if (unwrappedType.isArray()) { - containedType = unwrappedType.getComponentType(); - } else if (Collection.class.isAssignableFrom(unwrappedType)) { - JavaType innerType = type.equals(ValueProvider.class) - ? genericType.containedType(0).containedType(0) - : genericType.containedType(0); + JavaType unwrappedType = type.equals(ValueProvider.class) + ? genericType.containedType(0) : genericType; + + Class containedType = unwrappedType.getRawClass(); + if (unwrappedType.getRawClass().isArray()) { + containedType = unwrappedType.getRawClass().getComponentType(); + } else if (Collection.class.isAssignableFrom(unwrappedType.getRawClass())) { + JavaType innerType = unwrappedType.containedType(0); // Note that raw types are allowed, hence the null check. containedType = innerType == null ? String.class : innerType.getRawClass(); } http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/a0a1fea3/sdks/java/core/src/test/java/org/apache/beam/sdk/options/PipelineOptionsFactoryTest.java ---------------------------------------------------------------------- diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/options/PipelineOptionsFactoryTest.java b/sdks/java/core/src/test/java/org/apache/beam/sdk/options/PipelineOptionsFactoryTest.java index 525b937..d73cad4 100644 --- a/sdks/java/core/src/test/java/org/apache/beam/sdk/options/PipelineOptionsFactoryTest.java +++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/options/PipelineOptionsFactoryTest.java @@ -833,7 +833,6 @@ public class PipelineOptionsFactoryTest { assertEquals(TestEnum.Value, options.getEnumValue().get()); } - @Test public void testStringValueProvider() { String[] args = new String[] {"--stringValue=beam"};