jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1324698 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/ oak-core/src/main/java/org/apache/jackrabbit/oak/util/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ oak-jcr/src/main/java/org/apache/jackr...
Date Wed, 11 Apr 2012 11:03:12 GMT
Author: mduerig
Date: Wed Apr 11 11:03:11 2012
New Revision: 1324698

URL: http://svn.apache.org/viewvc?rev=1324698&view=rev
Log:
OAK-15: Clean up oak-jcr
move iterator utilities to oak-core

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Function1.java
      - copied, changed from r1324672, jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/Function1.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Iterators.java
      - copied, changed from r1324672, jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/Iterators.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/PagedIterator.java
      - copied, changed from r1324672, jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/PagedIterator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Predicate.java
      - copied, changed from r1324672, jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/Predicate.java
Removed:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/Function0.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/Function1.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/Iterators.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/PagedIterator.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/Predicate.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/TransientKernelNodeState.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/TransientKernelNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/TransientKernelNodeState.java?rev=1324698&r1=1324697&r2=1324698&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/TransientKernelNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/TransientKernelNodeState.java
Wed Apr 11 11:03:11 2012
@@ -18,29 +18,27 @@
  */
 package org.apache.jackrabbit.oak.kernel;
 
-import org.apache.commons.collections.iterators.EmptyIterator;
-import org.apache.commons.collections.iterators.FilterIterator;
-import org.apache.commons.collections.iterators.IteratorChain;
-import org.apache.commons.collections.iterators.TransformIterator;
 import org.apache.jackrabbit.oak.api.ChildNodeEntry;
 import org.apache.jackrabbit.oak.api.NodeState;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.TransientNodeState;
-import org.apache.jackrabbit.oak.kernel.TransientKernelNodeState.Iterators.PagedIterator;
+import org.apache.jackrabbit.oak.util.Function1;
+import org.apache.jackrabbit.oak.util.Iterators;
+import org.apache.jackrabbit.oak.util.PagedIterator;
+import org.apache.jackrabbit.oak.util.Predicate;
 
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.NoSuchElementException;
 import java.util.Set;
 
-import static org.apache.jackrabbit.oak.kernel.TransientKernelNodeState.Iterators.Function1;
-import static org.apache.jackrabbit.oak.kernel.TransientKernelNodeState.Iterators.Predicate;
-import static org.apache.jackrabbit.oak.kernel.TransientKernelNodeState.Iterators.add;
-import static org.apache.jackrabbit.oak.kernel.TransientKernelNodeState.Iterators.filter;
-import static org.apache.jackrabbit.oak.kernel.TransientKernelNodeState.Iterators.map;
+import static org.apache.jackrabbit.oak.util.Iterators.chain;
+import static org.apache.jackrabbit.oak.util.Iterators.empty;
+import static org.apache.jackrabbit.oak.util.Iterators.filter;
+import static org.apache.jackrabbit.oak.util.Iterators.flatten;
+import static org.apache.jackrabbit.oak.util.Iterators.map;
 
 public class TransientKernelNodeState implements TransientNodeState {
     /** Editor acting upon this instance */
@@ -258,15 +256,15 @@ public class TransientKernelNodeState im
 
                 // persisted states - removed states
                 Iterator<PropertyState> persistedMinusRemoved =
-                    filter(properties, new Predicate<PropertyState>() {
-                        @Override
-                        public boolean evaluate(PropertyState state) {
-                            return !removed.contains(state.getName());
-                        }
-                });
+                        filter(properties, new Predicate<PropertyState>() {
+                            @Override
+                            public boolean evaluate(PropertyState state) {
+                                return !removed.contains(state.getName());
+                            }
+                        });
 
                 // persisted states - removed states + added states
-                return add(persistedMinusRemoved, added.iterator());
+                return chain(persistedMinusRemoved, added.iterator());
             }
         };
     }
@@ -298,7 +296,7 @@ public class TransientKernelNodeState im
                         public boolean evaluate(ChildNodeEntry entry) {
                             return !removed.contains(entry.getName());
                         }
-                });
+                    });
 
                 // persisted states - removed states
                 Iterator<TransientNodeState> persistedMinusRemoved =
@@ -308,10 +306,10 @@ public class TransientKernelNodeState im
                             public TransientNodeState apply(ChildNodeEntry entry) {
                                 return getExistingChildNode(entry.getName());
                             }
-                });
+                        });
 
                 // persisted states - removed states + added states
-                return add(persistedMinusRemoved, added.iterator());
+                return chain(persistedMinusRemoved, added.iterator());
             }
         };
     }
