You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by md...@apache.org on 2011/09/14 22:52:19 UTC

svn commit: r1170845 - /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ConsolidatingChangeLog.java

Author: mduerig
Date: Wed Sep 14 20:52:18 2011
New Revision: 1170845

URL: http://svn.apache.org/viewvc?rev=1170845&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP) 
refactor: replace int constants with enum

Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ConsolidatingChangeLog.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ConsolidatingChangeLog.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ConsolidatingChangeLog.java?rev=1170845&r1=1170844&r2=1170845&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ConsolidatingChangeLog.java (original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ConsolidatingChangeLog.java Wed Sep 14 20:52:18 2011
@@ -144,19 +144,17 @@ public class ConsolidatingChangeLog exte
         for (OperationsBackwardWithSentinel it = new OperationsBackwardWithSentinel(); it.hasNext(); ) {
             CancelableOperation thisOp = it.next();
             switch (thisOp.cancel(otherOp)) {
-                case CancelableOperation.CANCEL_THIS:
+                case THIS:
                     it.remove();
                     continue;
-                case CancelableOperation.CANCEL_OTHER:
+                case OTHER:
                     return;
-                case CancelableOperation.CANCEL_BOTH:
+                case BOTH:
                     it.remove();
                     return;
-                case CancelableOperation.CANCEL_NONE:
+                case NONE:
                     super.addOperation(otherOp);
                     return;
-                default:
-                    assert false : "Invalid case in switch";
             }
         }
     }
@@ -205,35 +203,30 @@ public class ConsolidatingChangeLog exte
      */
     protected interface CancelableOperation extends Operation {
 
-        /**
-         * The other operation cancels this operations
-         */
-        int CANCEL_THIS = 0;
+        enum Cancel {
 
-        /**
-         * This operation cancels the other operation
-         */
-        int CANCEL_OTHER = 1;
+            /** The other operation cancels this operations */
+            THIS,
 
-        /**
-         * This operation and the other operation cancel each other mutually
-         */
-        int CANCEL_BOTH = 2;
+            /** This operation cancels the other operation */
+            OTHER,
 
-        /**
-         * No cancellation
-         */
-        int CANCEL_NONE = 3;
+            /** This operation and the other operation cancel each other mutually */
+            BOTH,
+
+            /** No cancellation */
+            NONE
+        }
 
         /**
          * Determines the cancellation behavior of the {@code other} operation
          * on this operation.
+         *
          * @param other
-         * @return Either {@link #CANCEL_THIS}, {@link #CANCEL_OTHER}, {@link #CANCEL_OTHER}
-         *   or {@link #CANCEL_NONE}
+         * @return Either {@link Cancel#THIS}, {@link Cancel#OTHER}, {@link Cancel#OTHER} or {@link Cancel#NONE}
          * @throws RepositoryException
          */
-        int cancel(CancelableOperation other) throws RepositoryException;
+        Cancel cancel(CancelableOperation other) throws RepositoryException;
     }
 
     /**
@@ -255,11 +248,11 @@ public class ConsolidatingChangeLog exte
         public static class Empty extends Operations.Empty implements CancelableOperation {
 
             /**
-             * @return {@link ConsolidatingChangeLog.CancelableOperation#CANCEL_NONE}
+             * @return {@link ConsolidatingChangeLog.CancelableOperation.Cancel#NONE}
              */
             @Override
-            public int cancel(CancelableOperation other) throws RepositoryException {
-                return CANCEL_NONE;
+            public Cancel cancel(CancelableOperation other) throws RepositoryException {
+                return Cancel.NONE;
             }
         }
 
@@ -288,33 +281,33 @@ public class ConsolidatingChangeLog exte
             /**
              * @return
              * <ul>
-             * <li>{@link ConsolidatingChangeLog.CancelableOperation#CANCEL_BOTH CANCEL_BOTH} if
+             * <li>{@link ConsolidatingChangeLog.CancelableOperation.Cancel#BOTH CANCEL_BOTH} if
              *   {@code other} is an instance of
              *   {@link ConsolidatingChangeLog.CancelableOperations.Remove Remove} and has this node
              *   as target.</li>
-             * <li>{@link ConsolidatingChangeLog.CancelableOperation#CANCEL_THIS CANCEL_THIS} if
+             * <li>{@link ConsolidatingChangeLog.CancelableOperation.Cancel#THIS CANCEL_THIS} if
              *  {@code other} is an instance of
              *  {@link ConsolidatingChangeLog.CancelableOperations.Remove Remove} and has an node higher up
              *  the hierarchy as target.</li>
-             * <li>{@link ConsolidatingChangeLog.CancelableOperation#CANCEL_NONE CANCEL_NONE} otherwise.</li>
+             * <li>{@link ConsolidatingChangeLog.CancelableOperation.Cancel#NONE CANCEL_NONE} otherwise.</li>
              * </ul>
              */
             @Override
