jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r377806 - in /incubator/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/core/nodetype: EffectiveNodeTypeCache.java NodeTypeRegistry.java
Date Tue, 14 Feb 2006 19:27:32 GMT
Author: tripod
Date: Tue Feb 14 11:27:30 2006
New Revision: 377806

URL: http://svn.apache.org/viewcvs?rev=377806&view=rev
Log:
- some minor nodetype enhancements

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=377806&r1=377805&r2=377806&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
Tue Feb 14 11:27:30 2006
@@ -26,6 +26,8 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Set;
+import java.util.Arrays;
+import java.util.HashSet;
 
 /**
  * <code>EffectiveNodeTypeCache</code> ...
@@ -169,10 +171,15 @@
      * approximation).
      */
     static class WeightedKey implements Comparable {
+
         /**
          * set of node type names, sorted in ascending order
          */
-        private final TreeSet set;
+        private final QName[] names;
+
+        /**
+         * the weight of this key
+         */
         private final int weight;
 
         /**
@@ -188,12 +195,9 @@
          */
         WeightedKey(QName[] ntNames, int weight) {
             this.weight = weight;
-
-            set = new TreeSet();
-            for (int i = 0; i < ntNames.length; i++) {
-                // add name to this sorted set
-                set.add(ntNames[i]);
-            }
+            names = new QName[ntNames.length];
+            System.arraycopy(ntNames, 0, names, 0, names.length);
+            Arrays.sort(names);
         }
 
         /**
@@ -208,8 +212,7 @@
          * @param weight
          */
         WeightedKey(Collection ntNames, int weight) {
-            this.weight = weight;
-            set = new TreeSet(ntNames);
+            this((QName[]) ntNames.toArray(new QName[ntNames.size()]), weight);
         }
 
         /**
@@ -220,40 +223,38 @@
          * @return string representation of this sorted set
          * @see java.util.AbstractCollection#toString
          */
-        String getKey() {
-            return set.toString();
+        Object getKey() {
+            return names;
         }
 
         /**
-         * @return
+         * @return the weight of this key
          */
         int getWeight() {
             return weight;
         }
 
         int size() {
-            return set.size();
-        }
-
-        Iterator iterator() {
-            return Collections.unmodifiableSortedSet(set).iterator();
-        }
-
-        Set getSet() {
-            return Collections.unmodifiableSortedSet(set);
+            return names.length;
         }
 
         QName[] toArray() {
-            return (QName[]) set.toArray(new QName[set.size()]);
+            return names;
         }
 
         boolean contains(WeightedKey otherKey) {
-            return set.containsAll(otherKey.getSet());
+            Set tmp = new HashSet(Arrays.asList(names));
+            for (int i=0; i<otherKey.names.length; i++) {
+                if (!tmp.contains(otherKey.names[i])) {
+                    return false;
+                }
+            }
+            return true;
         }
 
         WeightedKey subtract(WeightedKey otherKey) {
-            Set tmp = (Set) set.clone();
-            tmp.removeAll(otherKey.getSet());
+            Set tmp = new HashSet(Arrays.asList(names));
+            tmp.removeAll(Arrays.asList(otherKey.names));
             return new WeightedKey(tmp);
 
         }
@@ -263,28 +264,28 @@
          * (i.e. string representation of this sorted set).
          *
          * @param o
-         * @return
+         * @return the result of the comparison
          */
         public int compareTo(Object o) {
             WeightedKey other = (WeightedKey) o;
-            if (getWeight() > other.getWeight()) {
+            if (weight > other.weight) {
                 return -1;
-            } else if (getWeight() < other.getWeight()) {
+            } else if (weight < other.weight) {
                 return 1;
             }
-            return getKey().compareTo(other.getKey());
+            if (Arrays.equals(names, other.names)) {
+                return 0;
+            } else {
+                return -1;
+            }
         }
 
         public int hashCode() {
             int h = 17;
             // ignore weight
-            Iterator i = set.iterator();
-            while (i.hasNext()) {
+            for (int i=0; i<names.length; i++) {
                 h *= 37;
-                Object obj = i.next();
-                if (obj != null) {
-                    h += obj.hashCode();
-                }
+                h += names[i].hashCode();
             }
             return h;
         }
@@ -296,13 +297,13 @@
             if (obj instanceof WeightedKey) {
                 WeightedKey other = (WeightedKey) obj;
                 // ignore weight
-                return set.equals(other.set);
+                return Arrays.equals(names, other.names);
             }
             return false;
         }
 
         public String toString() {
-            return set.toString() + " (" + weight + ")";
+            return 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=377806&r1=377805&r2=377806&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
Tue Feb 14 11:27:30 2006
@@ -203,7 +203,7 @@
         NodeDefImpl def = new NodeDefImpl();
 
         // FIXME need a fake declaring node type:
-        // rep:root is not quite correct but better than a non-existing node type 
+        // rep:root is not quite correct but better than a non-existing node type
         def.setDeclaringNodeType(QName.REP_ROOT);
         def.setRequiredPrimaryTypes(new QName[]{QName.REP_ROOT});
         def.setDefaultPrimaryType(QName.REP_ROOT);
@@ -856,17 +856,17 @@
                                                                EffectiveNodeTypeCache anEntCache,
                                                                Map aRegisteredNTDefCache)
             throws NoSuchNodeTypeException {
-        // 1. make sure that the specified node type exists
-        if (!aRegisteredNTDefCache.containsKey(ntName)) {
-            throw new NoSuchNodeTypeException(ntName.toString());
-        }
-
-        // 2. check if effective node type has already been built
+        // 1. check if effective node type has already been built
         EffectiveNodeType ent = anEntCache.get(new QName[]{ntName});
         if (ent != null) {
             return ent;
         }
 
+        // 2. make sure that the specified node type exists
+        if (!aRegisteredNTDefCache.containsKey(ntName)) {
+            throw new NoSuchNodeTypeException(ntName.toString());
+        }
+
         // 3. build effective node type
         try {
             NodeTypeDef ntd = (NodeTypeDef) aRegisteredNTDefCache.get(ntName);
@@ -894,21 +894,21 @@
                                                                EffectiveNodeTypeCache anEntCache,
                                                                Map aRegisteredNTDefCache)
             throws NodeTypeConflictException, NoSuchNodeTypeException {
-        // 1. make sure every single node type exists
-        for (int i = 0; i < ntNames.length; i++) {
-            if (!aRegisteredNTDefCache.containsKey(ntNames[i])) {
-                throw new NoSuchNodeTypeException(ntNames[i].toString());
-            }
-        }
 
         EffectiveNodeTypeCache.WeightedKey key =
                 new EffectiveNodeTypeCache.WeightedKey(ntNames);
 
-        // 2. check if aggregate has already been built
+        // 1. check if aggregate has already been built
         if (anEntCache.contains(key)) {
             return anEntCache.get(key);
         }
 
+        // 2. make sure every single node type exists
+        for (int i = 0; i < ntNames.length; i++) {
+            if (!aRegisteredNTDefCache.containsKey(ntNames[i])) {
+                throw new NoSuchNodeTypeException(ntNames[i].toString());
+            }
+        }
         // 3. build aggregate
         EffectiveNodeType result = null;
 
@@ -994,7 +994,7 @@
     }
 
     /**
-     * @return
+     * @return the definition of the root node
      */
     public NodeDef getRootNodeDef() {
         return rootNodeDef;
@@ -1398,7 +1398,8 @@
 
     /**
      * @param nodeTypeName
-     * @return
+     * @return <code>true</code> if the specified nodetype is registered;
+     *         <code>false</code> otherwise.
      */
     public synchronized boolean isRegistered(QName nodeTypeName) {
         return registeredNTDefs.containsKey(nodeTypeName);
@@ -1407,7 +1408,8 @@
 
     /**
      * @param nodeTypeName
-     * @return
+     * @return <code>true</code> if the specified nodetype is built-in;
+     *         <code>false</code> otherwise.
      */
     public synchronized boolean isBuiltIn(QName nodeTypeName) {
         return builtInNTDefs.contains(nodeTypeName);
@@ -1415,7 +1417,7 @@
 
     /**
      * @param id
-     * @return
+     * @return the node definition for the given id.
      */
     public NodeDef getNodeDef(NodeDefId id) {
         return (NodeDef) nodeDefs.get(id);
@@ -1423,7 +1425,7 @@
 
     /**
      * @param id
-     * @return
+     * @return the property definition for the given id.
      */
     public PropDef getPropDef(PropDefId id) {
         return (PropDef) propDefs.get(id);



Mime
View raw message