jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1468860 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: plugins/commit/ plugins/memory/ spi/state/
Date Wed, 17 Apr 2013 12:09:07 GMT
Author: jukka
Date: Wed Apr 17 12:09:07 2013
New Revision: 1468860

URL: http://svn.apache.org/r1468860
Log:
OAK-776: NodeState convenience accessors

Add getName() and getNames() to NodeState/Builder

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/AnnotatingConflictHandler.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/AnnotatingConflictHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/AnnotatingConflictHandler.java?rev=1468860&r1=1468859&r2=1468860&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/AnnotatingConflictHandler.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/AnnotatingConflictHandler.java
Wed Apr 17 12:09:07 2013
@@ -18,12 +18,15 @@ package org.apache.jackrabbit.oak.plugin
 
 import java.util.List;
 
+import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.spi.commit.ConflictHandler;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
+import static com.google.common.collect.Iterables.addAll;
+import static com.google.common.collect.Lists.newArrayList;
 import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
 import static org.apache.jackrabbit.oak.api.Type.NAMES;
 import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.ADD_EXISTING;
@@ -117,19 +120,21 @@ public class AnnotatingConflictHandler i
     }
 
     private static NodeBuilder addConflictMarker(NodeBuilder parent) {
-        PropertyState jcrMixin = parent.getProperty(JCR_MIXINTYPES);
-        List<String> mixins;
-        if (jcrMixin == null) {
-            mixins = Lists.newArrayList();
+        List<String> mixins = newArrayList();;
+        boolean hasConflictType = false;
+        Iterable<String> types = parent.getNames(JCR_MIXINTYPES);
+        if (types != null) {
+            for (String type : types) {
+                mixins.add(type);
+                if (MIX_REP_MERGE_CONFLICT.equals(type)) {
+                    hasConflictType = true;
+                }
+            }
         }
-        else {
-            mixins = Lists.newArrayList(jcrMixin.getValue(NAMES));
-        }
-        if (!mixins.contains(MIX_REP_MERGE_CONFLICT)) {
+        if (!hasConflictType) {
             mixins.add(MIX_REP_MERGE_CONFLICT);
             parent.setProperty(JCR_MIXINTYPES, mixins, NAMES);
         }
-
         return parent.child(REP_OURS);
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyNodeState.java?rev=1468860&r1=1468859&r2=1468860&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/EmptyNodeState.java
Wed Apr 17 12:09:07 2013
@@ -71,6 +71,16 @@ public final class EmptyNodeState implem
         return false;
     }
 
+    @Override @CheckForNull
+    public String getName(@Nonnull String name) {
+        return null;
+    }
+
+    @Override @CheckForNull
+    public Iterable<String> getNames(@Nonnull String name) {
+        return null;
+    }
+
     @Override @Nonnull
     public Iterable<? extends PropertyState> getProperties() {
         return Collections.emptyList();
@@ -132,10 +142,18 @@ public final class EmptyNodeState implem
         }
     }
 
+    public static boolean isEmptyState(NodeState state) {
+        return state == EMPTY_NODE || state == MISSING_NODE;
+    }
+
     //------------------------------------------------------------< Object >--
 
     public String toString() {
-        return "{ }";
+        if (exists) {
+            return "{ }";
+        } else {
+            return "{N/A}";
+        }
     }
 
     public boolean equals(Object object) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java?rev=1468860&r1=1468859&r2=1468860&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
Wed Apr 17 12:09:07 2013
@@ -20,6 +20,7 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Map.Entry;
 
+import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.api.PropertyState;
@@ -33,6 +34,9 @@ import org.apache.jackrabbit.oak.spi.sta
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.collect.Maps.newHashMap;
+import static org.apache.jackrabbit.oak.api.Type.BOOLEAN;
+import static org.apache.jackrabbit.oak.api.Type.NAME;
+import static org.apache.jackrabbit.oak.api.Type.NAMES;
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 import static org.apache.jackrabbit.oak.plugins.memory.ModifiedNodeState.with;
 import static org.apache.jackrabbit.oak.plugins.memory.ModifiedNodeState.withNodes;
@@ -425,6 +429,34 @@ public class MemoryNodeBuilder implement
         return read().getProperty(name);
     }
 
+    @Override
+    public boolean getBoolean(String name) {
+        PropertyState property = getProperty(name);
+        return property != null
+                && property.getType() == BOOLEAN
+                && property.getValue(BOOLEAN);
+    }
+
+    @Override @CheckForNull
+    public String getName(@Nonnull String name) {
+        PropertyState property = getProperty(name);
+        if (property != null && property.getType() == NAME) {
+            return property.getValue(NAME);
+        } else {
+            return null;
+        }
+    }
+
+    @Override @CheckForNull
+    public Iterable<String> getNames(@Nonnull String name) {
+        PropertyState property = getProperty(name);
+        if (property != null && property.getType() == NAMES) {
+            return property.getValue(NAMES);
+        } else {
+            return null;
+        }
+    }
+
     @Override @Nonnull
     public NodeBuilder removeProperty(String name) {
         write();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java?rev=1468860&r1=1468859&r2=1468860&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/AbstractNodeState.java
Wed Apr 17 12:09:07 2013
@@ -17,11 +17,16 @@
 package org.apache.jackrabbit.oak.spi.state;
 
 import static org.apache.jackrabbit.oak.api.Type.BOOLEAN;
+import static org.apache.jackrabbit.oak.api.Type.NAME;
+import static org.apache.jackrabbit.oak.api.Type.NAMES;
 
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
 import com.google.common.base.Function;
 import com.google.common.collect.Iterables;
 
@@ -54,6 +59,27 @@ public abstract class AbstractNodeState 
                 && property.getType() == BOOLEAN
                 && property.getValue(BOOLEAN);
     }
