You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by cd...@apache.org on 2009/07/21 00:58:21 UTC
svn commit: r796052 - in /hadoop/common/trunk: CHANGES.txt
src/java/org/apache/hadoop/conf/Configuration.java
src/test/core/org/apache/hadoop/conf/TestConfiguration.java
Author: cdouglas
Date: Mon Jul 20 22:58:21 2009
New Revision: 796052
URL: http://svn.apache.org/viewvc?rev=796052&view=rev
Log:
HADOOP-6161. Add get/setEnum methods to Configuration.
Modified:
hadoop/common/trunk/CHANGES.txt
hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/conf/TestConfiguration.java
Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=796052&r1=796051&r2=796052&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Mon Jul 20 22:58:21 2009
@@ -480,6 +480,8 @@
HADOOP-6146. Upgrade to JetS3t version 0.7.1. (tomwhite)
+ HADOOP-6161. Add get/setEnum methods to Configuration. (cdouglas)
+
OPTIMIZATIONS
HADOOP-5595. NameNode does not need to run a replicator to choose a
Modified: hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java?rev=796052&r1=796051&r2=796052&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java Mon Jul 20 22:58:21 2009
@@ -596,6 +596,30 @@
}
/**
+ * Set the value of the <code>name</code> property to the given type. This
+ * is equivalent to <code>set(<name>, value.toString())</code>.
+ * @param name property name
+ * @param value new value
+ */
+ public <T extends Enum<T>> 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 extends Enum<T>> 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/trunk/src/test/core/org/apache/hadoop/conf/TestConfiguration.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/conf/TestConfiguration.java?rev=796052&r1=796051&r2=796052&view=diff
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/conf/TestConfiguration.java (original)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/conf/TestConfiguration.java Mon Jul 20 22:58:21 2009
@@ -327,6 +327,23 @@
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();