jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1360710 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: api/ core/ kernel/ plugins/lucene/ plugins/name/ plugins/type/ plugins/value/ query/ast/ util/
Date Thu, 12 Jul 2012 14:53:44 GMT
Author: jukka
Date: Thu Jul 12 14:53:44 2012
New Revision: 1360710

URL: http://svn.apache.org/viewvc?rev=1360710&view=rev
Log:
OAK-184: Allow PropertyState.getValues() to work on single-valued properties

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/PropertyState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/PropertyStateImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/AnnotatingConflictHandler.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ConflictValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Iterators.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/PropertyState.java?rev=1360710&r1=1360709&r2=1360710&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/PropertyState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/PropertyState.java
Thu Jul 12 14:53:44 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.api;
 
+import java.util.List;
+
 import javax.annotation.Nonnull;
 
 /**
@@ -54,11 +56,14 @@ public interface PropertyState {
     CoreValue getValue();
 
     /**
-     * Values of this property.
-     * @return  an iterable of the values of this multi valued property.
-     * @throws IllegalStateException  if {@code isArray()} is {@code false}.
+     * Values of this property. The returned list is immutable and contains
+     * all the values of this property. If this is a single-valued property,
+     * then the returned list will simply contain the single value returned
+     * by the {@link #getValue()} method.
+     *
+     * @return immutable list of the values of this property
      */
     @Nonnull
-    Iterable<CoreValue> getValues();
+    List<CoreValue> getValues();
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java?rev=1360710&r1=1360709&r2=1360710&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
Thu Jul 12 14:53:44 2012
@@ -28,7 +28,6 @@ import org.apache.jackrabbit.oak.api.Cha
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.ConflictHandler;
 import org.apache.jackrabbit.oak.api.ConflictHandler.Resolution;
-import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
@@ -46,7 +45,6 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
 import static org.apache.jackrabbit.oak.commons.PathUtils.getName;
 import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath;