-            public int cancel(CancelableOperation other) throws RepositoryException {
+            public Cancel cancel(CancelableOperation other) throws RepositoryException {
                 if (other instanceof Remove) {
                     Path thisPath = ConsolidatingChangeLog.getPath(parentId, nodeName);
                     Path otherPath = ConsolidatingChangeLog.getPath(((Remove) other).itemId);
                     if (thisPath == null || otherPath == null) {
-                        return CANCEL_NONE;
+                        return Cancel.NONE;
                     }
                     if (thisPath.equals(otherPath)) {
-                        return CANCEL_BOTH;
+                        return Cancel.BOTH;
                     }
                     return thisPath.isDescendantOf(otherPath)
-                        ? CANCEL_THIS
-                        : CANCEL_NONE;
+                        ? Cancel.THIS
+                        : Cancel.NONE;
                 }
-                return CANCEL_NONE;
+                return Cancel.NONE;
             }
         }
 
@@ -351,60 +344,60 @@ public class ConsolidatingChangeLog exte
             /**
              * @return
              * <ul>
-             * <li>{@link ConsolidatingChangeLog.CancelableOperation#CANCEL_BOTH CANCEL_BOTH} if
+             * <li>{@link ConsolidatingChangeLog.CancelableOperation.Cancel#BOTH CANCEL_BOTH} if
              *  {@code other} is an instance of
              *  {@link ConsolidatingChangeLog.CancelableOperations.Remove Remove} and has this property as
              *  target or if {@code other} is an instance of
              *  {@link ConsolidatingChangeLog.CancelableOperations.SetValue SetValue} for a value of
              *  {@code null} and has this property as target.</li>
-             * <li>{@link ConsolidatingChangeLog.CancelableOperation#CANCEL_THIS CANCEL_THIS} if
+             * <li>{@link ConsolidatingChangeLog.CancelableOperation.Cancel#THIS CANCEL_THIS} if
              *   {@code other} is an instance of
              *   {@link ConsolidatingChangeLog.CancelableOperations.Remove Remove} and has a node higher up
              *   the hierarchy as target.</li>
-             * <li>{@link ConsolidatingChangeLog.CancelableOperation#CANCEL_OTHER CANCEL_OTHER} if
+             * <li>{@link ConsolidatingChangeLog.CancelableOperation.Cancel#OTHER CANCEL_OTHER} if
              *   {@code other} is an instance of
              *   {@link ConsolidatingChangeLog.CancelableOperations.SetValue SetValue} and has this
              *   property as target.</li>
-             * <li>{@link ConsolidatingChangeLog.CancelableOperation#CANCEL_NONE CANCEL_NONE} otherwise.</li>
+             * <li>{@link ConsolidatingChangeLog.CancelableOperation.Cancel#NONE CANCEL_NONE} otherwise.</li>
              * <ul>
              */
             @Override
