jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r328809 - /incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/
Date Thu, 27 Oct 2005 06:43:53 GMT
Author: jukka
Date: Wed Oct 26 23:43:47 2005
New Revision: 328809

URL: http://svn.apache.org/viewcvs?rev=328809&view=rev
Log:
JCR-EXT: Cleanups and improvements for the simple node type state implementation.

Added:
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/StateComparator.java
  (with props)
Modified:
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/ItemDefinitionState.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeDefinitionState.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeManagerState.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeState.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/PropertyDefinitionState.java
    incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/package.html

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/ItemDefinitionState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/ItemDefinitionState.java?rev=328809&r1=328808&r2=328809&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/ItemDefinitionState.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/ItemDefinitionState.java
Wed Oct 26 23:43:47 2005
@@ -24,34 +24,22 @@
  * Item definition state. This base class contains the common
  * state properties used by both property and node definitions.
  */
-public class ItemDefinitionState {
+public class ItemDefinitionState implements Comparable {
 
     /** The qualified name of the defined item. */
-    private QName name;
+    private QName name = null;
 
     /** The AutoCreated item definition property. */
-    private boolean autoCreated;
+    private boolean autoCreated = false;
 
     /** The Mandatory item definition property. */
-    private boolean mandatory;
+    private boolean mandatory = false;
 
     /** The OnParentVersion item definition property. */
-    private int onParentVersion;
+    private int onParentVersion = OnParentVersionAction.COPY;
 
     /** The Protected item definition property. */
-    private boolean isProtected; // avoid the reserved word "protected"
-
-    /**
-     * Creates an empty item definition state instance. This constructor
-     * is protected because this class must only be used through subclasses.
-     */
-    protected ItemDefinitionState() {
-        name = null;
-        autoCreated = false;
-        mandatory = false;
-        onParentVersion = OnParentVersionAction.IGNORE;
-        isProtected = false;
-    }
+    private boolean isProtected = false; // avoid the reserved word "protected"
 
     /**
      * Returns the qualified name of the defined item.
@@ -143,4 +131,46 @@
         this.isProtected = isProtected;
     }
 
+    public int compareTo(Object object) {
+        ItemDefinitionState that = (ItemDefinitionState) object;
+        if ((this.name == null) != (that.name == null)) {
+            return (name != null) ? -1 : 1;
+        } else if (this.name != null && this.name.compareTo(that.name) != 0) {
+            return this.name.compareTo(that.name);
+        } else if (this.autoCreated != that.autoCreated) {
+            return autoCreated ? -1 : 1;
+        } else if (this.mandatory != that.mandatory) {
+            return mandatory ? -1 : 1;
+        } else if (this.isProtected != that.isProtected) {
+            return isProtected ? -1 : 1;
+        } else {
+            return this.onParentVersion - that.onParentVersion;
+        }
+    }
+
+    public boolean equals(Object object) {
+        if (this == object) {
+            return true;
+        } else if (object instanceof ItemDefinitionState) {
+            ItemDefinitionState that = (ItemDefinitionState) object;
+            return ((name != null) ? name.equals(that.name) : (that.name == null))
+                && this.autoCreated == that.autoCreated
+                && this.isProtected == that.isProtected
+                && this.mandatory == that.mandatory
+                && this.onParentVersion == that.onParentVersion;
+        } else {
+            return false;
+        }
+    }
+
+    public int hashCode() {
+        int code = 37;
+        code = code * 17 + ((name != null) ? name.hashCode() : 0);
+        code = code * 17 + (autoCreated ? 1 : 0);
+        code = code * 17 + (isProtected ? 1 : 0);
+        code = code * 17 + (mandatory ? 1 : 0);
+        code = code * 17 + onParentVersion;
+        return code;
+    }
+    
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeDefinitionState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeDefinitionState.java?rev=328809&r1=328808&r2=328809&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeDefinitionState.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeDefinitionState.java
Wed Oct 26 23:43:47 2005
@@ -16,8 +16,7 @@
  */
 package org.apache.jackrabbit.state.nodetype;
 
-import java.util.HashSet;
-import java.util.Set;
+import java.util.Arrays;
 
 import org.apache.jackrabbit.name.QName;
 
@@ -28,21 +27,13 @@
 public class NodeDefinitionState extends ItemDefinitionState {
 
     /** Name of the default primary type of the defined node. */
-    private QName defaultPrimaryTypeName;
+    private QName defaultPrimaryTypeName = null;
 
     /** Names of the required primary types of the defined node. */
-    private Set requiredPrimaryTypeNames;
+    private QName[] requiredPrimaryTypeNames = new QName[0];
 
     /** The AllowsSameNameSiblings node definition property. */
-    private boolean allowsSameNameSiblings;
-
-    /** Creates an empty node definition state instance. */
-    public NodeDefinitionState() {
-        super();
-        defaultPrimaryTypeName = null;
-        requiredPrimaryTypeNames = new HashSet();
-        allowsSameNameSiblings = false;
-    }
+    private boolean allowsSameNameSiblings = false;
 
     /**
      * Returns the name of the default primary type of the defined node.
@@ -68,17 +59,17 @@
      * @return type names
      */
     public QName[] getRequiredPrimaryTypeNames() {
-        return (QName[]) requiredPrimaryTypeNames.toArray(
-                new QName[requiredPrimaryTypeNames.size()]);
+        return requiredPrimaryTypeNames;
     }
 
     /**
-     * Adds a type name to the list of required primary types.
+     * Sets the list of required primary types.
      *
-     * @param requiredPrimaryTypeName type name
+     * @param requiredPrimaryTypeNames type names
      */
-    public void addRequiredPrimaryTypeName(QName requiredPrimaryTypeName) {
-        requiredPrimaryTypeNames.add(requiredPrimaryTypeName);
+    public void setRequiredPrimaryTypeName(QName[] requiredPrimaryTypeNames) {
+        this.requiredPrimaryTypeNames = requiredPrimaryTypeNames;
+        Arrays.sort(this.requiredPrimaryTypeNames);
     }
 
     /**
@@ -97,6 +88,21 @@
      */
     public void setAllowsSameNameSiblings(boolean allowsSameNameSiblings) {
         this.allowsSameNameSiblings = allowsSameNameSiblings;
+    }
+
+    public boolean equals(Object object) {
+        return (this == object)
+            || (object != null && new StateComparator().compare(this, object) ==
0);
+    }
+
+    public int hashCode() {
+        int code = super.hashCode();
+        code = code * 17 + (allowsSameNameSiblings ? 1 : 0);
+        code = code * 17 + ((defaultPrimaryTypeName != null) ? defaultPrimaryTypeName.hashCode()
: 0);
+        for (int i = 0; i < requiredPrimaryTypeNames.length; i++) {
+            code = code * 17 + requiredPrimaryTypeNames[i].hashCode();
+        }
+        return code;
     }
 
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeManagerState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeManagerState.java?rev=328809&r1=328808&r2=328809&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeManagerState.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeManagerState.java
Wed Oct 26 23:43:47 2005
@@ -16,9 +16,6 @@
  */
 package org.apache.jackrabbit.state.nodetype;
 
-import java.util.HashSet;
-import java.util.Set;
-
 /**
  * Node type manager state. Instances of this class are used to hold
  * and manage the internal state of node type managers.
@@ -26,12 +23,7 @@
 public class NodeTypeManagerState {
 
     /** Available node type states. */
-    private final Set types;
-
-    /** Creates an empty node type manager state instance. */
-    public NodeTypeManagerState() {
-        types = new HashSet();
-    }
+    private NodeTypeState[] nodeTypeStates;
 
     /**
      * Returns all available node type states.
@@ -39,16 +31,16 @@
      * @return node type states
      */
     public NodeTypeState[] getNodeTypeStates() {
-        return (NodeTypeState[]) types.toArray(new NodeTypeState[types.size()]);
+        return nodeTypeStates;
     }
 
     /**
-     * Adds a node type to the node type manager state.
+     * Sets the node type manager state.
      *
-     * @param state node type state
+     * @param nodeTypeStates node type states
      */
-    public void addNodeTypeState(NodeTypeState state) {
-        types.add(state);
+    public void setNodeTypeStates(NodeTypeState[] nodeTypeStates) {
+        this.nodeTypeStates = nodeTypeStates;
     }
 
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeState.java?rev=328809&r1=328808&r2=328809&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeState.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/NodeTypeState.java
Wed Oct 26 23:43:47 2005
@@ -16,9 +16,6 @@
  */
 package org.apache.jackrabbit.state.nodetype;
 
-import java.util.HashSet;
-import java.util.Set;
-
 import org.apache.jackrabbit.name.QName;
 
 /**
@@ -28,36 +25,27 @@
 public class NodeTypeState {
 
     /** Name of the node type. */
-    private QName name;
+    private QName name = null;
 
     /** The Mixin node type property. */
-    private boolean mixin;
+    private boolean mixin = false;
 
     /** The HasOrderableChildNodes node type property. */
-    private boolean hasOrderableChildNodes;
+    private boolean hasOrderableChildNodes = false;
 
     /** Name of the primary item of the node type. */
-    private QName primaryItemName;
+    private QName primaryItemName = null;
 
     /** Names of the declared supertypes. */
-    private Set supertypeNames;
+    private QName[] supertypeNames = new QName[0];
 
     /** Child node definition states. */
-    private Set childNodeDefinitionStates;
+    private NodeDefinitionState[] childNodeDefinitionStates =
+        new NodeDefinitionState[0];
 
     /** Property definition states. */
-    private Set propertyDefinitionStates;
-
-    /** Creates an empty node type state instance. */
-    public NodeTypeState() {
-        name = null;
-        mixin = false;
-        hasOrderableChildNodes = false;
-        primaryItemName = null;
-        supertypeNames = new HashSet();
-        childNodeDefinitionStates = new HashSet();
-        propertyDefinitionStates = new HashSet();
-    }
+    private PropertyDefinitionState[] propertyDefinitionStates =
+        new PropertyDefinitionState[0];
 
     /**
      * Returns the node type name.
@@ -100,7 +88,7 @@
      *
      * @return HasOrderableChildNodes property value
      */
-    public boolean isHasOrderableChildNodes() {
+    public boolean hasOrderableChildNodes() {
         return hasOrderableChildNodes;
     }
 
@@ -137,17 +125,16 @@
      * @return supertype names
      */
     public QName[] getSupertypeNames() {
-        return (QName[])
-            supertypeNames.toArray(new QName[supertypeNames.size()]);
+        return supertypeNames;
     }
 
     /**
-     * Adds a supertype name to the list of declared supertypes.
+     * Sets the list of declared supertypes.
      *
-     * @param name supertype name
+     * @param supertypeNames supertype names
      */
-    public void addSupertypeName(QName name) {
-        supertypeNames.add(name);
+    public void setSupertypeNames(QName[] supertypeNames) {
+        this.supertypeNames = supertypeNames;
     }
 
     /**
@@ -156,18 +143,17 @@
      * @return child node definition states
      */
     public NodeDefinitionState[] getChildNodeDefinitionStates() {
-        return (NodeDefinitionState[]) childNodeDefinitionStates.toArray(
-                new NodeDefinitionState[childNodeDefinitionStates.size()]);
+        return childNodeDefinitionStates;
     }
 
     /**
-     * Adds a node definition state to the list of child node definition
-     * states of the node type.
+     * Sets the list of child node definition states of the node type.
      *
-     * @param state child node definition state
+     * @param childNodeDefinitionStates child node definition states
      */
-    public void addChildNodeDefinition(NodeDefinitionState state) {
-        childNodeDefinitionStates.add(state);
+    public void setChildNodeDefinitionStates(
+            NodeDefinitionState[] childNodeDefinitionStates) {
+        this.childNodeDefinitionStates = childNodeDefinitionStates;
     }
 
     /**
@@ -176,18 +162,30 @@
      * @return property definition states
      */
     public PropertyDefinitionState[] getPropertyDefinitionStates() {
-        return (PropertyDefinitionState[]) propertyDefinitionStates.toArray(
-                new PropertyDefinitionState[propertyDefinitionStates.size()]);
+        return propertyDefinitionStates;
     }
 
     /**
-     * Adds a property definition state to the list of property definition
-     * states of the node type.
+     * Sets the list of property definition states of the node type.
      *
-     * @param state property definition state
+     * @param propertyDefinitionStates property definition states
      */
-    public void addPropertyDefinitionState(PropertyDefinitionState state) {
-        propertyDefinitionStates.add(state);
+    public void setPropertyDefinitionStates(
+            PropertyDefinitionState[] propertyDefinitionStates) {
+        this.propertyDefinitionStates = propertyDefinitionStates;
+    }
+
+    public boolean equals(Object object) {
+        return (this == object)
+            || (object != null && new StateComparator().compare(this, object) ==
0);
+    }
+
+    public int hashCode() {
+        int code = 37;
+        code = code * 17 + ((name != null) ? name.hashCode() : 0);
+        code = code * 17 + (mixin ? 1 : 0);
+        code = code * 17 + (hasOrderableChildNodes ? 1 : 0);
+        return code;
     }
 
 }

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/PropertyDefinitionState.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/PropertyDefinitionState.java?rev=328809&r1=328808&r2=328809&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/PropertyDefinitionState.java
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/PropertyDefinitionState.java
Wed Oct 26 23:43:47 2005
@@ -16,9 +16,6 @@
  */
 package org.apache.jackrabbit.state.nodetype;
 
-import java.util.List;
-import java.util.Vector;
-
 import javax.jcr.PropertyType;
 
 /**
@@ -28,21 +25,10 @@
 public class PropertyDefinitionState extends ItemDefinitionState {
 
     /** Required type of the defined property. */
-    private int requiredType;
-
-    /** List of value constraint strings. */
-    private List valueConstraints;
+    private int requiredType = PropertyType.UNDEFINED;
 
     /** The Multiple property definition property. */
-    private boolean multiple;
-
-    /** Creates an empty property definition state instance. */
-    public PropertyDefinitionState() {
-        super();
-        requiredType = PropertyType.UNDEFINED;
-        valueConstraints = new Vector();
-        multiple = false;
-    }
+    private boolean multiple = false;
 
     /**
      * Returns the required type of the defined property.
@@ -63,27 +49,6 @@
     }
 
     /**
-     * Returns the property value constraint strings. The returned
-     * array can be modified freely as it is freshly instantiated and
-     * not a part of the property definition state.
-     *
-     * @return value constraints
-     */
-    public String[] getValueConstraints() {
-        return (String[])
-            valueConstraints.toArray(new String[valueConstraints.size()]);
-    }
-
-    /**
-     * Adds a constraint string to the list of property value constraints.
-     *
-     * @param constraint constraint string
-     */
-    public void addValueConstraints(String constraint) {
-        valueConstraints.add(constraint);
-    }
-
-    /**
      * Returns the value of the Multiple property definition property.
      *
      * @return Multiple property value
@@ -99,6 +64,26 @@
      */
     public void setMultiple(boolean multiple) {
         this.multiple = multiple;
+    }
+
+    public boolean equals(Object object) {
+        if (this == object) {
+            return true;
+        } else if (object instanceof PropertyDefinitionState) {
+            PropertyDefinitionState that = (PropertyDefinitionState) object;
+            return super.equals(that)
+                && this.multiple == that.multiple
+                && this.requiredType == that.requiredType;
+        } else {
+            return false;
+        }
+    }
+
+    public int hashCode() {
+        int code = super.hashCode();
+        code = code * 17 + (multiple ? 1 : 0);
+        code = code * 17 + requiredType;
+        return code;
     }
 
 }

Added: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/StateComparator.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/StateComparator.java?rev=328809&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/StateComparator.java
(added)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/StateComparator.java
Wed Oct 26 23:43:47 2005
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.state.nodetype;
+
+import java.util.Comparator;
+
+import org.apache.jackrabbit.name.QName;
+
+/**
+ * TODO
+ */
+class StateComparator implements Comparator {
+
+    public int compare(Object a, Object b) {
+        if (a instanceof NodeTypeState) {
+            return compareNodeTypeStates((NodeTypeState) a, (NodeTypeState) b);
+        } else if (a instanceof NodeDefinitionState) {
+            return compareNodeDefinitionStates((NodeDefinitionState) a, (NodeDefinitionState)
b);
+        } else if (a instanceof PropertyDefinitionState) {
+            return comparePropertyDefinitionStates((PropertyDefinitionState) a, (PropertyDefinitionState)
b);
+        } else if (a instanceof QName) {
+            return compareQNames((QName) a, (QName) b);
+        } else {
+            throw new ClassCastException("Unknown class: " + a.getClass());
+        }
+    }
+
+    private int compareNodeTypeStates(NodeTypeState a, NodeTypeState b) {
+        if (compareQNames(a.getName(), b.getName()) != 0) {
+            return compareQNames(a.getName(), b.getName());
+        } else if (a.isMixin() != b.isMixin()) {
+            return a.isMixin() ? -1 : 1;
+        } else if (a.hasOrderableChildNodes() != b.hasOrderableChildNodes()) {
+            return a.hasOrderableChildNodes() ? -1 : 1;
+        } else if (compareQNames(a.getPrimaryItemName(), b.getPrimaryItemName()) != 0) {
+            return compareQNames(a.getPrimaryItemName(), b.getPrimaryItemName());
+        } else if (compareQNameArrays(a.getSupertypeNames(), b.getSupertypeNames()) != 0)
{
+            return compareQNameArrays(a.getSupertypeNames(), b.getSupertypeNames());
+        } else if (comparePropertyDefinitionStateArrays(a.getPropertyDefinitionStates(),
b.getPropertyDefinitionStates()) != 0) {
+            return comparePropertyDefinitionStateArrays(a.getPropertyDefinitionStates(),
b.getPropertyDefinitionStates());
+        } else {
+            return compareNodeDefinitionStateArrays(a.getChildNodeDefinitionStates(), b.getChildNodeDefinitionStates());
+        }
+    }
+
+    private int compareNodeDefinitionStateArrays(
+            NodeDefinitionState[] a, NodeDefinitionState[] b) {
+        for (int i = 0; i < a.length && i < b.length; i++) {
+            if (compareNodeDefinitionStates(a[i], b[i]) != 0) {
+                return compareNodeDefinitionStates(a[i], b[i]);
+            }
+        }
+        return a.length - b.length;
+    }
+
+    private int compareNodeDefinitionStates(
+            NodeDefinitionState a, NodeDefinitionState b) {
+        if (compareItemDefinitionStates(a, b) != 0) {
+            return compareItemDefinitionStates(a, b);
+        } else if (a.allowsSameNameSiblings() != b.allowsSameNameSiblings()) {
+            return a.allowsSameNameSiblings() ? -1 : 1;
+        } else if (compareQNames(a.getDefaultPrimaryTypeName(), b.getDefaultPrimaryTypeName())
!= 0) {
+            return compareQNames(a.getDefaultPrimaryTypeName(), b.getDefaultPrimaryTypeName());
+        } else {
+            return compareQNameArrays(a.getRequiredPrimaryTypeNames(), b.getRequiredPrimaryTypeNames());
+        }
+    }
+
+    private int comparePropertyDefinitionStateArrays(
+            PropertyDefinitionState[] a, PropertyDefinitionState[] b) {
+        for (int i = 0; i < a.length && i < b.length; i++) {
+            if (comparePropertyDefinitionStates(a[i], b[i]) != 0) {
+                return comparePropertyDefinitionStates(a[i], b[i]);
+            }
+        }
+        return a.length - b.length;
+    }
+    private int comparePropertyDefinitionStates(
+            PropertyDefinitionState a, PropertyDefinitionState b) {
+        if (compareItemDefinitionStates(a, b) != 0) {
+            return compareItemDefinitionStates(a, b);
+        } else if (a.isMultiple() != b.isMultiple()) {
+            return a.isMultiple() ? -1 : 1;
+        } else {
+            return a.getRequiredType() - b.getRequiredType();
+        }
+    }
+
+    private int compareItemDefinitionStates(
+            ItemDefinitionState a, ItemDefinitionState b) {
+        if (compareQNames(a.getName(), b.getName()) != 0) {
+            return compareQNames(a.getName(), b.getName());
+        } else if (a.isAutoCreated() != b.isAutoCreated()) {
+            return a.isAutoCreated() ? -1 : 1;
+        } else if (a.isMandatory() != b.isMandatory()) {
+            return a.isMandatory() ? -1 : 1;
+        } else if (a.isProtected() != b.isProtected()) {
+            return b.isProtected() ? -1 : 1;
+        } else {
+            return a.getOnParentVersion() - b.getOnParentVersion();
+        }
+    }
+
+    private int compareQNameArrays(QName[] a, QName[] b) {
+        for (int i = 0; i < a.length && i < b.length; i++) {
+            if (compareQNames(a[i], b[i]) != 0) {
+                return compareQNames(a[i], b[i]);
+            }
+        }
+        return a.length - b.length;
+    }
+
+    private int compareQNames(QName a, QName b) {
+        if (a != null && b != null) {
+            return a.compareTo(b);
+        } else if (a != null) {
+            return -1;
+        } else if (b != null) {
+            return 1;
+        } else {
+            return 0;
+        }
+    }
+
+}

Propchange: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/StateComparator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/package.html
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/package.html?rev=328809&r1=328808&r2=328809&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/package.html
(original)
+++ incubator/jackrabbit/trunk/contrib/jcr-ext/src/java/org/apache/jackrabbit/state/nodetype/package.html
Wed Oct 26 23:43:47 2005
@@ -4,20 +4,7 @@
 The classes in this package provide a simple and straightforward mechanism
 for holding and managing node type information. The node type information
 managed by this package is mutable and not bound to a specific session.
-The {@link org.apache.jackrabbit.session.nodetype
-org.apache.jackrabbit.session.nodetype} package implements the standard
-{@link javax.jcr.nodetype JCR node type interfaces} based on underlying
-node type state managed by classes from this package.
-</p>
-
-<h2>Implementation notes</h2>
-<h3>State equality</h3>
-<p>
-Although in most use cases the node type state instances do not change
-once they have been created and properly configured, but they still are
-mutable and it is possible for their state to change. Thus none of these
-classes override the default {@link Object#equals(Object) equals()} and
-{@link Object#hashCode() hashCode()} methods that are based on reference
-equality.
-</p>
+The {@link org.apache.jackrabbit.session.nodetype} package implements the
+standard {@link javax.jcr.nodetype JCR node type interfaces} based on
+underlying node type state managed by classes from this package.
 </body>



Mime
View raw message