-import static org.apache.jackrabbit.oak.util.Iterators.toList;
 
 public class RootImpl implements Root {
     static final Logger log = LoggerFactory.getLogger(RootImpl.class);
@@ -426,10 +424,8 @@ public class RootImpl implements Root {
 
             private void setProperty(Tree target, PropertyState property) {
                 if (property.isArray()) {
-                    target.setProperty(property.getName(),
-                            toList(property.getValues(), new ArrayList<CoreValue>()));
-                }
-                else {
+                    target.setProperty(property.getName(), property.getValues());
+                } else {
                     target.setProperty(property.getName(), property.getValue());
                 }
             }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/PropertyStateImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/PropertyStateImpl.java?rev=1360710&r1=1360709&r2=1360710&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/PropertyStateImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/PropertyStateImpl.java
Thu Jul 12 14:53:44 2012
@@ -22,30 +22,30 @@ import org.apache.jackrabbit.oak.api.Cor
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.plugins.memory.MemoryValueFactory;
 
+import java.util.Arrays;
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.List;
 
 public class PropertyStateImpl implements PropertyState {
 
     private final String name;
-    private final CoreValue value;
-    private final List<CoreValue> values;
 
-    private PropertyStateImpl(String name, CoreValue value, List<CoreValue> values)
{
-        assert name != null;
+    private final boolean array;
 
-        this.name = name;
-        this.value = value;
-        this.values = values;
-    }
+    private final CoreValue[] values;
 
     public PropertyStateImpl(String name, CoreValue value) {
-        this(name, value, null);
+        assert name != null && value != null;
+        this.name = name;
+        this.array = false;
+        this.values = new CoreValue[] { value };
     }
 
     public PropertyStateImpl(String name, List<CoreValue> values) {
-        this(name, null, Collections.unmodifiableList(values));
+        assert name != null && values != null;
+        this.name = name;
+        this.array = true;
+        this.values = values.toArray(new CoreValue[values.size()]);
     }
 
     public PropertyStateImpl(String name, String value) {
@@ -59,23 +59,20 @@ public class PropertyStateImpl implement
 
     @Override
     public boolean isArray() {
-        return value == null;
+        return array;
     }
-    
+
     @Override
     public CoreValue getValue() {
-        if (value == null) {
+        if (array) {
             throw new IllegalStateException("Not a single valued property");
         }
-        return value;
+        return values[0];
     }
 
     @Override
-    public Iterable<CoreValue> getValues() {
-        if (values == null) {
-            throw new IllegalStateException("Not a multi valued property");
-        }
-        return values;
+    public List<CoreValue> getValues() {
+        return Collections.unmodifiableList(Arrays.asList(values));
     }
 
     //------------------------------------------------------------< Object >----
@@ -94,7 +91,9 @@ public class PropertyStateImpl implement
             return true;
         } else if (that instanceof PropertyState) {
             PropertyState other = (PropertyState) that;
-            return getName().equals(other.getName()) && valueEquals(other);
+            return getName().equals(other.getName())
+                    && isArray() == other.isArray()
+                    && getValues().equals(other.getValues());
         } else {
             return false;
         }
@@ -119,21 +118,4 @@ public class PropertyStateImpl implement
         return getName() + '=' + (isArray() ? getValues() : getValue());
     }
 
-    //------------------------------------------------------------< private >---
-
-    private boolean valueEquals(PropertyState other) {
-        if (isArray() != other.isArray()) {
-            return false;
-        } else if (isArray()) {
-            Iterator<CoreValue> iterator = other.getValues().iterator();
-            for (CoreValue value : getValues()) {
-                if (!iterator.hasNext() || !value.equals(iterator.next())) {
-                    return false;
-                }
-            }
-            return !iterator.hasNext();
-        } else {
-            return getValue().equals(other.getValue());
-        }
-    }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java?rev=1360710&r1=1360709&r2=1360710&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneEditor.java
Thu Jul 12 14:53:44 2012
@@ -184,12 +184,8 @@ public class LuceneEditor implements Com
                     ":path", path, Store.YES, Index.NOT_ANALYZED));
             for (PropertyState property : state.getProperties()) {
                 String pname = property.getName();
-                if (property.isArray()) {
-                    for (CoreValue value : property.getValues()) {
-                        document.add(makeField(pname, value));
-                    }
-                } else {
-                    document.add(makeField(pname, property.getValue()));
+                for (CoreValue value : property.getValues()) {
+                    document.add(makeField(pname, value));
                 }
             }
             return document;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java?rev=1360710&r1=1360709&r2=1360710&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidator.java
Thu Jul 12 14:53:44 2012
@@ -52,12 +52,8 @@ class NameValidator implements Validator
 
     protected void checkValidValue(PropertyState property)
             throws CommitFailedException {
-        if (property.isArray()) {
-            for (CoreValue value : property.getValues()) {
-                checkValidValue(value);
-            }
-        } else {
-            checkValidValue(property.getValue());
+        for (CoreValue value : property.getValues()) {
+            checkValidValue(value);
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java?rev=1360710&r1=1360709&r2=1360710&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/type/TypeValidator.java
Thu Jul 12 14:53:44 2012
@@ -38,19 +38,16 @@ class TypeValidator implements Validator
 
     private void checkTypeExists(PropertyState after)
             throws CommitFailedException {
-        Iterable<CoreValue> coreValues = Collections.emptyList();
-        if (JcrConstants.JCR_PRIMARYTYPE.equals(after.getName())) {
-            coreValues = Collections.singletonList(after.getValue());
-        } else if (JcrConstants.JCR_MIXINTYPES.equals(after.getName())) {
-            coreValues = after.getValues();
-        }
-        for (CoreValue cv : coreValues) {
-            String value = cv.getString();
-            if (!types.contains(value)) {
-                throw new CommitFailedException(
-                    new NoSuchNodeTypeException("Unknown node type: " + value));
+        if (JcrConstants.JCR_PRIMARYTYPE.equals(after.getName())
+                || JcrConstants.JCR_MIXINTYPES.equals(after.getName())) {
+            for (CoreValue cv : after.getValues()) {
+                String value = cv.getString();
+                if (!types.contains(value)) {
+                    throw new CommitFailedException(
+                        new NoSuchNodeTypeException("Unknown node type: " + value));
+                }
+                // TODO: make sure the specified node type isn't abstract
             }
-            // TODO: make sure the specified node type isn't abstract
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/AnnotatingConflictHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/AnnotatingConflictHandler.java?rev=1360710&r1=1360709&r2=1360710&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/AnnotatingConflictHandler.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/AnnotatingConflictHandler.java
Thu Jul 12 14:53:44 2012
@@ -28,9 +28,6 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.oak.util.Iterators;
-
-import static org.apache.jackrabbit.oak.util.Iterators.toList;
 
 /**
  * This {@link ConflictHandler} implementation resolves conflicts to
@@ -135,7 +132,7 @@ public class AnnotatingConflictHandler i
         List<CoreValue> mixins = new ArrayList<CoreValue>();
         if (jcrMixin != null) {
             assert jcrMixin.isArray();
-            mixins = Iterators.toList(jcrMixin.getValues(), mixins);
+            mixins.addAll(jcrMixin.getValues());
         }
         if (!mixins.contains(MIX_MERGE_CONFLICT)) {
             mixins.add(valueFactory.createValue(MIX_MERGE_CONFLICT, PropertyType.NAME));
@@ -169,10 +166,8 @@ public class AnnotatingConflictHandler i
 
     private static void setProperty(Tree parent, PropertyState property) {
         if (property.isArray()) {
-            parent.setProperty(property.getName(),
-                    toList(property.getValues(), new ArrayList<CoreValue>()));
-        }
-        else {
+            parent.setProperty(property.getName(), property.getValues());
+        } else {
             parent.setProperty(property.getName(), property.getValue());
         }
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ConflictValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ConflictValidator.java?rev=1360710&r1=1360709&r2=1360710&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ConflictValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ConflictValidator.java
Thu Jul 12 14:53:44 2012
@@ -61,8 +61,7 @@ public class ConflictValidator extends D
     private static void failOnMergeConflict(PropertyState property) throws CommitFailedException
{
         if ("jcr:mixinTypes".equals(property.getName())) {
             assert property.isArray();
-            Iterable<CoreValue> mixins = property.getValues();
-            for (CoreValue v : mixins) {
+            for (CoreValue v : property.getValues()) {
                 if ("mix:mergeConflict".equals(v.getString())) {
                     throw new CommitFailedException(new InvalidItemStateException("Item has
unresolved conflicts"));
                 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.java?rev=1360710&r1=1360709&r2=1360710&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/FullTextSearchImpl.java
Thu Jul 12 14:53:44 2012
@@ -75,9 +75,6 @@ public class FullTextSearchImpl extends 
     }
 
     private boolean evaluateContains(PropertyState p) {
-        if (!p.isArray()) {
-            return evaluateContains(p.getValue());
-        }
         for (CoreValue v : p.getValues()) {
             if (evaluateContains(v)) {
                 return true;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Iterators.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Iterators.java?rev=1360710&r1=1360709&r2=1360710&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Iterators.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Iterators.java
Thu Jul 12 14:53:44 2012
@@ -243,19 +243,4 @@ public final class Iterators {
         };
     }
 
-    /**
-     * Spools the values of an iterator into a list.
-     * @param values  the values to spool
-     * @param list  the target list to receive the values
-     * @param <T>
-     * @return  {@code list}
-     */
-    @Nonnull
-    public static <T> List<T> toList(Iterable<? extends T> values, List<T>
list) {
-        for (T value : values) {
-            list.add(value);
-        }
-        return list;
-    }
-
 }



Mime
View raw message