-            public int cancel(CancelableOperation other) throws RepositoryException {
+            public Cancel cancel(CancelableOperation other) throws RepositoryException {
                 if (other instanceof Remove) {
                     Path thisPath = ConsolidatingChangeLog.getPath(parentId, propertyName);
                     Path otherPath = ConsolidatingChangeLog.getPath(((Remove) other).itemId);
                     if (thisPath == null || otherPath == null) {
-                        return CANCEL_NONE;
+                        return Cancel.NONE;
                     }
                     if (thisPath.equals(otherPath)) {
-                        return CANCEL_BOTH;
+                        return Cancel.BOTH;
                     }
                     return thisPath.isDescendantOf(otherPath)
-                        ? CANCEL_THIS
-                        : CANCEL_NONE;
+                        ? Cancel.THIS
+                        : Cancel.NONE;
                 }
                 if (other instanceof SetValue) {
                     SetValue setValue = (SetValue) other;
                     Path thisPath = ConsolidatingChangeLog.getPath(parentId, propertyName);
                     Path otherPath = ConsolidatingChangeLog.getPath(setValue.propertyId);
                     if (thisPath == null || otherPath == null) {
-                        return CANCEL_NONE;
+                        return Cancel.NONE;
                     }
                     if (thisPath.equals(otherPath)) {
                         if (!isMultivalued && setValue.values[0] == null) {
-                            return CANCEL_BOTH;
+                            return Cancel.BOTH;
                         }
                         else if (values.length == setValue.values.length) {
                             for (int k = 0; k < values.length; k++) {
                                 if (!values[k].equals(setValue.values[k])) {
-                                    return CANCEL_NONE;
+                                    return Cancel.NONE;
                                 }
                             }
-                            return CANCEL_OTHER;
+                            return Cancel.OTHER;
                         }
                     }
                 }
-                return CANCEL_NONE;
+                return Cancel.NONE;
             }
         }
 
@@ -446,11 +439,11 @@ public class ConsolidatingChangeLog exte
             }
 
             /**
-             * @return {@link ConsolidatingChangeLog.CancelableOperation#CANCEL_NONE CANCEL_NONE}
+             * @return {@link ConsolidatingChangeLog.CancelableOperation.Cancel#NONE CANCEL_NONE}
              */
             @Override
-            public int cancel(CancelableOperation other) {
-                return CANCEL_NONE;
+            public Cancel cancel(CancelableOperation other) {
+                return Cancel.NONE;
             }
         }
 
@@ -479,11 +472,11 @@ public class ConsolidatingChangeLog exte
             }
 
             /**
-             * @return {@link ConsolidatingChangeLog.CancelableOperation#CANCEL_NONE CANCEL_NONE}
+             * @return {@link ConsolidatingChangeLog.CancelableOperation.Cancel#NONE CANCEL_NONE}
              */
             @Override
-            public int cancel(CancelableOperation other) {
-                return CANCEL_NONE;
+            public Cancel cancel(CancelableOperation other) {
+                return Cancel.NONE;
             }
         }
 
@@ -513,39 +506,39 @@ public class ConsolidatingChangeLog exte
             /**
              * @return
              * <ul>
-             * <li>{@link ConsolidatingChangeLog.CancelableOperation#CANCEL_THIS CANCEL_THIS} if
+             * <li>{@link ConsolidatingChangeLog.CancelableOperation.Cancel#THIS CANCEL_THIS} if
              *   {@code other} is an instance of
              *   {@link ConsolidatingChangeLog.CancelableOperations.Remove Remove} and has an node higher up
              *   the hierarchy or this node as target. Or if {@code other} is an instance of
              *   {@link ConsolidatingChangeLog.CancelableOperations.ReorderNodes ReorderNodes} which
              *   has this node as target and neither {@code srcNodeId} nor {@code beforeNodeId}
              *   has same name siblings.</li>
-             * <li>{@link ConsolidatingChangeLog.CancelableOperation#CANCEL_NONE CANCEL_NONE} otherwise.</li>
+             * <li>{@link ConsolidatingChangeLog.CancelableOperation.Cancel#NONE CANCEL_NONE} otherwise.</li>
              * </ul>
              */
             @Override
