Return-Path: X-Original-To: apmail-jackrabbit-commits-archive@www.apache.org Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 83F477D22 for ; Wed, 14 Sep 2011 20:52:41 +0000 (UTC) Received: (qmail 54662 invoked by uid 500); 14 Sep 2011 20:52:41 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 54621 invoked by uid 500); 14 Sep 2011 20:52:41 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 54607 invoked by uid 99); 14 Sep 2011 20:52:41 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Sep 2011 20:52:41 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Sep 2011 20:52:39 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 4CE9A23888FD; Wed, 14 Sep 2011 20:52:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1170845 - /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/batch/ConsolidatingChangeLog.java Date: Wed, 14 Sep 2011 20:52:19 -0000 To: commits@jackrabbit.apache.org From: mduerig@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110914205219.4CE9A23888FD@eris.apache.org> 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 *
    - *
  • {@link ConsolidatingChangeLog.CancelableOperation#CANCEL_BOTH CANCEL_BOTH} if + *
  • {@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.
  • - *
  • {@link ConsolidatingChangeLog.CancelableOperation#CANCEL_THIS CANCEL_THIS} if + *
  • {@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.
  • - *
  • {@link ConsolidatingChangeLog.CancelableOperation#CANCEL_NONE CANCEL_NONE} otherwise.
  • + *
  • {@link ConsolidatingChangeLog.CancelableOperation.Cancel#NONE CANCEL_NONE} otherwise.
  • *
*/ @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 *
    - *
  • {@link ConsolidatingChangeLog.CancelableOperation#CANCEL_BOTH CANCEL_BOTH} if + *
  • {@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.
  • - *
  • {@link ConsolidatingChangeLog.CancelableOperation#CANCEL_THIS CANCEL_THIS} if + *
  • {@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.
  • - *
  • {@link ConsolidatingChangeLog.CancelableOperation#CANCEL_OTHER CANCEL_OTHER} if + *
  • {@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.
  • - *
  • {@link ConsolidatingChangeLog.CancelableOperation#CANCEL_NONE CANCEL_NONE} otherwise.
  • + *
  • {@link ConsolidatingChangeLog.CancelableOperation.Cancel#NONE CANCEL_NONE} otherwise.
  • *
      */ @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 *
        - *
      • {@link ConsolidatingChangeLog.CancelableOperation#CANCEL_THIS CANCEL_THIS} if + *
      • {@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.
      • - *
      • {@link ConsolidatingChangeLog.CancelableOperation#CANCEL_NONE CANCEL_NONE} otherwise.
      • + *
      • {@link ConsolidatingChangeLog.CancelableOperation.Cancel#NONE CANCEL_NONE} otherwise.
      • *
      */ @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 *
        - *
      • {@link ConsolidatingChangeLog.CancelableOperation#CANCEL_THIS CANCEL_THIS} if + *
      • {@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}.
      • - *
      • {@link ConsolidatingChangeLog.CancelableOperation#CANCEL_NONE CANCEL_NONE} otherwise.
      • + *
      • {@link ConsolidatingChangeLog.CancelableOperation.Cancel#NONE CANCEL_NONE} otherwise.
      • *
      */ @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 *
        - *
      • {@link ConsolidatingChangeLog.CancelableOperation#CANCEL_THIS CANCEL_THIS} if + *
      • {@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}.
      • - *
      • {@link ConsolidatingChangeLog.CancelableOperation#CANCEL_NONE CANCEL_NONE} otherwise.
      • + *
      • {@link ConsolidatingChangeLog.CancelableOperation.Cancel#NONE CANCEL_NONE} otherwise.
      • *
      */ @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 *
        - *
      • {@link ConsolidatingChangeLog.CancelableOperation#CANCEL_THIS CANCEL_THIS} if + *
      • {@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
      • - *
      • {@link ConsolidatingChangeLog.CancelableOperation#CANCEL_NONE CANCEL_NONE} otherwise.
      • + *
      • {@link ConsolidatingChangeLog.CancelableOperation.Cancel#NONE CANCEL_NONE} otherwise.
      • *
      */ @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; } }