+
+    @Override @CheckForNull
+    public String getName(@Nonnull String name) {
+        PropertyState property = getProperty(name);
+        if (property != null && property.getType() == NAME) {
+            return property.getValue(NAME);
+        } else {
+            return null;
+        }
+    }
+
+    @Override @CheckForNull
+    public Iterable<String> getNames(@Nonnull String name) {
+        PropertyState property = getProperty(name);
+        if (property != null && property.getType() == NAMES) {
+            return property.getValue(NAMES);
+        } else {
+            return null;
+        }
+    }
+
     @Override
     public PropertyState getProperty(String name) {
         for (PropertyState property : getProperties()) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java?rev=1468860&r1=1468859&r2=1468860&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
Wed Apr 17 12:09:07 2013
@@ -164,6 +164,57 @@ public interface NodeBuilder {
     PropertyState getProperty(String name);
 
     /**
+     * Returns the boolean value of the named property. The implementation
+     * is equivalent to the following code, but may be optimized.
+     * <pre>
+     * PropertyState property = builder.getProperty(name);
+     * return property != null
+     *     && property.getType() == Type.BOOLEAN
+     *     && property.getValue(Type.BOOLEAN);
+     * </pre>
+     *
+     * @param name property name
+     * @return boolean value of the named property, or {@code false}
+     */
+    boolean getBoolean(@Nonnull String name);
+
+    /**
+     * Returns the name value of the named property. The implementation
+     * is equivalent to the following code, but may be optimized.
+     * <pre>
+     * PropertyState property = builder.getProperty(name);
+     * if (property != null && property.getType() == Type.NAME) {
+     *     return property.getValue(Type.NAME);
+     * } else {
+     *     return null;
+     * }
+     * </pre>
+     *
+     * @param name property name
+     * @return name value of the named property, or {@code null}
+     */
+    @CheckForNull
+    String getName(@Nonnull String name);
+
+    /**
+     * Returns the name values of the named property. The implementation
+     * is equivalent to the following code, but may be optimized.
+     * <pre>
+     * PropertyState property = builder.getProperty(name);
+     * if (property != null && property.getType() == Type.NAMES) {
+     *     return property.getValue(Type.NAMES);
+     * } else {
+     *     return null;
+     * }
+     * </pre>
+     *
+     * @param name property name
+     * @return name values of the named property, or {@code null}
+     */
+    @CheckForNull
+    Iterable<String> getNames(@Nonnull String name);
+
+    /**
      * Set a property state
      * @param property  The property state to set
      * @return this builder

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeState.java?rev=1468860&r1=1468859&r2=1468860&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeState.java
Wed Apr 17 12:09:07 2013
@@ -169,6 +169,42 @@ public interface NodeState {
     boolean getBoolean(@Nonnull String name);
 
     /**
+     * Returns the name value of the named property. The implementation
+     * is equivalent to the following code, but may be optimized.
+     * <pre>
+     * PropertyState property = state.getProperty(name);
+     * if (property != null && property.getType() == Type.NAME) {
+     *     return property.getValue(Type.NAME);
+     * } else {
+     *     return null;
+     * }
+     * </pre>
+     *
+     * @param name property name
+     * @return name value of the named property, or {@code null}
+     */
+    @CheckForNull
+    String getName(@Nonnull String name);
+
+    /**
+     * Returns the name values of the named property. The implementation
+     * is equivalent to the following code, but may be optimized.
+     * <pre>
+     * PropertyState property = state.getProperty(name);
+     * if (property != null && property.getType() == Type.NAMES) {
+     *     return property.getValue(Type.NAMES);
+     * } else {
+     *     return null;
+     * }
+     * </pre>
+     *
+     * @param name property name
+     * @return name values of the named property, or {@code null}
+     */
+    @CheckForNull
+    Iterable<String> getNames(@Nonnull String name);
+
+    /**
      * Returns the number of properties of this node.
      *
      * @return number of properties

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java?rev=1468860&r1=1468859&r2=1468860&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
Wed Apr 17 12:09:07 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.spi.state;
 
+import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.api.PropertyState;
@@ -112,6 +113,21 @@ public class ReadOnlyBuilder implements 
         return state.getProperty(name);
     }
 
+    @Override
+    public boolean getBoolean(String name) {
+        return state.getBoolean(name);
+    }
+
+    @Override @CheckForNull
+    public String getName(@Nonnull String name) {
+        return state.getName(name);
+    }
+
+    @Override @CheckForNull
+    public Iterable<String> getNames(@Nonnull String name) {
+        return state.getNames(name);
+    }
+
     @Override @Nonnull
     public NodeBuilder removeProperty(String name) {
         throw unsupported();



Mime
View raw message