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 D156E200D29 for ; Thu, 12 Oct 2017 00:21:41 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id CFD40160BE3; Wed, 11 Oct 2017 22:21:41 +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 2057D1609E5 for ; Thu, 12 Oct 2017 00:21:40 +0200 (CEST) Received: (qmail 16169 invoked by uid 500); 11 Oct 2017 22:21:40 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 16160 invoked by uid 99); 11 Oct 2017 22:21:40 -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, 11 Oct 2017 22:21:40 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 093F7DF9F1; Wed, 11 Oct 2017 22:21:40 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: asuresh@apache.org To: common-commits@hadoop.apache.org Message-Id: <5ca6fbc66acb403e8a840c10478d532d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hadoop git commit: HADOOP-13556. Change Configuration.getPropsWithPrefix to use getProps instead of iterator. (Larry McCay via asuresh) Date: Wed, 11 Oct 2017 22:21:40 +0000 (UTC) archived-at: Wed, 11 Oct 2017 22:21:42 -0000 Repository: hadoop Updated Branches: refs/heads/trunk 8acdf5c27 -> b6c2c9058 HADOOP-13556. Change Configuration.getPropsWithPrefix to use getProps instead of iterator. (Larry McCay via asuresh) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/b6c2c905 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/b6c2c905 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/b6c2c905 Branch: refs/heads/trunk Commit: b6c2c9058e83116dcca46cd6934db3428f931347 Parents: 8acdf5c Author: Arun Suresh Authored: Wed Oct 11 15:21:21 2017 -0700 Committer: Arun Suresh Committed: Wed Oct 11 15:21:21 2017 -0700 ---------------------------------------------------------------------- .../java/org/apache/hadoop/conf/Configuration.java | 9 ++++++--- .../org/apache/hadoop/conf/TestConfiguration.java | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/b6c2c905/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java index 2890853..9d5bb1b 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java @@ -2700,11 +2700,14 @@ public class Configuration implements Iterable>, * @return mapping of configuration properties with prefix stripped */ public Map getPropsWithPrefix(String confPrefix) { + Properties props = getProps(); + Enumeration e = props.propertyNames(); Map configMap = new HashMap<>(); - for (Map.Entry entry : this) { - String name = entry.getKey(); + String name = null; + while (e.hasMoreElements()) { + name = (String) e.nextElement(); if (name.startsWith(confPrefix)) { - String value = this.get(name); + String value = props.getProperty(name); name = name.substring(confPrefix.length()); configMap.put(name, value); } http://git-wip-us.apache.org/repos/asf/hadoop/blob/b6c2c905/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java index a806b8c..52215da 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java @@ -2242,6 +2242,21 @@ public class TestConfiguration { FileUtil.fullyDelete(tmpDir); } + public void testGettingPropertiesWithPrefix() throws Exception { + Configuration conf = new Configuration(); + for (int i = 0; i < 10; i++) { + conf.set("prefix" + ".name" + i, "value"); + } + conf.set("different.prefix" + ".name", "value"); + Map props = conf.getPropsWithPrefix("prefix"); + assertEquals(props.size(), 10); + + // test call with no properties for a given prefix + props = conf.getPropsWithPrefix("none"); + assertNotNull(props.isEmpty()); + assertTrue(props.isEmpty()); + } + public static void main(String[] argv) throws Exception { junit.textui.TestRunner.main(new String[]{ TestConfiguration.class.getName() --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org