jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1400045 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core: OrderedChildrenEditor.java TreeImpl.java
Date Fri, 19 Oct 2012 11:27:12 GMT
Author: mduerig
Date: Fri Oct 19 11:27:12 2012
New Revision: 1400045

URL: http://svn.apache.org/viewvc?rev=1400045&view=rev
Log:
OAK-389: Simplify code by using PropertyBuilder

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/OrderedChildrenEditor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/OrderedChildrenEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/OrderedChildrenEditor.java?rev=1400045&r1=1400044&r2=1400045&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/OrderedChildrenEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/OrderedChildrenEditor.java
Fri Oct 19 11:27:12 2012
@@ -16,23 +16,20 @@
  */
 package org.apache.jackrabbit.oak.core;
 
-import java.util.Set;
-
 import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryPropertyBuilder;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.DefaultNodeStateDiff;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateUtils;
-
-import com.google.common.collect.Sets;
+import org.apache.jackrabbit.oak.spi.state.PropertyBuilder;
 
 import static org.apache.jackrabbit.oak.core.TreeImpl.OAK_CHILD_ORDER;
 
@@ -96,27 +93,20 @@ public class OrderedChildrenEditor imple
         private void updateChildOrder() {
             PropertyState childOrder = builder.getProperty(OAK_CHILD_ORDER);
             if (childOrder != null) {
-                Set<String> children = Sets.newLinkedHashSet();
-                for (int i = 0; i < childOrder.count(); i++) {
-                    String name = childOrder.getValue(Type.STRING, i);
-                    // ignore hidden
-                    if (NodeStateUtils.isHidden(name)) {
-                        continue;
-                    }
-                    if (builder.hasChildNode(name)) {
-                        children.add(name);
+                PropertyBuilder<String> children = MemoryPropertyBuilder.create(Type.STRING,
childOrder);
+                // Remove removed
+                for (String name : children.getValues()) {
+                    if (NodeStateUtils.isHidden(name) || !builder.hasChildNode(name)) {
+                        children.removeValue(name);
                     }
                 }
-                // make sure we have all
+                // Add added
                 for (String name : builder.getChildNodeNames()) {
-                    // ignore hidden
-                    if (NodeStateUtils.isHidden(name)) {
-                        continue;
+                    if (!NodeStateUtils.isHidden(name) && !children.hasValue(name))
{
+                        children.addValue(name);
                     }
-                    // will only add it if not yet present in set
-                    children.add(name);
                 }
-                builder.setProperty(PropertyStates.stringProperty(OAK_CHILD_ORDER, children));
+                builder.setProperty(children.getPropertyState(true));
             }
         }
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java?rev=1400045&r1=1400044&r2=1400045&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
Fri Oct 19 11:27:12 2012
@@ -26,22 +26,22 @@ import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.collect.Iterables;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.TreeLocation;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.core.RootImpl.PurgeListener;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryPropertyBuilder;
 import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
 
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.collect.Iterables;
-
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
@@ -266,11 +266,10 @@ public class TreeImpl implements Tree, P
         if (!hasChild(name)) {
             getNodeBuilder().child(name);
             if (hasOrderableChildren()) {
-                getNodeBuilder().setProperty(PropertyStates.stringProperty(
-                        OAK_CHILD_ORDER,
-                        Iterables.concat(
-                                getOrderedChildNames(),
-                                Collections.singleton(name))));
+                getNodeBuilder().setProperty(
+                        MemoryPropertyBuilder.create(Type.STRING, internalGetProperty(OAK_CHILD_ORDER))
+                                .addValue(name)
+                                .getPropertyState(true));
             }
             root.purge();
         }
@@ -292,14 +291,11 @@ public class TreeImpl implements Tree, P
             parent.children.remove(name);
             removed = true;
             if (parent.hasOrderableChildren()) {
-                builder.setProperty(PropertyStates.stringProperty(
-                        OAK_CHILD_ORDER,
-                        Iterables.filter(parent.getOrderedChildNames(), new Predicate<String>()
{
-                            @Override
-                            public boolean apply(@Nullable String input) {
-                                return !name.equals(input);
-                            }
-                        })));
+                builder.setProperty(
+                        MemoryPropertyBuilder.create(Type.STRING, parent.internalGetProperty(OAK_CHILD_ORDER))
+                                .removeValue(name)
+                                .getPropertyState(true)
+                );
             }
             root.purge();
             return true;



Mime
View raw message