harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhouke...@apache.org
Subject svn commit: r899035 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Properties.java test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java
Date Thu, 14 Jan 2010 02:46:50 GMT
Author: zhoukevin
Date: Thu Jan 14 02:46:49 2010
New Revision: 899035

URL: http://svn.apache.org/viewvc?rev=899035&view=rev
Log:
Fix a bug of sequence of return from Properties.propertyNames() method

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Properties.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Properties.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Properties.java?rev=899035&r1=899034&r2=899035&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Properties.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Properties.java Thu
Jan 14 02:46:49 2010
@@ -17,9 +17,9 @@
 
 package java.util;
 
+import java.io.BufferedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.BufferedInputStream;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.PrintStream;
@@ -34,19 +34,17 @@
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 
+import org.apache.harmony.luni.internal.nls.Messages;
+import org.apache.harmony.luni.util.PriviAction;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
 import org.xml.sax.EntityResolver;
 import org.xml.sax.ErrorHandler;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
 
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
-import org.apache.harmony.luni.internal.nls.Messages;
-import org.apache.harmony.luni.util.PriviAction;
-
 /**
  * A {@code Properties} object is a {@code Hashtable} where the keys and values
  * must be {@code String}s. Each property can have a default
@@ -455,22 +453,16 @@
      *         that this {@code Properties} object contains.
      */
     public Enumeration<?> propertyNames() {
-        if (defaults == null) {
-            return keys();
-        }
+        Hashtable<Object, Object> selected = new Hashtable<Object, Object>();
+        selectProperties(selected);
+        return selected.keys();
+    }
 
-        Hashtable<Object, Object> set = new Hashtable<Object, Object>(defaults
-                .size()
-                + size());
-        Enumeration<?> keys = defaults.propertyNames();
-        while (keys.hasMoreElements()) {
-            set.put(keys.nextElement(), set);
-        }
-        keys = keys();
-        while (keys.hasMoreElements()) {
-            set.put(keys.nextElement(), set);
+    private void selectProperties(Hashtable<Object, Object> selected) {
+        if(defaults != null) {
+            defaults.selectProperties(selected);
         }
-        return set.keys();
+        selected.putAll(this);
     }
 
     /**

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java?rev=899035&r1=899034&r2=899035&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/PropertiesTest.java
Thu Jan 14 02:46:49 2010
@@ -304,6 +304,41 @@
         }
     }
 
+    public void test_propertyNames_sequence() {
+        Properties parent = new Properties();
+        parent.setProperty("parent.a.key", "parent.a.value");
+        parent.setProperty("parent.b.key", "parent.b.value");
+
+        Enumeration<?> names = parent.propertyNames();
+        assertEquals("parent.a.key", names.nextElement());
+        assertEquals("parent.b.key", names.nextElement());
+        assertFalse(names.hasMoreElements());
+
+        Properties current = new Properties(parent);
+        current.setProperty("current.a.key", "current.a.value");
+        current.setProperty("current.b.key", "current.b.value");
+
+        names = current.propertyNames();
+        assertEquals("parent.a.key", names.nextElement());
+        assertEquals("current.b.key", names.nextElement());
+        assertEquals("parent.b.key", names.nextElement());
+        assertEquals("current.a.key", names.nextElement());
+        assertFalse(names.hasMoreElements());
+
+        Properties child = new Properties(current);
+        child.setProperty("child.a.key", "child.a.value");
+        child.setProperty("child.b.key", "child.b.value");
+
+        names = child.propertyNames();
+        assertEquals("parent.a.key", names.nextElement());
+        assertEquals("child.b.key", names.nextElement());
+        assertEquals("current.b.key", names.nextElement());
+        assertEquals("parent.b.key", names.nextElement());
+        assertEquals("child.a.key", names.nextElement());
+        assertEquals("current.a.key", names.nextElement());
+        assertFalse(names.hasMoreElements());
+    }
+
     /**
 
      * @tests java.util.Properties#save(java.io.OutputStream, java.lang.String)



Mime
View raw message