jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1170681 - in /jackrabbit/sandbox/jackrabbit-mk: jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/ jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/benchmark/ jackrabbit-spi-commons/src/main/java/org/apache/jackr...
Date Wed, 14 Sep 2011 15:22:02 GMT
Author: mduerig
Date: Wed Sep 14 15:22:01 2011
New Revision: 1170681

URL: http://svn.apache.org/viewvc?rev=1170681&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP) 
refactor: consolidate Function et all

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/benchmark/ReadPerformanceTest.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ItemInfoBuilder.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/iterator/Iterators.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/iterator/Predicate.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/iterator/Predicates.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/iterator/Transformer.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Predicate1.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Predicates.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java?rev=1170681&r1=1170680&r2=1170681&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/GetItemsTest.java
Wed Sep 14 15:22:01 2011
@@ -27,7 +27,7 @@ import org.apache.jackrabbit.spi.QNodeDe
 import org.apache.jackrabbit.spi.RepositoryService;
 import org.apache.jackrabbit.spi.SessionInfo;
 import org.apache.jackrabbit.spi.commons.ItemInfoBuilder.NodeInfoBuilder;
-import org.apache.jackrabbit.spi.commons.iterator.Predicate;
+import org.apache.jackrabbit.spi.commons.util.Predicate1;
 
 import javax.jcr.AccessDeniedException;
 import javax.jcr.Item;
