jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r380724 - in /incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype: EffectiveNodeTypeCache.java NodeTypeRegistry.java
Date Fri, 24 Feb 2006 17:37:27 GMT
Author: stefan
Date: Fri Feb 24 09:37:20 2006
New Revision: 380724

URL: http://svn.apache.org/viewcvs?rev=380724&view=rev
Log:
fixing minor issues with recent changes in nodetype package (r377806)

Modified:
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeTypeCache.java
    incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeTypeCache.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeTypeCache.java?rev=380724&r1=380723&r2=380724&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeTypeCache.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/EffectiveNodeTypeCache.java
Fri Feb 24 09:37:20 2006
@@ -20,22 +20,26 @@
 import org.apache.jackrabbit.name.QName;
 
 import java.io.PrintStream;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.TreeSet;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Set;
-import java.util.Arrays;
+import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.TreeSet;
 
 /**
  * <code>EffectiveNodeTypeCache</code> ...
  */
 class EffectiveNodeTypeCache implements Cloneable, Dumpable {
-    /** ordered set of keys */
+    /**
+     * ordered set of keys
+     */
     final TreeSet sortedKeys;
-    /** cache of pre-built aggregations of node types */
+    /**
+     * cache of pre-built aggregations of node types
+     */
     final HashMap aggregates;
 
     EffectiveNodeTypeCache() {
@@ -173,7 +177,7 @@
     static class WeightedKey implements Comparable {
 
         /**
-         * set of node type names, sorted in ascending order
+         * array of node type names, sorted in ascending order
          */
         private final QName[] names;
 
@@ -216,35 +220,22 @@
         }
 
         /**
-         * The key is the string representation of this sorted set
-         * (e.g. the key for a set containing entries "c", "b" and "a" would
-         * be "[a, b, c]").
-         *
-         * @return string representation of this sorted set
-         * @see java.util.AbstractCollection#toString
-         */
-        Object getKey() {
-            return names;
-        }
-
-        /**
          * @return the weight of this key
          */
         int getWeight() {
             return weight;
         }
 
-        int size() {
-            return names.length;
-        }
-
-        QName[] toArray() {
+        /**
+         * @return the node type names of this key
+         */
+        QName[] getNames() {
             return names;
         }
 
         boolean contains(WeightedKey otherKey) {
             Set tmp = new HashSet(Arrays.asList(names));
-            for (int i=0; i<otherKey.names.length; i++) {
+            for (int i = 0; i < otherKey.names.length; i++) {
                 if (!tmp.contains(otherKey.names[i])) {
                     return false;
                 }
@@ -259,6 +250,7 @@
 
         }
 
+        //-------------------------------------------------------< Comparable >
         /**
          * The resulting sort-order is: 1. descending weight, 2. ascending key
          * (i.e. string representation of this sorted set).
@@ -268,22 +260,35 @@
          */
         public int compareTo(Object o) {
             WeightedKey other = (WeightedKey) o;
+
+            // compare weights
             if (weight > other.weight) {
                 return -1;
             } else if (weight < other.weight) {
                 return 1;
             }
-            if (Arrays.equals(names, other.names)) {
-                return 0;
-            } else {
-                return -1;
+
+            // compare arrays of names
+            int len1 = names.length;
+            int len2 = other.names.length;
+            int len = Math.min(len1, len2);
+
+            for (int i = 0; i < len; i++) {
+                QName name1 = names[i];
+                QName name2 = other.names[i];
+                int result = name1.compareTo(name2);
+                if (result != 0) {
+                    return result;
+                }
             }
+            return len1 - len2;
         }
 
+        //---------------------------------------< java.lang.Object overrides >
         public int hashCode() {
             int h = 17;
             // ignore weight
-            for (int i=0; i<names.length; i++) {
+            for (int i = 0; i < names.length; i++) {
                 h *= 37;
                 h += names[i].hashCode();
             }
@@ -303,7 +308,7 @@
         }
 
         public String toString() {
-            return names.toString() + " (" + weight + ")";
+            return Arrays.asList(names).toString() + " (" + weight + ")";
         }
     }
 }

Modified: incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java?rev=380724&r1=380723&r2=380724&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype/NodeTypeRegistry.java
Fri Feb 24 09:37:20 2006
@@ -914,7 +914,7 @@
 
         // build list of 'best' existing sub-aggregates
         ArrayList tmpResults = new ArrayList();
-        while (key.size() > 0) {
+        while (key.getNames().length > 0) {
             // check if we've already built this aggregate
             if (anEntCache.contains(key)) {
                 tmpResults.add(anEntCache.get(key));
@@ -949,7 +949,7 @@
                  * no matching sub-aggregates found:
                  * build aggregate of remaining node types through iteration
                  */
-                QName[] remainder = key.toArray();
+                QName[] remainder = key.getNames();
                 for (int i = 0; i < remainder.length; i++) {
                     NodeTypeDef ntd = (NodeTypeDef) aRegisteredNTDefCache.get(remainder[i]);
                     EffectiveNodeType ent =
@@ -1398,7 +1398,7 @@
 
     /**
      * @param nodeTypeName
-     * @return <code>true</code> if the specified nodetype is registered;
+     * @return <code>true</code> if the specified node type is registered;
      *         <code>false</code> otherwise.
      */
     public synchronized boolean isRegistered(QName nodeTypeName) {
@@ -1408,7 +1408,7 @@
 
     /**
      * @param nodeTypeName
-     * @return <code>true</code> if the specified nodetype is built-in;
+     * @return <code>true</code> if the specified node type is built-in;
      *         <code>false</code> otherwise.
      */
     public synchronized boolean isBuiltIn(QName nodeTypeName) {



Mime
View raw message