jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1236117 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model: ChildNodeEntriesInlined.java ChildNodeEntriesTree.java
Date Thu, 26 Jan 2012 09:42:37 GMT
Author: stefan
Date: Thu Jan 26 09:42:37 2012
New Revision: 1236117

URL: http://svn.apache.org/viewvc?rev=1236117&view=rev
Log:
flat hierarchy support (WIP)

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesInlined.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesTree.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesInlined.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesInlined.java?rev=1236117&r1=1236116&r2=1236117&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesInlined.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesInlined.java
Thu Jan 26 09:42:37 2012
@@ -213,15 +213,23 @@ public class ChildNodeEntriesInlined imp
         };
     }
 
-    public Iterator<ChildNodeEntry> getModified(final ChildNodeEntries other) {
+    public Iterator<ChildNodeEntry> getModified(ChildNodeEntries other) {
         if (equals(other)) {
             return EMPTY_ITER;
         }
 
-        return new AbstractFilteringIterator<ChildNodeEntry>(entries.values().iterator())
{
+        final ChildNodeEntries cnes1, cnes2;
+        if (other.getCount() < getCount()) {
+            cnes1 = other;
+            cnes2 = this;
+        } else {
+            cnes1 = this;
+            cnes2 = other;
+        }
+        return new AbstractFilteringIterator<ChildNodeEntry>(cnes1.getEntries(0, -1))
{
             @Override
             protected boolean include(ChildNodeEntry entry) {
-                ChildNodeEntry namesake = other.get(entry.getName());
+                ChildNodeEntry namesake = cnes2.get(entry.getName());
                 return (namesake != null && !namesake.getId().equals(entry.getId()));
             }
         };

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesTree.java?rev=1236117&r1=1236116&r2=1236117&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesTree.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/model/ChildNodeEntriesTree.java
Thu Jan 26 09:42:37 2012
@@ -16,12 +16,14 @@
  */
 package org.apache.jackrabbit.mk.model;
 
+import org.apache.jackrabbit.mk.util.AbstractFilteringIterator;
 import org.apache.jackrabbit.mk.util.AbstractRangeIterator;
 import org.apache.jackrabbit.mk.util.EmptyIterator;
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
+import java.util.List;
 
 /**
  *
@@ -80,7 +82,7 @@ public class ChildNodeEntriesTree implem
             return (ChildNodeEntry) entry;
         } else {
             BucketInfo bi = (BucketInfo) entry;
-            ChildNodeEntries entries = retrieveBucket(bi.id);
+            ChildNodeEntries entries = retrieveBucket(bi.getId());
             return entries == null ? null : entries.get(name);
         }
     }
@@ -94,7 +96,6 @@ public class ChildNodeEntriesTree implem
             return new EmptyIterator<String>();
         }
 
-        int skipped = 0;
         if (cnt == -1 || (offset + cnt) > count) {
             cnt = count - offset;
         }
@@ -131,7 +132,7 @@ public class ChildNodeEntriesTree implem
                         list.add((NodeInfo) e);
                     } else {
                         BucketInfo bi = (BucketInfo) e;
-                        ChildNodeEntriesBucket bucket = retrieveBucket(bi.id);
+                        ChildNodeEntriesBucket bucket = retrieveBucket(bi.getId());
                         for (Iterator<ChildNodeEntry> it =
                                      bucket.getEntries(offset - skipped, cnt - list.size());
                              it.hasNext(); ) {
@@ -263,8 +264,62 @@ public class ChildNodeEntriesTree implem
             return EMPTY_ITER;
         }
 
-        // todo implement
-        return null;
+        if (other instanceof ChildNodeEntriesTree) {
+            List<ChildNodeEntry> added = new ArrayList<ChildNodeEntry>();
+            ChildNodeEntriesTree otherEntries = (ChildNodeEntriesTree) other;
+            for (int i = 0; i < index.length; i++) {
+                IndexEntry ie1 = index[i];
+                IndexEntry ie2 = otherEntries.index[i];
+                if (! (ie1 == null ? ie2 == null : ie1.equals(ie2))) {
+                    // index entries aren't equal
+                    if (ie1 == null) {
+                        // this index entry in null => other must be non-null
+                        if (ie2 instanceof NodeInfo) {
+                            added.add((ChildNodeEntry) ie2);    
+                        } else {
+                            BucketInfo bi = (BucketInfo) ie2;
+                            ChildNodeEntriesBucket bucket = retrieveBucket(bi.getId());
+                            for (Iterator<ChildNodeEntry> it = bucket.getEntries(0,
-1);
+                                 it.hasNext(); ) {
+                                added.add(it.next());
+                            }
+                        }
+                    } else if (ie2 != null) {
+                        // both this and other index entry are non-null
+                        ChildNodeEntriesBucket bucket1;
+                        if (ie1 instanceof NodeInfo) {
+                            bucket1 = new ChildNodeEntriesBucket();
+                            bucket1.add((ChildNodeEntry) ie1);
+                        } else {
+                            BucketInfo bi = (BucketInfo) ie1;
+                            bucket1 = retrieveBucket(bi.getId());
+                        }
+                        ChildNodeEntriesBucket bucket2;
+                        if (ie2 instanceof NodeInfo) {
+                            bucket2 = new ChildNodeEntriesBucket();
+                            bucket2.add((ChildNodeEntry) ie2);
+                        } else {
+                            BucketInfo bi = (BucketInfo) ie2;
+                            bucket2 = retrieveBucket(bi.getId());
+                        }
+
+                        for (Iterator<ChildNodeEntry> it = bucket1.getAdded(bucket2);
+                             it.hasNext(); ) {
+                            added.add(it.next());
+                        }
+                    }
+                }
+            }
+            return added.iterator();
+        } else {
+            // todo optimize
+            return new AbstractFilteringIterator<ChildNodeEntry>(other.getEntries(0,
-1)) {
+                @Override
+                protected boolean include(ChildNodeEntry entry) {
+                    return get(entry.getName()) == null;
+                }
+            };
+        }
     }
 
     public Iterator<ChildNodeEntry> getRemoved(final ChildNodeEntries other) {
@@ -272,17 +327,100 @@ public class ChildNodeEntriesTree implem
             return EMPTY_ITER;
         }
 
-        // todo implement
-        return null;
+        if (other instanceof ChildNodeEntriesTree) {
+            List<ChildNodeEntry> removed = new ArrayList<ChildNodeEntry>();
+            ChildNodeEntriesTree otherEntries = (ChildNodeEntriesTree) other;
+            for (int i = 0; i < index.length; i++) {
+                IndexEntry ie1 = index[i];
+                IndexEntry ie2 = otherEntries.index[i];
+                if (! (ie1 == null ? ie2 == null : ie1.equals(ie2))) {
+                    // index entries aren't equal
+                    if (ie2 == null) {
+                        // other index entry in null => this must be non-null
+                        if (ie1 instanceof NodeInfo) {
+                            removed.add((ChildNodeEntry) ie1);
+                        } else {
+                            BucketInfo bi = (BucketInfo) ie1;
+                            ChildNodeEntriesBucket bucket = retrieveBucket(bi.getId());
+                            for (Iterator<ChildNodeEntry> it = bucket.getEntries(0,
-1);
+                                 it.hasNext(); ) {
+                                removed.add(it.next());
+                            }
+                        }
+                    } else if (ie1 != null) {
+                        // both this and other index entry are non-null
+                        ChildNodeEntriesBucket bucket1;
+                        if (ie1 instanceof NodeInfo) {
+                            bucket1 = new ChildNodeEntriesBucket();
+                            bucket1.add((ChildNodeEntry) ie1);
+                        } else {
+                            BucketInfo bi = (BucketInfo) ie1;
+                            bucket1 = retrieveBucket(bi.getId());
+                        }
+                        ChildNodeEntriesBucket bucket2;
+                        if (ie2 instanceof NodeInfo) {
+                            bucket2 = new ChildNodeEntriesBucket();
+                            bucket2.add((ChildNodeEntry) ie2);
+                        } else {
+                            BucketInfo bi = (BucketInfo) ie2;
+                            bucket2 = retrieveBucket(bi.getId());
+                        }
+
+                        for (Iterator<ChildNodeEntry> it = bucket1.getRemoved(bucket2);
+                             it.hasNext(); ) {
+                            removed.add(it.next());
+                        }
+                    }
+                }
+            }
+            return removed.iterator();
+        } else {
+            // todo optimize
+            return new AbstractFilteringIterator<ChildNodeEntry>(getEntries(0, -1))
{
+                @Override
+                protected boolean include(ChildNodeEntry entry) {
+                    return other.get(entry.getName()) == null;
+                }
+            };
+        }
     }
 
-    public Iterator<ChildNodeEntry> getModified(final ChildNodeEntries other) {
+    public Iterator<ChildNodeEntry> getModified(ChildNodeEntries other) {
         if (equals(other)) {
             return EMPTY_ITER;
         }
 
-        // todo implement
-        return null;
+        if (other instanceof ChildNodeEntriesTree) {
+            List<ChildNodeEntry> modified = new ArrayList<ChildNodeEntry>();
+            ChildNodeEntriesTree otherEntries = (ChildNodeEntriesTree) other;
+            for (int i = 0; i < index.length; i++) {
+                IndexEntry ie1 = index[i];
+                IndexEntry ie2 = otherEntries.index[i];
+                if (! (ie1 == null ? ie2 == null : ie1.equals(ie2))) {
+                    // index entries aren't equal
+
+                    // todo implement
+                }
+            }
+
+            return modified.iterator();
+        } else {
+            final ChildNodeEntries cnes1, cnes2;
+            if (other.getCount() < getCount()) {
+                cnes1 = other;
+                cnes2 = this;
+            } else {
+                cnes1 = this;
+                cnes2 = other;
+            }
+            return new AbstractFilteringIterator<ChildNodeEntry>(cnes1.getEntries(0,
-1)) {
+                @Override
+                protected boolean include(ChildNodeEntry entry) {
+                    ChildNodeEntry namesake = cnes2.get(entry.getName());
+                    return (namesake != null && !namesake.getId().equals(entry.getId()));
+                }
+            };
+        }
     }
 
     //-------------------------------------------------------< implementation >



Mime
View raw message