-            public int cancel(CancelableOperation other) throws RepositoryException {
+            public Cancel cancel(CancelableOperation other) throws RepositoryException {
                 if (other instanceof Remove) {
                     Path thisPath = ConsolidatingChangeLog.getPath(srcNodeId);
                     Path otherPath = ConsolidatingChangeLog.getPath(((Remove) other).itemId);
                     if (thisPath == null || otherPath == null) {
-                        return CANCEL_NONE;
+                        return Cancel.NONE;
                     }
                     return thisPath.isDescendantOf(otherPath) || thisPath.equals(otherPath)
-                        ? CANCEL_THIS
-                        : CANCEL_NONE;
+                        ? Cancel.THIS
+                        : Cancel.NONE;
                 }
                 if (other instanceof ReorderNodes) {
                     Path thisPath = ConsolidatingChangeLog.getPath(parentId);
                     Path otherPath = ConsolidatingChangeLog.getPath(((ReorderNodes) other).parentId);
                     if (thisPath == null || otherPath == null) {
-                        return CANCEL_NONE;
+                        return Cancel.NONE;
                     }
                     return thisPath.equals(otherPath) && !hasSNS(srcNodeId) && !hasSNS(beforeNodeId)
-                        ? CANCEL_THIS
-                        : CANCEL_NONE;
+                        ? Cancel.THIS
+                        : Cancel.NONE;
                 }
-                return CANCEL_NONE;
+                return Cancel.NONE;
             }
 
             private static boolean hasSNS(NodeId nodeId) {
@@ -586,26 +579,26 @@ public class ConsolidatingChangeLog exte
             /**
              * @return
              * <ul>
-             * <li>{@link ConsolidatingChangeLog.CancelableOperation#CANCEL_THIS CANCEL_THIS} if
+             * <li>{@link ConsolidatingChangeLog.CancelableOperation.Cancel#THIS CANCEL_THIS} if
              *   {@code other} is an instance of
              *   {@link ConsolidatingChangeLog.CancelableOperations.Remove Remove} and has an node higher up
              *   the hierarchy or this node as target. Or if {@code other} is an instance of
              *   {@link ConsolidatingChangeLog.CancelableOperations.SetMixins SetMixins} which has this node
              *   as target and has the same {@code mixinNodeTypeNames}.</li>
-             * <li>{@link ConsolidatingChangeLog.CancelableOperation#CANCEL_NONE CANCEL_NONE} otherwise.</li>
+             * <li>{@link ConsolidatingChangeLog.CancelableOperation.Cancel#NONE CANCEL_NONE} otherwise.</li>
              * </ul>
              */
             @Override
-            public int cancel(CancelableOperation other) throws RepositoryException {
+            public Cancel cancel(CancelableOperation other) throws RepositoryException {
                 if (other instanceof Remove) {
                     Path thisPath = ConsolidatingChangeLog.getPath(nodeId);
                     Path otherPath = ConsolidatingChangeLog.getPath(((Remove) other).itemId);
                     if (thisPath == null || otherPath == null) {
-                        return CANCEL_NONE;
+                        return Cancel.NONE;
                     }
                     return thisPath.isDescendantOf(otherPath) || thisPath.equals(otherPath)
-                        ? CANCEL_THIS
-                        : CANCEL_NONE;
+                        ? Cancel.THIS
+                        : Cancel.NONE;
                 }
                 if (other instanceof SetMixins) {
                     SetMixins setMixin = (SetMixins) other;
@@ -613,19 +606,19 @@ public class ConsolidatingChangeLog exte
                         Path thisPath = ConsolidatingChangeLog.getPath(nodeId);
                         Path otherPath = ConsolidatingChangeLog.getPath(setMixin.nodeId);
                         if (thisPath == null || otherPath == null) {
-                            return CANCEL_NONE;
+                            return Cancel.NONE;
                         }
                         if (thisPath.equals(otherPath)) {
                             for (int k = 0; k < mixinNodeTypeNames.length; k++) {
                                 if (!mixinNodeTypeNames[k].equals(setMixin.mixinNodeTypeNames[k])) {
-                                    return CANCEL_NONE;
+                                    return Cancel.NONE;
                                 }
                             }
-                            return CANCEL_THIS;
+                            return Cancel.THIS;
                         }
                     }
                 }
-                return CANCEL_NONE;
+                return Cancel.NONE;
             }
         }
 
@@ -656,26 +649,26 @@ public class ConsolidatingChangeLog exte
             /**
              * @return
              * <ul>
-             * <li>{@link ConsolidatingChangeLog.CancelableOperation#CANCEL_THIS CANCEL_THIS} if
+             * <li>{@link ConsolidatingChangeLog.CancelableOperation.Cancel#THIS CANCEL_THIS} if
              *   {@code other} is an instance of
              *   {@link ConsolidatingChangeLog.CancelableOperations.Remove Remove} and has an node higher up
              *   the hierarchy or this node as target. Or if {@code other} is an instance of
              *   {@link ConsolidatingChangeLog.CancelableOperations.SetMixins SetMixins} which has this node
              *   as target and has the same {@code mixinNodeTypeNames}.</li>
-             * <li>{@link ConsolidatingChangeLog.CancelableOperation#CANCEL_NONE CANCEL_NONE} otherwise.</li>
+             * <li>{@link ConsolidatingChangeLog.CancelableOperation.Cancel#NONE CANCEL_NONE} otherwise.</li>
              * </ul>
              */
             @Override
-            public int cancel(CancelableOperation other) throws RepositoryException {
+            public Cancel cancel(CancelableOperation other) throws RepositoryException {
                 if (other instanceof Remove) {
                     Path thisPath = ConsolidatingChangeLog.getPath(nodeId);
                     Path otherPath = ConsolidatingChangeLog.getPath(((Remove) other).itemId);
                     if (thisPath == null || otherPath == null) {
-                        return CANCEL_NONE;
+                        return Cancel.NONE;
                     }
                     return thisPath.isDescendantOf(otherPath) || thisPath.equals(otherPath)
-                        ? CANCEL_THIS
-                        : CANCEL_NONE;
+                        ? Cancel.THIS
+                        : Cancel.NONE;
                 }
                 if (other instanceof SetPrimaryType) {
                     SetPrimaryType setPrimaryType = (SetPrimaryType) other;
@@ -683,14 +676,14 @@ public class ConsolidatingChangeLog exte
                         Path thisPath = ConsolidatingChangeLog.getPath(nodeId);
                         Path otherPath = ConsolidatingChangeLog.getPath(setPrimaryType.nodeId);
                         if (thisPath == null || otherPath == null) {
-                            return CANCEL_NONE;
+                            return Cancel.NONE;
                         }
                         if (thisPath.equals(otherPath)) {
-                            return CANCEL_THIS;
+                            return Cancel.THIS;
                         }
                     }
                 }
-                return CANCEL_NONE;
+                return Cancel.NONE;
             }
         }
 