@@ -460,10 +458,10 @@ public class TransientKernelNodeState im
             final NodeState persistentState) {
 
         if (persistentState == null) {
-            return Iterators.empty();
+            return empty();
         }
         else {
-            return Iterators.flatten(
+            return flatten(
                 new PagedIterator<ChildNodeEntry>(1024) {
                     @Override
                     protected Iterator<? extends ChildNodeEntry> getPage(long pos,
int size) {
@@ -473,201 +471,4 @@ public class TransientKernelNodeState im
         }
     }
 
-    // TODO: move to a more suitable location
-    static final class Iterators {
-        private Iterators() { }
-
-        /**
-         * Returns an empty iterator of type {@code T}.
-         *
-         * @param <T>
-         * @return
-         */
-        @SuppressWarnings("unchecked")
-        public static <T> Iterator<T> empty() {
-            return EmptyIterator.INSTANCE;
-        }
-
-        /**
-         * Returns an iterator for the concatenation of {@code iterator1} and
-         * {@code iterator2}.
-         *
-         * @param <T>
-         * @param iterator1
-         * @param iterator2
-         * @return
-         */
-        @SuppressWarnings("unchecked")
-        public static <T> Iterator<T> add(Iterator<? extends T> iterator1,
-                Iterator<? extends T> iterator2) {
-
-            return new IteratorChain(iterator1, iterator2);
-        }
-
-        /**
-         * Returns an iterator containing only the elements from an original
-         * {@code iterator} where the given {@code predicate} matches.
-         *
-         * @param <T>
-         * @param iterator
-         * @param predicate
-         * @return
-         */
-        @SuppressWarnings("unchecked")
-        public static <T> Iterator<T> filter(Iterator<? extends T> iterator,
-                final Predicate<? super T> predicate) {
-
-            return new FilterIterator(iterator, new org.apache.commons.collections.Predicate()
{
-                @Override
-                public boolean evaluate(Object object) {
-                    return predicate.evaluate((T) object);
-                }
-            });
-        }
-
-        /**
-         * Returns an iterator with elements of an original  {@code iterator} mapped by
-         * a function {@code f}.
-         *
-         * @param <T>
-         * @param <R>
-         * @param <S>
-         * @param iterator
-         * @param f
-         * @return
-         */
-        @SuppressWarnings("unchecked")
-        public static <T, R, S extends T> Iterator<R> map(Iterator<? extends
T> iterator,
-                final Function1<S, ? super R> f) {
-
-            return new TransformIterator(iterator, new org.apache.commons.collections.Transformer()
{
-                @Override
-                public Object transform(Object input) {
-                    return f.apply((S) input);
-                }
-            });
-        }
-
-        /**
-         * Type safe counter part of {@link org.apache.commons.collections.Predicate}.
-         *
-         * @param <T> type of values this predicate is defined on
-         */
-        interface Predicate<T> {
-            boolean evaluate(T arg);
-        }
-
-        /**
-         * Type safe counter part of {@link org.apache.commons.collections.Transformer}.
-         *
-         * @param <S>  argument type to transform from
-         * @param <T>  result type to transform to
-         */
-        public interface Function1<S, T> {
-            T apply(S argument);
-        }
-
-        /**
-         * Flattens an iterator of iterators into a single iterator.
-         * @param iterators
-         * @param <T>
-         * @return
-         */
-        public static <T> Iterator<? extends T> flatten(
-                final Iterator<Iterator<? extends T>> iterators) {
-
-            return new Iterator<T>() {
-                private Iterator<? extends T> current;
-
-                @Override
-                public boolean hasNext() {
-                    if (current != null && current.hasNext()) {
-                        return true;
-                    }
-                    else if (!iterators.hasNext()) {
-                        return false;
-                    }
-                    else {
-                        do {
-                            current = iterators.next();
-                        } while (!current.hasNext() && iterators.hasNext());
-                        return current.hasNext();
-                    }
-                }
-
-                @Override
-                public T next() {
-                    if (!hasNext()) {
-                        throw new NoSuchElementException();
-                    }
-
-                    return current.next();
-                }
-
-                @Override
-                public void remove() {
-                    if (current == null) {
-                        throw new IllegalStateException();
-                    }
-
-                    current.remove();
-                }
-            };
-        }
-
-        /**
-         * A {@code PagedIterator} is an iterator of several pages. A page itself is
-         * an iterator. The abstract {@code getPage} method is called whenever this
-         * iterator needs to fetch another page.<p/>
-         *
-         * Lazy flattening (e.g. with {@link Iterators#flatten(java.util.Iterator)}
-         * results in an iterator which does batch reading from its back end.
-         *
-         * @param <T>
-         */
-        public abstract static class PagedIterator<T>
-                implements Iterator<Iterator<? extends T>> {
-
-            private final int pageSize;
-            private long pos;
-            private Iterator<? extends T> current;
-
-            protected PagedIterator(int pageSize) {
-                this.pageSize = pageSize;
-            }
-
-            /**
-             * @param pos  start index
-             * @param size  maximal number of elements
-             * @return  iterator starting at index {@code pos} containing at most {@code
size} elements.
-             */
-            protected abstract Iterator<? extends T> getPage(long pos, int size);
-
-            @Override
-            public boolean hasNext() {
-                if (current == null) {
-                    current = getPage(pos, pageSize);
-                    pos += pageSize;
-                }
-
-                return current.hasNext();
-            }
-
-            @Override
-            public Iterator<? extends T> next() {
-                if (!hasNext()) {
-                    throw new NoSuchElementException();
-                }
-                Iterator<? extends T> e = current;
-                current = null;
-                return e;
-            }
-
-            @Override
-            public void remove() {
-                throw new UnsupportedOperationException("remove");
-            }
-        }
-
-    }
 }

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Function1.java
(from r1324672, jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/Function1.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Function1.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Function1.java&p1=jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/Function1.java&r1=1324672&r2=1324698&rev=1324698&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/Function1.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Function1.java
Wed Apr 11 11:03:11 2012
@@ -14,7 +14,7 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package org.apache.jackrabbit.oak.jcr.util;
+package org.apache.jackrabbit.oak.util;
 
 /**
  * Type safe counter part of {@link org.apache.commons.collections.Transformer}.

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Iterators.java
(from r1324672, jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/Iterators.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Iterators.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Iterators.java&p1=jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/Iterators.java&r1=1324672&r2=1324698&rev=1324698&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/Iterators.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Iterators.java
Wed Apr 11 11:03:11 2012
@@ -14,7 +14,7 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package org.apache.jackrabbit.oak.jcr.util;
+package org.apache.jackrabbit.oak.util;
 
 import org.apache.commons.collections.iterators.ArrayIterator;
 import org.apache.commons.collections.iterators.EmptyIterator;

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/PagedIterator.java
(from r1324672, jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/PagedIterator.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/PagedIterator.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/PagedIterator.java&p1=jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/PagedIterator.java&r1=1324672&r2=1324698&rev=1324698&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/PagedIterator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/PagedIterator.java
Wed Apr 11 11:03:11 2012
@@ -17,7 +17,7 @@
  * under the License.
  */
 
-package org.apache.jackrabbit.oak.jcr.util;
+package org.apache.jackrabbit.oak.util;
 
 import java.util.Iterator;
 import java.util.NoSuchElementException;
@@ -27,7 +27,7 @@ import java.util.NoSuchElementException;
  * an iterator. The abstract {@code getPage} method is called whenever this
  * iterator needs to fetch another page.<p/>
  *
- * Lazy flattening (e.g. with {@link org.apache.jackrabbit.oak.jcr.util.Iterators#flatten(java.util.Iterator)}
+ * Lazy flattening (e.g. with {@link Iterators#flatten(java.util.Iterator)}
  * results in an iterator which does batch reading from its back end.
  *
  * @param <T>

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Predicate.java
(from r1324672, jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/Predicate.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Predicate.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Predicate.java&p1=jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/Predicate.java&r1=1324672&r2=1324698&rev=1324698&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/util/Predicate.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/Predicate.java
Wed Apr 11 11:03:11 2012
@@ -14,7 +14,7 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package org.apache.jackrabbit.oak.jcr.util;
+package org.apache.jackrabbit.oak.util;
 
 /**
  * Type safe counter part of {@link org.apache.commons.collections.Predicate}.

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1324698&r1=1324697&r2=1324698&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Wed Apr 11 11:03:11 2012
@@ -23,11 +23,11 @@ import org.apache.jackrabbit.mk.util.Pat
 import org.apache.jackrabbit.oak.api.NodeStateEditor;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.TransientNodeState;
-import org.apache.jackrabbit.oak.jcr.util.Function1;
+import org.apache.jackrabbit.oak.util.Function1;
 import org.apache.jackrabbit.oak.jcr.util.ItemNameMatcher;
-import org.apache.jackrabbit.oak.jcr.util.Iterators;
+import org.apache.jackrabbit.oak.util.Iterators;
 import org.apache.jackrabbit.oak.jcr.util.LogUtil;
-import org.apache.jackrabbit.oak.jcr.util.Predicate;
+import org.apache.jackrabbit.oak.util.Predicate;
 import org.apache.jackrabbit.oak.jcr.util.ValueConverter;
 import org.apache.jackrabbit.oak.kernel.ScalarImpl;
 import org.apache.jackrabbit.value.ValueHelper;
@@ -59,7 +59,7 @@ import java.math.BigDecimal;
 import java.util.Calendar;
 import java.util.Iterator;
 
-import static org.apache.jackrabbit.oak.jcr.util.Iterators.filter;
+import static org.apache.jackrabbit.oak.util.Iterators.filter;
 
 /**
  * {@code NodeImpl}...



Mime
View raw message