felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1650469 - in /felix/trunk/utils/src: main/java/org/apache/felix/utils/properties/Properties.java test/java/org/apache/felix/utils/properties/PropertiesTest.java
Date Fri, 09 Jan 2015 09:49:28 GMT
Author: gnodet
Date: Fri Jan  9 09:49:27 2015
New Revision: 1650469

URL: http://svn.apache.org/r1650469
Log:
[FELIX-4761] Modifications on Properties#entrySet() are not properly reflected in the layout

Modified:
    felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/Properties.java
    felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java

Modified: felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/Properties.java
URL: http://svn.apache.org/viewvc/felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/Properties.java?rev=1650469&r1=1650468&r2=1650469&view=diff
==============================================================================
--- felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/Properties.java (original)
+++ felix/trunk/utils/src/main/java/org/apache/felix/utils/properties/Properties.java Fri
Jan  9 09:49:27 2015
@@ -32,9 +32,11 @@ import java.net.URL;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.AbstractMap;
+import java.util.AbstractSet;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Enumeration;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Locale;
@@ -202,7 +204,47 @@ public class Properties extends Abstract
 
     @Override
     public Set<Entry<String, String>> entrySet() {
-        return storage.entrySet();
+        return new AbstractSet<Entry<String, String>>() {
+            @Override
+            public Iterator<Entry<String, String>> iterator() {
+                return new Iterator<Entry<String, String>>() {
+                    final Iterator<Entry<String, String>> keyIterator = storage.entrySet().iterator();
+                    Entry<String, String> entry;
+                    public boolean hasNext() {
+                        return keyIterator.hasNext();
+                    }
+                    public Entry<String, String> next() {
+                        entry = keyIterator.next();
+                        return new Entry<String, String>() {
+                            public String getKey() {
+                                return entry.getKey();
+                            }
+                            public String getValue() {
+                                return entry.getValue();
+                            }
+                            public String setValue(String value) {
+                                String old = entry.setValue(value);
+                                if (old == null || !old.equals(value)) {
+                                    Layout l = layout.get(entry.getKey());
+                                    if (l != null) {
+                                        l.clearValue();
+                                    }
+                                }
+                                return old;
+                            }
+                        };
+                    }
+                    public void remove() {
+                        keyIterator.remove();
+                    }
+                };
+            }
+
+            @Override
+            public int size() {
+                return storage.size();
+            }
+        };
     }
 
     /**
@@ -283,6 +325,15 @@ public class Properties extends Abstract
         return result;
     }
 
+    public List<String> getComments(String key) {
+        if (layout.containsKey(key)) {
+            if (layout.get(key).getCommentLines() != null) {
+                return new ArrayList<String>(layout.get(key).getCommentLines());
+            }
+        }
+        return new ArrayList<String>();
+    }
+
     @Override
     public String remove(Object key) {
         Layout l = layout.get(key);

Modified: felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java?rev=1650469&r1=1650468&r2=1650469&view=diff
==============================================================================
--- felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java
(original)
+++ felix/trunk/utils/src/test/java/org/apache/felix/utils/properties/PropertiesTest.java
Fri Jan  9 09:49:27 2015
@@ -16,6 +16,8 @@
  */
 package org.apache.felix.utils.properties;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringReader;
@@ -238,4 +240,27 @@ public class PropertiesTest extends Test
         assertEquals(KEY1A + " = " + VALUE1 + "\\", rawValue.get(0));
         assertEquals(VALUE1, rawValue.get(1));
     }
+
+    public void testEntrySetValue() throws Exception {
+        properties.put(KEY1, VALUE1);
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        properties.save(baos);
+
+        properties = new Properties();
+        properties.load(new ByteArrayInputStream(baos.toByteArray()));
+        assertEquals(VALUE1, properties.get(KEY1));
+        for (Map.Entry<String, String> entry : properties.entrySet()) {
+            entry.setValue(entry.getValue() + "x");
+        }
+        assertEquals(VALUE1 + "x", properties.get(KEY1));
+
+        baos = new ByteArrayOutputStream();
+        properties.save(baos);
+
+        properties = new Properties();
+        properties.load(new ByteArrayInputStream(baos.toByteArray()));
+        assertEquals(VALUE1 + "x", properties.get(KEY1));
+    }
+
 }



Mime
View raw message