@@ -724,38 +717,38 @@ public class ConsolidatingChangeLog exte
             /**
              * @return
              * <ul>
-             * <li>{@link ConsolidatingChangeLog.CancelableOperation#CANCEL_THIS CANCEL_THIS} if
+             * <li>{@link ConsolidatingChangeLog.CancelableOperation.Cancel#THIS CANCEL_THIS} if
              *   {@code other} is an instance of
              *   {@link ConsolidatingChangeLog.CancelableOperations.Remove Remove} and has an node higher up
              *   the hierarchy or this node as target. Or if {@code other} is an instance of
              *   {@link ConsolidatingChangeLog.CancelableOperations.SetValue SetValue} which has this
              *   property as target</li>
-             * <li>{@link ConsolidatingChangeLog.CancelableOperation#CANCEL_NONE CANCEL_NONE} otherwise.</li>
+             * <li>{@link ConsolidatingChangeLog.CancelableOperation.Cancel#NONE CANCEL_NONE} otherwise.</li>
              * </ul>
              */
             @Override
-            public int cancel(CancelableOperation other) throws RepositoryException {
+            public Cancel cancel(CancelableOperation other) throws RepositoryException {
                 if (other instanceof Remove) {
                     Path thisPath = ConsolidatingChangeLog.getPath(propertyId);
                     Path otherPath = ConsolidatingChangeLog.getPath(((Remove) other).itemId);
                     if (thisPath == null || otherPath == null) {
-                        return CANCEL_NONE;
+                        return Cancel.NONE;
                     }
                     return thisPath.isDescendantOf(otherPath) || thisPath.equals(otherPath)
-                        ? CANCEL_THIS
-                        : CANCEL_NONE;
+                        ? Cancel.THIS
+                        : Cancel.NONE;
                 }
                 if (other instanceof SetValue) {
                     Path thisPath = ConsolidatingChangeLog.getPath(propertyId);
                     Path otherPath = ConsolidatingChangeLog.getPath(((SetValue) other).propertyId);
                     if (thisPath == null || otherPath == null) {
-                        return CANCEL_NONE;
+                        return Cancel.NONE;
                     }
                     if (thisPath.equals(otherPath)) {
-                        return CANCEL_THIS;
+                        return Cancel.THIS;
                     }
                 }
-                return CANCEL_NONE;
+                return Cancel.NONE;
             }
         }