jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1299739 - in /jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit: state/ utils/
Date Mon, 12 Mar 2012 17:05:55 GMT
Author: mduerig
Date: Mon Mar 12 17:05:54 2012
New Revision: 1299739

URL: http://svn.apache.org/viewvc?rev=1299739&view=rev
Log:
Microkernel based prototype of JCR implementation (WIP)
- Javadoc, comments 

Modified:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/EmptyNodeState.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientNodeState.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Arrays.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Function0.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Predicates.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Unchecked.java

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/EmptyNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/EmptyNodeState.java?rev=1299739&r1=1299738&r2=1299739&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/EmptyNodeState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/EmptyNodeState.java
Mon Mar 12 17:05:54 2012
@@ -26,6 +26,10 @@ import org.apache.jackrabbit.utils.Itera
 
 import java.util.Iterator;
 
+/**
+ * A {@code NodeState} implementation which is empty. That is, does not
+ * have properties nor child nodes.
+ */
 public final class EmptyNodeState extends AbstractNodeState {
     public static final EmptyNodeState INSTANCE = new EmptyNodeState();
     

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java?rev=1299739&r1=1299738&r2=1299739&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/PersistentNodeState.java
Mon Mar 12 17:05:54 2012
@@ -40,11 +40,27 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+/**
+ * A {@code NodeState} implementation on top of a {@code MicroKernel}.
+ */
 public class PersistentNodeState extends AbstractNodeState {
     private final MicroKernel microkernel;
     private final String revision;
     private final Path path;
-    
+
+    /**
+     * Create a new {@code NodeState} instance for the given {@code path} and {@code revision}.
+     *
+     * @param microkernel
+     * @param path
+     * @param revision
+     */
+    public PersistentNodeState(MicroKernel microkernel, Path path, String revision) {
+        this.microkernel = microkernel;
+        this.path = path;
+        this.revision = revision;
+    }
+
     private final Function0<Map<String, PropertyStateImpl>> properties =
         new Function0<Map<String, PropertyStateImpl>>() {
             private Map<String, PropertyStateImpl> properties;
@@ -57,13 +73,7 @@ public class PersistentNodeState extends
                 return properties;
             }
     };
-    
-    PersistentNodeState(MicroKernel microkernel, Path path, String revision) {
-        this.microkernel = microkernel;
-        this.path = path;
-        this.revision = revision;
-    }
-    
+
     @Override
     public PropertyState getProperty(String name) {
         return properties.apply().get(name);
@@ -98,7 +108,7 @@ public class PersistentNodeState extends
 
     @Override
     public Iterable<? extends ChildNodeEntry> getChildNodeEntries(final long offset,
final long length) {
-        // fixme: microkernel should also use long for length
+        // fixme: microkernel should also use long for length (OAK-10)
         String json = microkernel.getNodes(path.toMkPath(), revision, 1, offset, (int) length,
null);
         final List<ChildNodeEntry> childNodeEntries = new ArrayList<ChildNodeEntry>();
 

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientNodeState.java?rev=1299739&r1=1299738&r2=1299739&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientNodeState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/TransientNodeState.java
Mon Mar 12 17:05:54 2012
@@ -41,6 +41,10 @@ import static org.apache.jackrabbit.util
 import static org.apache.jackrabbit.utils.Iterators.flatten;
 import static org.apache.jackrabbit.utils.Iterators.map;
 
+/**
+ * A {@code TransientNodeState} instance uses a {@code TransientSpace} to record changes
+ * to a {@code PersistedNodeState}.
+ */
 public class TransientNodeState {
     private static final long BATCH_SIZE = 256;
 
@@ -55,37 +59,70 @@ public class TransientNodeState {
         this.nodeDelta = nodeDelta;
     }
 
+    /**
+     * @return {@code true} iff this is the root node
+     */
     public boolean isRoot() {
         return getPath().isRoot();
     }
 
+    /**
+     * @return the path of this node
+     */
     public Path getPath() {
         return getNodeDelta().getPath();
     }
 
+    /**
+     * @return the name of this node
+     */
     public String getName() {
         return getPath().getName();
     }
 
+    /**
+     * @return {@code true} iff this node has been transiently added.
+     */
     public boolean isNew() {
         NodeDelta delta = getNodeDelta();
         return delta.isTransient() && !delta.isRemoved();
     }
 
+    /**
+     * @return {@code true} iff this node has been transiently modified.
+     */
     public boolean isModified() {
         return getNodeDelta().isTransient();
     }
 
+    /**
+     * Transiently add a node with the given {@code name}.
+     * @param name
+     * @return the added node
+     * @throws ItemExistsException if a node with that name exists already.
+     */
     public TransientNodeState addNode(String name) throws ItemExistsException {
         NodeDelta child = getNodeDelta().addNode(name);
         return getNodeState(child);
     }
 
+    /**
+     * Transiently remove this node.
+     * @throws ItemNotFoundException if this node has been removed already
+     */
     public void remove() throws ItemNotFoundException {
         getNodeStateProvider().release(getPath());
         getNodeDelta().getParent().removeNode(getName());
     }
 
+    /**
+     * Transiently move this node.
+     * @param name  name of this node at its {@code destination}
+     * @param destination
+     * @throws ItemExistsException  {@code name} exists at {@code destination}
+     * @throws PathNotFoundException  {@code destination} does not exist
+     * @throws ItemNotFoundException  {@code name} does not exist
+     */
     public void move(String name, Path destination) throws ItemExistsException, PathNotFoundException,
             ItemNotFoundException {
 
@@ -93,14 +130,26 @@ public class TransientNodeState {
         getNodeStateProvider().release(getPath().concat(name));
     }
 
+    /**
+     * Transiently set a property.
+     * @param name  Name of the property.
+     * @param value  Value of the property. Use {@code null} or {@code JsonAtom.NULL}
+     *               to remove the property.
+     */
     public void setProperty(String name, JsonValue value) {
         getNodeDelta().setValue(name, value);
     }
 
+    /**
+     * @return {@code true} iff this instance has child nodes.
+     */
     public boolean hasNodes() {
         return getNodes().hasNext();
     }
 
+    /**
+     * @return Iterator of all child node states of this instance.
+     */
     public Iterator<TransientNodeState> getNodes() {
         Iterator<? extends ChildNodeEntry> persistedEntries = flatten(
             new PagedIterator<ChildNodeEntry>(BATCH_SIZE) {
@@ -140,10 +189,16 @@ public class TransientNodeState {
         return chain(unmodifiedStates, modifiedStates);
     }
 
+    /**
+     * @return {@code true} iff this instance has properties
+     */
     public boolean hasProperties() {
         return getProperties().hasNext();
     }
 
+    /**
+     * @return Iterator of all property states of this instance.
+     */
     public Iterator<PropertyState> getProperties() {
         Iterable<? extends PropertyState> propertyStates = getPersistentNodeState().getProperties();
         final NodeDelta delta = getNodeDelta();
@@ -161,6 +216,11 @@ public class TransientNodeState {
         return chain(propertyEntries, delta.getPropertyStates());
     }
 
+    /**
+     * @param name  name of the property
+     * @return  value of the property named {@code name}.
+     * @throws ItemNotFoundException  if no such property exists.
+     */
     public JsonValue getPropertyValue(String name) throws ItemNotFoundException {
         JsonValue value = getPropertyValueOrNull(name);
         if (value == null) {
@@ -170,19 +230,35 @@ public class TransientNodeState {
         return value;
     }
 
+    /**
+     * @param name name of the property
+     * @return {@code true} iff this instance has a property name {@code name}.
+     */
     public boolean hasProperty(String name) {
         return getPropertyValueOrNull(name) != null;
     }
 
+    /**
+     * @param name name of the property
+     * @return {@code true} iff the property named {@code name} has been transiently added.
+     */
     public boolean isPropertyNew(String name) {
         JsonValue value = getNodeDelta().getPropertyValue(name);
         return value != null && !value.isNull() && getPersistedPropertyValue(name)
== null;
     }
 
+    /**
+     * @param name name of the property
+     * @return {@code true} iff the property named {@code name} has been transiently modified.
+     */
     public boolean isPropertyModified(String name) {
         return getNodeDelta().hasProperty(name);
     }
 
+    /**
+     * Transiently remove a property.
+     * @param name  name of the property to remove.
+     */
     public void removeProperty(String name) {
         getNodeDelta().setValue(name, null);
     }

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Arrays.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Arrays.java?rev=1299739&r1=1299738&r2=1299739&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Arrays.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Arrays.java
Mon Mar 12 17:05:54 2012
@@ -24,9 +24,19 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+/**
+ * Utility class providing helper functions for arrays.
+ */
 public final class Arrays {
     private Arrays() {}
 
+    /**
+     * Check whether an array contains a given element
+     * @param array
+     * @param element
+     * @param <T>
+     * @return {@code true} iff {@code array} contains {@code element}.
+     */
     public static <T> boolean contains(T[] array, T element) {
         for (T t : array) {
             if (element == null && t == null || element != null && element.equals(t))
{
@@ -36,16 +46,36 @@ public final class Arrays {
         return false;
     }
 
+    /**
+     * Convert an array to a set.
+     * @param elements
+     * @param <T>
+     * @return
+     */
     public static <T> Set<T> toSet(T... elements) {
         return new HashSet<T>(java.util.Arrays.asList(elements));
     }
 
+    /**
+     * Create a new array of the same type with an additional element added.
+     * @param array
+     * @param value
+     * @param <T>
+     * @return array of {@code array.length + 1} with {@code value} as its last element.
+     */
     public static <T> T[] add(T[] array, T value) {
         T[] copy = java.util.Arrays.copyOf(array, array.length + 1);
         copy[array.length] = value;
         return copy;
     }
-    
+
+    /**
+     * Create a new array with all occurrences of {@code value} removed.
+     * @param array
+     * @param value
+     * @param <T>
+     * @return an array containing all elements of {@code array} except for {@code value}.
+     */
     public static <T> T[] remove(T[] array, T value) {
         List<T> copy = new ArrayList<T>(array.length);
         for (T v : array) {

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Function0.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Function0.java?rev=1299739&r1=1299738&r2=1299739&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Function0.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Function0.java
Mon Mar 12 17:05:54 2012
@@ -19,6 +19,10 @@
 
 package org.apache.jackrabbit.utils;
 
+/**
+ * 0-ary function. That is, a constant.
+ * @param <T>
+ */
 public interface Function0<T> {
     T apply();
 }

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Predicates.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Predicates.java?rev=1299739&r1=1299738&r2=1299739&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Predicates.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Predicates.java
Mon Mar 12 17:05:54 2012
@@ -19,12 +19,26 @@
 
 package org.apache.jackrabbit.utils;
 
+/**
+ * Utility class for handling {@link Predicate}s.
+ */
 public final class Predicates {
+    /** Predicate which always evaluates {@code true} */
     public static final Predicate<?> TRUE = constant(true);
+
+    /** Predicate which always evaluates {@code false} */
     public static final Predicate<?> FALSE = constant(false);
 
     private Predicates() { }
 
+    /**
+     * Predicate which checks whether some element satisfy a predicate.
+     * @param elements
+     * @param predicate
+     * @param <T>
+     * @return {@code true} iff {@code elements} contains an element for which
+     * {@code predicate} evaluates to {@code true}.
+     */
     public static <T> boolean exists(Iterable<T> elements, Predicate<T>
predicate) {
         for (T e : elements) {
             if (predicate.evaluate(e)) {
@@ -34,7 +48,13 @@ public final class Predicates {
 
         return false;
     }
-    
+
+    /**
+     * Predicate which always evaluates to the same truth value.
+     * @param value
+     * @param <T>
+     * @return a predicate which always evaluates to {@code value}.
+     */
     public static <T> Predicate<T> constant(final boolean value) {
         return new Predicate<T>() {
             @Override

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Unchecked.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Unchecked.java?rev=1299739&r1=1299738&r2=1299739&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Unchecked.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/utils/Unchecked.java
Mon Mar 12 17:05:54 2012
@@ -19,6 +19,9 @@
 
 package org.apache.jackrabbit.utils;
 
+/**
+ * Utility class for hiding casts.
+ */
 public final class Unchecked {
     private Unchecked() {}
 



Mime
View raw message