jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From un...@apache.org
Subject svn commit: r1644674 - /jackrabbit/branches/2.8/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java
Date Thu, 11 Dec 2014 15:21:01 GMT
Author: unico
Date: Thu Dec 11 15:21:01 2014
New Revision: 1644674

URL: http://svn.apache.org/r1644674
Log:
JCR-3840 limit the number of null child node definitions to match with to the number of slots
available

Modified:
    jackrabbit/branches/2.8/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java

Modified: jackrabbit/branches/2.8/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.8/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java?rev=1644674&r1=1644673&r2=1644674&view=diff
==============================================================================
--- jackrabbit/branches/2.8/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java
(original)
+++ jackrabbit/branches/2.8/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/nodetype/NodeTypeDefDiff.java
Thu Dec 11 15:21:01 2014
@@ -36,6 +36,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * A <code>NodeTypeDefDiff</code> represents the result of the comparison of
@@ -733,10 +734,18 @@ public class NodeTypeDefDiff {
             });
             // select the most compatible ones
             final int size = defs1.size() > defs2.size() ? defs1.size() : defs2.size();
+            AtomicInteger allowedNewNull = new AtomicInteger(defs1.size() - defs2.size());
+            AtomicInteger allowedOldNull = new AtomicInteger(defs2.size() - defs1.size());
             final List<ChildNodeDefDiff> results = new ArrayList<ChildNodeDefDiff>();
             for (ChildNodeDefDiff diff : diffs) {
-                if (!alreadyMatched(results, diff.getNewDef(), diff.getOldDef())) {
+                if (!alreadyMatched(results, diff.getNewDef(), diff.getOldDef(), allowedNewNull,
allowedOldNull)) {
                     results.add(diff);
+                    if (diff.getNewDef() == null) {
+                        allowedNewNull.decrementAndGet();
+                    }
+                    if (diff.getOldDef() == null) {
+                        allowedOldNull.decrementAndGet();
+                    }
                 }
                 if (results.size() == size) {
                     break;
@@ -745,17 +754,31 @@ public class NodeTypeDefDiff {
             return results;
         }
 
-        private boolean alreadyMatched(final List<ChildNodeDefDiff> result, final QNodeDefinition
newDef, final QNodeDefinition oldDef) {
+        private boolean alreadyMatched(final List<ChildNodeDefDiff> result, final QNodeDefinition
newDef, final QNodeDefinition oldDef, final AtomicInteger allowedNewNull, final AtomicInteger
allowedOldNull) {
             boolean containsNewDef = false, containsOldDef = false;
             for (ChildNodeDefDiff d : result) {
                 if (d.getNewDef() != null && d.getNewDef().equals(newDef)) {
                     containsNewDef = true;
+                    break;
                 }
                 if (d.getOldDef() != null && d.getOldDef().equals(oldDef)) {
                     containsOldDef = true;
+                    break;
+                }
+            }
+            if (oldDef == null) {
+                if (allowedOldNull.get() < 1) {
+                    containsOldDef = true;
+                }
+            }
+            if (newDef == null) {
+                if (allowedNewNull.get() < 1) {
+                    containsNewDef = true;
                 }
             }
+
             return containsNewDef || containsOldDef;
         }
     }
+
 }



Mime
View raw message