You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2010/09/23 15:09:19 UTC

svn commit: r1000450 - /incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/PropertiesImpl.java

Author: fmui
Date: Thu Sep 23 13:09:18 2010
New Revision: 1000450

URL: http://svn.apache.org/viewvc?rev=1000450&view=rev
Log:
bug fix: PropertiesImpl: each property should be unique within the set of properties, even if a property is added more than once (last add wins)

Modified:
    incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/PropertiesImpl.java

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/PropertiesImpl.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/PropertiesImpl.java?rev=1000450&r1=1000449&r2=1000450&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/PropertiesImpl.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/dataobjects/PropertiesImpl.java Thu Sep 23 13:09:18 2010
@@ -21,6 +21,7 @@ package org.apache.chemistry.opencmis.co
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -71,14 +72,39 @@ public class PropertiesImpl extends Abst
      *            the property
      */
     public void addProperty(PropertyData<?> property) {
-        if (property == null) {
+        if ((property == null) || (property.getId() == null)) {
             return;
         }
 
+        removeProperty(property.getId());
+
         propertyList.add(property);
         properties.put(property.getId(), property);
     }
 
+    /**
+     * Removes a property.
+     * 
+     * @param id
+     *            the property id
+     */
+    public void removeProperty(String id) {
+        if (id == null) {
+            return;
+        }
+
+        Iterator<PropertyData<?>> iterator = propertyList.iterator();
+        while (iterator.hasNext()) {
+            PropertyData<?> property = iterator.next();
+            if (id.equals(property.getId())) {
+                iterator.remove();
+                break;
+            }
+        }
+
+        properties.remove(id);
+    }
+
     @Override
     public String toString() {
         return "Properties Data [properties=" + propertyList + "]" + super.toString();