@@ -43,8 +43,8 @@ import static org.apache.jackrabbit.spi.
 import static org.apache.jackrabbit.spi.commons.iterator.Iterators.singleton;
 
 /**
- * Test cases for {@link RepositoryService#getItemInfos(SessionInfo, NodeId)}. Specifically
- * for JCR-1797.
+ * Test cases for {@link RepositoryService#getItemInfos(org.apache.jackrabbit.spi.SessionInfo,
org.apache.jackrabbit.spi.ItemId)}
+ * Specifically for JCR-1797.
  */
 public class GetItemsTest extends AbstractJCR2SPITest {
     private Session session;
@@ -155,8 +155,9 @@ public class GetItemsTest extends Abstra
         
         return iteratorChain(
                 singleton(itemInfoStore.getItemInfo(itemId)),
-                filterIterator(itemInfoStore.getItemInfos(), new Predicate<ItemInfo>()
{
-                    public boolean evaluate(ItemInfo info) {
+                filterIterator(itemInfoStore.getItemInfos(), new Predicate1<ItemInfo>()
{
+                    @Override
+                    public Boolean apply(ItemInfo info) {
                         return !itemId.equals(info.getId());
                     }
                 }));

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/benchmark/ReadPerformanceTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/benchmark/ReadPerformanceTest.java?rev=1170681&r1=1170680&r2=1170681&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/benchmark/ReadPerformanceTest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/benchmark/ReadPerformanceTest.java
Wed Sep 14 15:22:01 2011
@@ -31,7 +31,7 @@ import org.apache.jackrabbit.spi.Session
 import org.apache.jackrabbit.spi.commons.ItemInfoBuilder.NodeInfoBuilder;
 import org.apache.jackrabbit.spi.commons.ItemInfoBuilder.PropertyInfoBuilder;
 import org.apache.jackrabbit.spi.commons.ItemInfoCacheImpl;
-import org.apache.jackrabbit.spi.commons.iterator.Predicate;
+import org.apache.jackrabbit.spi.commons.util.Predicate1;
 
 import javax.jcr.Item;
 import javax.jcr.ItemNotFoundException;
@@ -84,8 +84,8 @@ public class ReadPerformanceTest extends
 
     /**
      * Ratios of the number of items in the whole content tree compared to the number of
items
-     * in a batch of a {@link RepositoryService#getItemInfos(SessionInfo, NodeId)} call.
-     * The array contains one ratio per run
+     * in a batch of a {@link RepositoryService#getItemInfos(org.apache.jackrabbit.spi.SessionInfo,
org.apache.jackrabbit.spi.ItemId)}
+     * call. The array contains one ratio per run
      */
     private static int[] BATCH_RATIOS = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048,
4096, 8192, 16384};
 
@@ -304,8 +304,9 @@ public class ReadPerformanceTest extends
     }
 
     private Iterator<ItemInfo> getBatch() {
-        return filterIterator(itemInfoStore.getItemInfos(), new Predicate<ItemInfo>()
{
-            public boolean evaluate(ItemInfo value) {
+        return filterIterator(itemInfoStore.getItemInfos(), new Predicate1<ItemInfo>()
{
+            @Override
+            public Boolean apply(ItemInfo value) {
                 return rnd.nextInt(batchRatio) == 0;
             }
         });

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ItemInfoBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ItemInfoBuilder.java?rev=1170681&r1=1170680&r2=1170681&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ItemInfoBuilder.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ItemInfoBuilder.java
Wed Sep 14 15:22:01 2011
@@ -27,11 +27,11 @@ import org.apache.jackrabbit.spi.Propert
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.commons.identifier.IdFactoryImpl;
 import org.apache.jackrabbit.spi.commons.iterator.Iterators;
-import org.apache.jackrabbit.spi.commons.iterator.Predicate;
-import org.apache.jackrabbit.spi.commons.iterator.Transformer;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
 import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
+import org.apache.jackrabbit.spi.commons.util.Function1;
+import org.apache.jackrabbit.spi.commons.util.Predicate1;
 import org.apache.jackrabbit.spi.commons.value.QValueFactoryImpl;
 
 import javax.jcr.PropertyType;
@@ -445,15 +445,15 @@ public final class ItemInfoBuilder {
 
         private Iterator<ChildInfo> getChildInfos() {
             return transformIterator(filterIterator(itemInfos.iterator(),
-                    new Predicate<ItemInfo>(){
+                    new Predicate1<ItemInfo>(){
                         @Override
-                        public boolean evaluate(ItemInfo info) {
+                        public Boolean apply(ItemInfo info) {
                             return info.denotesNode();
                         }
                     }),
-                    new Transformer<ItemInfo, ChildInfo>(){
+                    new Function1<ItemInfo, ChildInfo>(){
                         @Override
-                        public ChildInfo transform(ItemInfo info) {
+                        public ChildInfo apply(ItemInfo info) {
                             return new ChildInfoImpl(
                                     info.getPath().getName(), null,
                                     Path.INDEX_DEFAULT);
@@ -463,15 +463,15 @@ public final class ItemInfoBuilder {
 
         private Iterator<PropertyId> getPropertyIds() {
             return transformIterator(filterIterator(itemInfos.iterator(),
-                    new Predicate<ItemInfo>(){
+                    new Predicate1<ItemInfo>(){
                         @Override
-                        public boolean evaluate(ItemInfo info) {
+                        public Boolean apply(ItemInfo info) {
                             return !info.denotesNode();
                         }
                     }),
-                    new Transformer<ItemInfo, PropertyId>(){
+                    new Function1<ItemInfo, PropertyId>(){
                         @Override
-                        public PropertyId transform(ItemInfo info) {
+                        public PropertyId apply(ItemInfo info) {
                             return (PropertyId) info.getId();
                         }
                     });

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/iterator/Iterators.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/iterator/Iterators.java?rev=1170681&r1=1170680&r2=1170681&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/iterator/Iterators.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/iterator/Iterators.java
Wed Sep 14 15:22:01 2011
@@ -22,13 +22,14 @@ import org.apache.commons.collections.it
 import org.apache.commons.collections.iterators.IteratorChain;
 import org.apache.commons.collections.iterators.SingletonIterator;
 import org.apache.commons.collections.iterators.TransformIterator;
+import org.apache.jackrabbit.spi.commons.util.Function1;
+import org.apache.jackrabbit.spi.commons.util.Predicate1;
 import org.apache.jackrabbit.spi.commons.util.Unchecked;
 
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.Property;
 import javax.jcr.PropertyIterator;
-
 import java.util.Collection;
 import java.util.Iterator;
 
@@ -123,12 +124,17 @@ public final class Iterators {
      * @return
      */
     public static <T> Iterator<T> filterIterator(Iterator<? extends T>
iterator,
-            final Predicate<? super T> predicate) {
+            final Predicate1<? super T> predicate) {
 
         return cast(new FilterIterator(iterator, new org.apache.commons.collections.Predicate()
{
             @Override
             public boolean evaluate(Object object) {
-                return predicate.evaluate(Unchecked.<T>cast(object));
+                try {
+                    return predicate.apply(Unchecked.<T>cast(object));
+                }
+                catch (Exception e) {
+                    throw new IllegalArgumentException("Predicate may not throw exceptions",
e);
+                }
             }
         }));
     }
@@ -145,12 +151,17 @@ public final class Iterators {
      * @return
      */
     public static <T, R, S extends T> Iterator<R> transformIterator(Iterator<?
extends T> iterator,
-            final Transformer<S, ? super R> transformer) {
+            final Function1<S, ? super R> transformer) {
 
         return cast(new TransformIterator(iterator, new org.apache.commons.collections.Transformer()
{
             @Override
             public Object transform(Object input) {
-                return transformer.transform(Unchecked.<S>cast(input));
+                try {
+                    return transformer.apply(Unchecked.<S>cast(input));
+                }
+                catch (Exception e) {
+                    throw new IllegalArgumentException("Transformer may not throw exceptions",
e);
+                }
             }
         }));
     }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Predicate1.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Predicate1.java?rev=1170681&r1=1170680&r2=1170681&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Predicate1.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Predicate1.java
Wed Sep 14 15:22:01 2011
@@ -19,5 +19,10 @@
 
 package org.apache.jackrabbit.spi.commons.util;
 
+/**
+ * Type safe counter part of {@link org.apache.commons.collections.Predicate}.
+ *
+ * @param <T> type of values this predicate is defined on
+ */
 public interface Predicate1<T> extends Function1<T, Boolean> {
 }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Predicates.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Predicates.java?rev=1170681&r1=1170680&r2=1170681&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Predicates.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/util/Predicates.java
Wed Sep 14 15:22:01 2011
@@ -21,10 +21,55 @@ package org.apache.jackrabbit.spi.common
 
 import java.util.Iterator;
 
+import static org.apache.jackrabbit.spi.commons.util.Unchecked.cast;
+
+/**
+ * Utility class containing pre defined {@link Predicate1}s and predicate functions
+ */
 public final class Predicates {
+
+    /**
+     * A predicate which is always true
+     */
+    public static final Predicate1<?> TRUE = new Predicate1() {
+        @Override
+        public Boolean apply(Object arg) {
+            return true;
+        }
+    };
+
+    /**
+     * A predicate which is always false
+     */
+    public static final Predicate1<?> FALSE = new Predicate1() {
+        @Override
+        public Boolean apply(Object arg) {
+            return false;
+        }
+    };
+
     private Predicates() {}
 
-    public static <T> boolean exists(Function1<T, Boolean> predicate, Iterator<T>
iterator) throws Exception {
+    /**
+     * A predicate which is always true
+     * @param <T>
+     * @return
+     */
+    public static <T> Predicate1<T> TRUE() {
+        return cast(TRUE);
+    }
+
+    /**
+     * A predicate which is always false
+     * @param <T>
+     * @return
+     */
+    public static <T> Predicate1<T> FALSE() {
+        return cast(FALSE);
+    }
+
+
+    public static <T> boolean exists(Predicate1<T> predicate, Iterator<T>
iterator) throws Exception {
         while (iterator.hasNext()) {
             if (predicate.apply(iterator.next())) {
                 return true;

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1170681&r1=1170680&r2=1170681&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Wed Sep 14 15:22:01 2011
@@ -52,10 +52,9 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.SessionInfoImpl;
 import org.apache.jackrabbit.spi.commons.batch.ConsolidatingChangeLog;
 import org.apache.jackrabbit.spi.commons.iterator.Iterators;
-import org.apache.jackrabbit.spi.commons.iterator.Predicate;
-import org.apache.jackrabbit.spi.commons.iterator.Transformer;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.util.Function1;
+import org.apache.jackrabbit.spi.commons.util.Predicate1;
 import org.json.simple.parser.JSONParser;
 import org.json.simple.parser.ParseException;
 import org.slf4j.Logger;
@@ -125,8 +124,8 @@ import static org.apache.jackrabbit.spi.
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_PRIMARYTYPE;
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.REP_ROOT;
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.ROOT;
-import static org.apache.jackrabbit.spi2microkernel.ItemInfos.buildItemInfos;
 import static org.apache.jackrabbit.spi.commons.util.Maps.getOrElse;
+import static org.apache.jackrabbit.spi2microkernel.ItemInfos.buildItemInfos;
 
 public class RepositoryServiceImpl extends AbstractRepositoryService {
     private static final long BINARY_VALUE_INLINE_THRESHOLD = 0x1000;
@@ -413,9 +412,9 @@ public class RepositoryServiceImpl exten
         final IdFactory idFactory = getIdFactory();
         final String wspName = sessionInfo.getWorkspaceName();
 
-        Iterator<PropertyId> propertyIds = Iterators.transformIterator(paths, new Transformer<String,
PropertyId>() {
+        Iterator<PropertyId> propertyIds = Iterators.transformIterator(paths, new Function1<String,
PropertyId>() {
             @Override
-            public PropertyId transform(String pathString) {
+            public PropertyId apply(String pathString) {
                 try {
                     pathString = PathUtils.concat("/", PathUtils.relativize('/' + wspName,
pathString));
                     Path path = Paths.stringToPath(pathString);
@@ -433,9 +432,9 @@ public class RepositoryServiceImpl exten
             return propertyIds;
         }
         else {
-            return Iterators.filterIterator(propertyIds, new Predicate<PropertyId>()
{
+            return Iterators.filterIterator(propertyIds, new Predicate1<PropertyId>()
{
                 @Override
-                public boolean evaluate(PropertyId propertyId) {
+                public Boolean apply(PropertyId propertyId) {
                     return propertyName.equals(propertyId.getName());
                 }
             });



Mime
View raw message