Return-Path: Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: (qmail 91991 invoked from network); 4 Mar 2011 03:51:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 Mar 2011 03:51:10 -0000 Received: (qmail 20704 invoked by uid 500); 4 Mar 2011 03:51:10 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 20675 invoked by uid 500); 4 Mar 2011 03:51:10 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 20659 invoked by uid 99); 4 Mar 2011 03:51:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Mar 2011 03:51:10 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Mar 2011 03:51:07 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 31FCC2388B42; Fri, 4 Mar 2011 03:50:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1077195 - in /hadoop/common/branches/branch-0.20-security-patches/src: core/org/apache/hadoop/conf/Configuration.java test/org/apache/hadoop/conf/TestConfiguration.java Date: Fri, 04 Mar 2011 03:50:46 -0000 To: common-commits@hadoop.apache.org From: omalley@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110304035046.31FCC2388B42@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: omalley Date: Fri Mar 4 03:50:45 2011 New Revision: 1077195 URL: http://svn.apache.org/viewvc?rev=1077195&view=rev Log: commit e125e9697d06b231efb478921a0299ef072b9791 Author: Hemanth Yamijala Date: Tue Feb 9 11:10:54 2010 +0530 HADOOP:6161 from http://issues.apache.org/jira/secure/attachment/12434928/hadoop-6161-yahoo-20-v1.patch +++ b/YAHOO-CHANGES.txt + HADOOP-6161. Add get/setEnum methods to Configuration. (cdouglas) + Modified: hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/conf/Configuration.java hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/conf/TestConfiguration.java Modified: hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/conf/Configuration.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/conf/Configuration.java?rev=1077195&r1=1077194&r2=1077195&view=diff ============================================================================== --- hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/conf/Configuration.java (original) +++ hadoop/common/branches/branch-0.20-security-patches/src/core/org/apache/hadoop/conf/Configuration.java Fri Mar 4 03:50:45 2011 @@ -627,6 +627,30 @@ public class Configuration implements It } /** + * Set the value of the name property to the given type. This + * is equivalent to set(<name>, value.toString()). + * @param name property name + * @param value new value + */ + public > void setEnum(String name, T value) { + set(name, value.toString()); + } + + /** + * Return value matching this enumerated type. + * @param name Property name + * @param defaultValue Value returned if no mapping exists + * @throws IllegalArgumentException If mapping is illegal for the type + * provided + */ + public > T getEnum(String name, T defaultValue) { + final String val = get(name); + return null == val + ? defaultValue + : Enum.valueOf(defaultValue.getDeclaringClass(), val); + } + + /** * A class that represents a set of positive integer ranges. It parses * strings of the form: "2-3,5,7-" where ranges are separated by comma and * the lower/upper bounds are separated by dash. Either the lower or upper Modified: hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/conf/TestConfiguration.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/conf/TestConfiguration.java?rev=1077195&r1=1077194&r2=1077195&view=diff ============================================================================== --- hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/conf/TestConfiguration.java (original) +++ hadoop/common/branches/branch-0.20-security-patches/src/test/org/apache/hadoop/conf/TestConfiguration.java Fri Mar 4 03:50:45 2011 @@ -351,6 +351,23 @@ public class TestConfiguration extends T assertEquals(-20, conf.getLong("test.int3", 0)); } + enum Dingo { FOO, BAR }; + enum Yak { RAB, FOO }; + public void testEnum() throws IOException { + Configuration conf = new Configuration(); + conf.setEnum("test.enum", Dingo.FOO); + assertSame(Dingo.FOO, conf.getEnum("test.enum", Dingo.BAR)); + assertSame(Yak.FOO, conf.getEnum("test.enum", Yak.RAB)); + boolean fail = false; + try { + conf.setEnum("test.enum", Dingo.BAR); + Yak y = conf.getEnum("test.enum", Yak.FOO); + } catch (IllegalArgumentException e) { + fail = true; + } + assertTrue(fail); + } + public void testReload() throws IOException { out=new BufferedWriter(new FileWriter(CONFIG)); startConfig();