jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r803119 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/retention/ jackrabbit-spi-comm...
Date Tue, 11 Aug 2009 13:46:15 GMT
Author: jukka
Date: Tue Aug 11 13:46:15 2009
New Revision: 803119

URL: http://svn.apache.org/viewvc?rev=803119&view=rev
Log:
JCR-2087: Upgrade to Java 5 as the base platform

Generify PathMap (as preparation for work on LockManagerImpl).

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/retention/HoldImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/retention/RetentionRegistryImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathMap.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java?rev=803119&r1=803118&r2=803119&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/CachingHierarchyManager.java Tue Aug 11 13:46:15 2009
@@ -63,7 +63,7 @@
     /**
      * Mapping of paths to children in the path map
      */
-    private final PathMap pathCache = new PathMap();
+    private final PathMap<LRUEntry> pathCache = new PathMap<LRUEntry>();
 
     /**
      * Mapping of item ids to <code>LRUEntry</code> in the path map
@@ -132,13 +132,13 @@
             pathToNode = path.getAncestor(1);
         }
 
-        PathMap.Element element = map(pathToNode);
+        PathMap.Element<LRUEntry> element = map(pathToNode);
         if (element == null) {
             // not even intermediate match: call base class
             return super.resolvePath(path, typesAllowed);
         }
 
-        LRUEntry entry = (LRUEntry) element.get();
+        LRUEntry entry = element.get();
         if (element.hasPath(path)) {
             // exact match: return answer
             synchronized (cacheMonitor) {
@@ -179,7 +179,7 @@
             throws ItemStateException, RepositoryException {
 
         if (state.isNode()) {
-            PathMap.Element element = get(state.getId());
+            PathMap.Element<LRUEntry> element = get(state.getId());
             if (element != null) {
                 try {
                     Path.Element[] elements = element.getPath().getElements();
@@ -218,7 +218,7 @@
             throws ItemNotFoundException, RepositoryException {
 
         if (id.denotesNode()) {
-            PathMap.Element element = get(id);
+            PathMap.Element<LRUEntry> element = get(id);
             if (element != null) {
                 try {
                     return element.getPath();
@@ -239,7 +239,7 @@
             throws ItemNotFoundException, RepositoryException {
 
         if (id.denotesNode()) {
-            PathMap.Element element = get(id);
+            PathMap.Element<LRUEntry> element = get(id);
             if (element != null) {
                 return element.getName();
             }
@@ -254,7 +254,7 @@
             throws ItemNotFoundException, RepositoryException {
 
         if (id.denotesNode()) {
-            PathMap.Element element = get(id);
+            PathMap.Element<LRUEntry> element = get(id);
             if (element != null) {
                 return element.getDepth();
             }
@@ -269,9 +269,9 @@
             throws ItemNotFoundException, RepositoryException {
 
         if (itemId.denotesNode()) {
-            PathMap.Element element = get(nodeId);
+            PathMap.Element<LRUEntry> element = get(nodeId);
             if (element != null) {
-                PathMap.Element child = get(itemId);
+                PathMap.Element<LRUEntry> child = get(itemId);
                 if (child != null) {
                     return element.isAncestorOf(child);
                 }
@@ -311,10 +311,10 @@
                 // Item not cached, ignore
                 return;
             }
-            for (PathMap.Element element : entry.getElements()) {
-                Iterator iter = element.getChildren();
+            for (PathMap.Element<LRUEntry> element : entry.getElements()) {
+                Iterator<PathMap.Element<LRUEntry>> iter = element.getChildren();
                 while (iter.hasNext()) {
-                    PathMap.Element child = (PathMap.Element) iter.next();
+                    PathMap.Element<LRUEntry> child = iter.next();
                     ChildNodeEntry cne = modified.getChildNodeEntry(
                             child.getName(), child.getNormalizedIndex());
                     if (cne == null) {
@@ -323,7 +323,7 @@
                         continue;
                     }
 
-                    LRUEntry childEntry = (LRUEntry) child.get();
+                    LRUEntry childEntry = child.get();
                     if (childEntry != null && !cne.getId().equals(childEntry.getId())) {
                         // Different child item, remove
                         evict(child, true);
@@ -395,13 +395,14 @@
             if (entry == null) {
                 return;
             }
-            for (PathMap.Element parent : entry.getElements()) {
-                HashMap<Path.Element, PathMap.Element> newChildrenOrder = new HashMap<Path.Element, PathMap.Element>();
+            for (PathMap.Element<LRUEntry> parent : entry.getElements()) {
+                HashMap<Path.Element, PathMap.Element<LRUEntry>> newChildrenOrder =
+                    new HashMap<Path.Element, PathMap.Element<LRUEntry>>();
                 boolean orderChanged = false;
 
-                Iterator iter = parent.getChildren();
+                Iterator<PathMap.Element<LRUEntry>> iter = parent.getChildren();
                 while (iter.hasNext()) {
-                    PathMap.Element child = (PathMap.Element) iter.next();
+                    PathMap.Element<LRUEntry> child = iter.next();
                     LRUEntry childEntry = (LRUEntry) child.get();
                     if (childEntry == null) {
                         /**
@@ -479,7 +480,7 @@
      * @param id node id
      * @return cached element, <code>null</code> if not found
      */
-    private PathMap.Element get(ItemId id) {
+    private PathMap.Element<LRUEntry> get(ItemId id) {
         synchronized (cacheMonitor) {
             LRUEntry entry = (LRUEntry) idCache.get(id);
             if (entry != null) {
@@ -498,11 +499,11 @@
      * @param path path
      * @return cached element, <code>null</code> if not found
      */
-    private PathMap.Element map(Path path) {
+    private PathMap.Element<LRUEntry> map(Path path) {
         synchronized (cacheMonitor) {
-            PathMap.Element element = pathCache.map(path, false);
+            PathMap.Element<LRUEntry> element = pathCache.map(path, false);
             while (element != null) {
-                LRUEntry entry = (LRUEntry) element.get();
+                LRUEntry entry = element.get();
                 if (entry != null) {
                     entry.touch();
                     return element;
@@ -531,7 +532,7 @@
                  */
                 LRUEntry entry = head;
                 while (entry != null) {
-                    PathMap.Element[] elements = entry.getElements();
+                    PathMap.Element<LRUEntry>[] elements = entry.getElements();
                     int childrenCount = 0;
                     for (int i = 0; i < elements.length; i++) {
                         childrenCount += elements[i].getChildrenCount();
@@ -543,7 +544,7 @@
                     entry = entry.getNext();
                 }
             }
-            PathMap.Element element = pathCache.put(path);
+            PathMap.Element<LRUEntry> element = pathCache.put(path);
             if (element.get() != null) {
                 if (!id.equals(((LRUEntry) element.get()).getId())) {
                     log.warn("overwriting PathMap.Element");
@@ -582,7 +583,7 @@
             if (path == null) {
                 return true;
             }
-            PathMap.Element[] elements = entry.getElements();
+            PathMap.Element<LRUEntry>[] elements = entry.getElements();
             for (int i = 0; i < elements.length; i++) {
                 if (elements[i].hasPath(path)) {
                     return true;
@@ -601,7 +602,7 @@
      */
     boolean isCached(Path path) {
         synchronized (cacheMonitor) {
-            PathMap.Element element = pathCache.map(path, true);
+            PathMap.Element<LRUEntry> element = pathCache.map(path, true);
             if (element != null) {
                 return element.get() != null;
             }
@@ -620,7 +621,7 @@
         synchronized (cacheMonitor) {
             LRUEntry entry = (LRUEntry) idCache.get(id);
             if (entry != null) {
-                PathMap.Element[] elements = entry.getElements();
+                PathMap.Element<LRUEntry>[] elements = entry.getElements();
                 for (int i = 0; i < elements.length; i++) {
                     evict(elements[i], shift);
                 }
@@ -636,10 +637,10 @@
      *
      * @param element path map element
      */
-    private void evict(PathMap.Element element, boolean shift) {
+    private void evict(PathMap.Element<LRUEntry> element, boolean shift) {
         // assert: synchronized (cacheMonitor)
-        element.traverse(new PathMap.ElementVisitor() {
-            public void elementVisited(PathMap.Element element) {
+        element.traverse(new PathMap.ElementVisitor<LRUEntry>() {
+            public void elementVisited(PathMap.Element<LRUEntry> element) {
                 LRUEntry entry = (LRUEntry) element.get();
                 if (entry.removeElement(element) == 0) {
                     idCache.remove(entry.getId());
@@ -665,7 +666,7 @@
             throws RepositoryException, ItemStateException {
 
         // assert: synchronized (cacheMonitor)
-        PathMap.Element element = null;
+        PathMap.Element<LRUEntry> element = null;
 
         LRUEntry entry = (LRUEntry) idCache.get(id);
         if (entry != null) {
@@ -678,14 +679,14 @@
                 child = (NodeState) getItemState(id);
             }
             if (child == null || !child.isShareable()) {
-                PathMap.Element[] elements = entry.getElements();
+                PathMap.Element<LRUEntry>[] elements = entry.getElements();
                 element = elements[0];
                 for (int i = 0; i < elements.length; i++) {
                     elements[i].remove();
                 }
             }
         }
-        PathMap.Element parent = pathCache.map(path.getAncestor(1), true);
+        PathMap.Element<LRUEntry> parent = pathCache.map(path.getAncestor(1), true);
         if (parent != null) {
             parent.insert(path.getNameElement());
         }
@@ -710,11 +711,13 @@
             throws RepositoryException, ItemStateException {
 
         // assert: synchronized (cacheMonitor)
-        PathMap.Element parent = pathCache.map(path.getAncestor(1), true);
+        PathMap.Element<LRUEntry> parent =
+            pathCache.map(path.getAncestor(1), true);
         if (parent == null) {
             return;
         }
-        PathMap.Element element = parent.getDescendant(PathFactoryImpl.getInstance().create(
+        PathMap.Element<LRUEntry> element =
+            parent.getDescendant(PathFactoryImpl.getInstance().create(
                 new Path.Element[] { path.getNameElement() }), true);
         if (element != null) {
             // with SNS, this might evict a child that is NOT the one
@@ -749,8 +752,8 @@
      */
     public void dump(final PrintStream ps) {
         synchronized (cacheMonitor) {
-            pathCache.traverse(new PathMap.ElementVisitor() {
-                public void elementVisited(PathMap.Element element) {
+            pathCache.traverse(new PathMap.ElementVisitor<LRUEntry>() {
+                public void elementVisited(PathMap.Element<LRUEntry> element) {
                     StringBuffer line = new StringBuffer();
                     for (int i = 0; i < element.getDepth(); i++) {
                         line.append("--");
@@ -787,9 +790,9 @@
             elementsInCache += entry.getElements().length;
         }
 
-        class PathMapElementCounter implements PathMap.ElementVisitor {
+        class PathMapElementCounter implements PathMap.ElementVisitor<LRUEntry> {
             int count;
-            public void elementVisited(PathMap.Element element) {
+            public void elementVisited(PathMap.Element<LRUEntry> element) {
                 LRUEntry mappedEntry = (LRUEntry) element.get();
                 LRUEntry cachedEntry = (LRUEntry) idCache.get(mappedEntry.getId());
                 if (cachedEntry == null) {
@@ -804,7 +807,7 @@
                         cachedEntry.getId() + ").";
                     throw new IllegalStateException(msg);
                 }
-                PathMap.Element[] elements = cachedEntry.getElements();
+                PathMap.Element<LRUEntry>[] elements = cachedEntry.getElements();
                 for (int i = 0; i < elements.length; i++) {
                     if (elements[i] == element) {
                         count++;
@@ -850,7 +853,7 @@
         /**
          * Elements in path map
          */
-        private PathMap.Element[] elements;
+        private PathMap.Element<LRUEntry>[] elements;
 
         /**
          * Create a new instance of this class
@@ -858,7 +861,7 @@
          * @param id node id
          * @param element the path map element for this entry
          */
-        public LRUEntry(NodeId id, PathMap.Element element) {
+        public LRUEntry(NodeId id, PathMap.Element<LRUEntry> element) {
             this.id = id;
             this.elements = new PathMap.Element[] { element };
 
@@ -909,15 +912,6 @@
         }
 
         /**
-         * Return previous LRU entry
-         *
-         * @return previous LRU entry
-         */
-        public LRUEntry getPrevious() {
-            return previous;
-        }
-
-        /**
          * Return next LRU entry
          *
          * @return next LRU entry
@@ -942,15 +936,16 @@
          *
          * @return element in path map
          */
-        public PathMap.Element[] getElements() {
+        public PathMap.Element<LRUEntry>[] getElements() {
             return elements;
         }
 
         /**
          * Add a mapping to some element.
          */
-        public void addElement(PathMap.Element element) {
-            PathMap.Element[] tmp = new PathMap.Element[elements.length + 1];
+        public void addElement(PathMap.Element<LRUEntry> element) {
+            PathMap.Element<LRUEntry>[] tmp =
+                new PathMap.Element[elements.length + 1];
             System.arraycopy(elements, 0, tmp, 0, elements.length);
             tmp[elements.length] = element;
             elements = tmp;
@@ -961,7 +956,7 @@
          *
          * @return number of mappings left
          */
-        public int removeElement(PathMap.Element element) {
+        public int removeElement(PathMap.Element<LRUEntry> element) {
             boolean found = false;
             for (int i = 0; i < elements.length; i++) {
                 if (found) {
@@ -971,7 +966,8 @@
                 }
             }
             if (found) {
-                PathMap.Element[] tmp = new PathMap.Element[elements.length - 1];
+                PathMap.Element<LRUEntry>[] tmp =
+                    new PathMap.Element[elements.length - 1];
                 System.arraycopy(elements, 0, tmp, 0, tmp.length);
                 elements = tmp;
             }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java?rev=803119&r1=803118&r2=803119&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/lock/LockManagerImpl.java Tue Aug 11 13:46:15 2009
@@ -90,7 +90,8 @@
     /**
      * Path map containing all locks at the leaves.
      */
-    private final PathMap lockMap = new PathMap();
+    private final PathMap<AbstractLockInfo> lockMap =
+        new PathMap<AbstractLockInfo>();
 
     private final ReentrantLock lockMapLock = new ReentrantLock(){
 
@@ -244,9 +245,9 @@
 
         final ArrayList<AbstractLockInfo> list = new ArrayList<AbstractLockInfo>();
 
-        lockMap.traverse(new PathMap.ElementVisitor() {
-            public void elementVisited(PathMap.Element element) {
-                AbstractLockInfo info = (AbstractLockInfo) element.get();
+        lockMap.traverse(new PathMap.ElementVisitor<AbstractLockInfo>() {
+            public void elementVisited(PathMap.Element<AbstractLockInfo> element) {
+                AbstractLockInfo info = element.get();
                 if (!info.isSessionScoped()) {
                     list.add(info);
                 }
@@ -318,9 +319,9 @@
         try {
             // check whether node is already locked
             Path path = getPath(session, node.getId());
-            PathMap.Element element = lockMap.map(path, false);
+            PathMap.Element<AbstractLockInfo> element = lockMap.map(path, false);
 
-            LockInfo other = (LockInfo) element.get();
+            LockInfo other = element.get();
             if (other != null) {
                 if (element.hasPath(path)) {
                     throw new LockException("Node already locked: " + node);
@@ -378,11 +379,12 @@
         try {
             SessionImpl session = (SessionImpl) node.getSession();
             // check whether node is locked by this session
-            PathMap.Element element = lockMap.map(getPath(session, node.getId()), true);
+            PathMap.Element<AbstractLockInfo> element =
+                lockMap.map(getPath(session, node.getId()), true);
             if (element == null) {
                 throw new LockException("Node not locked: " + node);
             }
-            AbstractLockInfo info = (AbstractLockInfo) element.get();
+            AbstractLockInfo info = element.get();
             if (info == null) {
                 throw new LockException("Node not locked: " + node);
             }
@@ -415,10 +417,10 @@
      * @return an array of <code>AbstractLockInfo</code>s
      */
     AbstractLockInfo[] getLockInfos(final SessionImpl session) {
-        final ArrayList<LockInfo> infos = new ArrayList<LockInfo>();
-        lockMap.traverse(new PathMap.ElementVisitor() {
-            public void elementVisited(PathMap.Element element) {
-                LockInfo info = (LockInfo) element.get();
+        final ArrayList<AbstractLockInfo> infos = new ArrayList<AbstractLockInfo>();
+        lockMap.traverse(new PathMap.ElementVisitor<AbstractLockInfo>() {
+            public void elementVisited(PathMap.Element<AbstractLockInfo> element) {
+                AbstractLockInfo info = element.get();
                 if (info.isLive() && info.isLockHolder(session)) {
                     infos.add(info);
                 }
@@ -444,8 +446,8 @@
 
         acquire();
         try {
-            PathMap.Element element = lockMap.map(path, false);
-            AbstractLockInfo info = (AbstractLockInfo) element.get();
+            PathMap.Element<AbstractLockInfo> element = lockMap.map(path, false);
+            AbstractLockInfo info = element.get();
             if (info != null) {
                 if (element.hasPath(path) || info.isDeep()) {
                     return info;
@@ -487,8 +489,8 @@
             SessionImpl session = (SessionImpl) node.getSession();
             Path path = getPath(session, node.getId());
 
-            PathMap.Element element = lockMap.map(path, false);
-            AbstractLockInfo info = (AbstractLockInfo) element.get();
+            PathMap.Element<AbstractLockInfo> element = lockMap.map(path, false);
+            AbstractLockInfo info = element.get();
             if (info != null && (element.hasPath(path) || info.deep)) {
                 Node lockHolder = (Node) session.getItemManager().getItem(info.getId());
                 return new LockImpl(info, lockHolder);
@@ -544,7 +546,7 @@
 
         try {
             SessionImpl session = (SessionImpl) node.getSession();
-            PathMap.Element element = lockMap.map(getPath(session, node.getId()), true);
+            PathMap.Element<AbstractLockInfo> element = lockMap.map(getPath(session, node.getId()), true);
             if (element == null) {
                 return false;
             }
@@ -566,8 +568,8 @@
             SessionImpl session = (SessionImpl) node.getSession();
             Path path = getPath(session, node.getId());
 
-            PathMap.Element element = lockMap.map(path, false);
-            AbstractLockInfo info = (AbstractLockInfo) element.get();
+            PathMap.Element<AbstractLockInfo> element = lockMap.map(path, false);
+            AbstractLockInfo info = element.get();
             if (info == null) {
                 return false;
             }
@@ -599,8 +601,8 @@
     public void checkLock(Path path, Session session)
             throws LockException, RepositoryException {
 
-        PathMap.Element element = lockMap.map(path, false);
-        LockInfo info = (LockInfo) element.get();
+        PathMap.Element<AbstractLockInfo> element = lockMap.map(path, false);
+        LockInfo info = element.get();
         if (info != null) {
             if (element.hasPath(path) || info.isDeep()) {
                 checkLock(info, session);
@@ -635,12 +637,12 @@
             throws LockException, RepositoryException {
 
         // check whether node is locked by this session
-        PathMap.Element element = lockMap.map(getPath((SessionImpl) session,
-                node.getId()), true);
+        PathMap.Element<AbstractLockInfo> element =
+            lockMap.map(getPath((SessionImpl) session, node.getId()), true);
         if (element == null) {
             throw new LockException("Node not locked: " + node);
         }
-        AbstractLockInfo info = (AbstractLockInfo) element.get();
+        AbstractLockInfo info = element.get();
         if (info == null) {
             throw new LockException("Node not locked: " + node);
         }
@@ -677,9 +679,10 @@
 
             NodeImpl node = (NodeImpl)
                 this.sysSession.getItemManager().getItem(lockToken.getId());
-            PathMap.Element element = lockMap.map(node.getPrimaryPath(), true);
+            PathMap.Element<AbstractLockInfo> element =
+                lockMap.map(node.getPrimaryPath(), true);
             if (element != null) {
-                AbstractLockInfo info = (AbstractLockInfo) element.get();
+                AbstractLockInfo info = element.get();
                 if (info != null) {
                     if (info.isLockHolder(session)) {
                         // nothing to do
@@ -715,9 +718,10 @@
 
             NodeImpl node = (NodeImpl) this.sysSession.getItemManager()
                     .getItem(lockToken.getId());
-            PathMap.Element element = lockMap.map(node.getPrimaryPath(), true);
+            PathMap.Element<AbstractLockInfo> element =
+                lockMap.map(node.getPrimaryPath(), true);
             if (element != null) {
-                AbstractLockInfo info = (AbstractLockInfo) element.get();
+                AbstractLockInfo info = element.get();
                 if (info != null) {
                     if (info.isLockHolder(session)) {
                         info.setLockHolder(null);
@@ -979,16 +983,6 @@
         }
 
         /**
-         * Return the event type. May be {@link Event#NODE_ADDED},
-         * {@link Event#NODE_REMOVED} or a combination of both.\
-         *
-         * @return event type
-         */
-        public int getType() {
-            return type;
-        }
-
-        /**
          * Return the old path if this is a move operation
          *
          * @return old path
@@ -1011,9 +1005,9 @@
      * {@inheritDoc}
      */
     public void onEvent(EventIterator events) {
-        Iterator iter = consolidateEvents(events);
+        Iterator<HierarchyEvent> iter = consolidateEvents(events);
         while (iter.hasNext()) {
-            HierarchyEvent event = (HierarchyEvent) iter.next();
+            HierarchyEvent event = iter.next();
             if (event.type == Event.NODE_ADDED) {
                 nodeAdded(event.path);
             } else if (event.type == Event.NODE_REMOVED) {
@@ -1029,7 +1023,7 @@
      * add and remove operations on nodes with the same UUID into a move
      * operation.
      */
-    private Iterator consolidateEvents(EventIterator events) {
+    private Iterator<HierarchyEvent> consolidateEvents(EventIterator events) {
         LinkedMap eventMap = new LinkedMap();
 
         while (events.hasNext()) {
@@ -1062,15 +1056,14 @@
      * Refresh a non-empty path element whose children might have changed
      * its position.
      */
-    private void refresh(PathMap.Element element) {
+    private void refresh(PathMap.Element<AbstractLockInfo> element) {
         final ArrayList<AbstractLockInfo> infos = new ArrayList<AbstractLockInfo>();
         boolean needsSave = false;
 
         // save away non-empty children
-        element.traverse(new PathMap.ElementVisitor() {
-            public void elementVisited(PathMap.Element element) {
-                AbstractLockInfo info = (AbstractLockInfo) element.get();
-                infos.add(info);
+        element.traverse(new PathMap.ElementVisitor<AbstractLockInfo>() {
+            public void elementVisited(PathMap.Element<AbstractLockInfo> element) {
+                infos.add(element.get());
             }
         }, false);
 
@@ -1110,7 +1103,8 @@
         acquire();
 
         try {
-            PathMap.Element parent = lockMap.map(path.getAncestor(1), true);
+            PathMap.Element<AbstractLockInfo> parent =
+                lockMap.map(path.getAncestor(1), true);
             if (parent != null) {
                 refresh(parent);
             }
@@ -1132,7 +1126,8 @@
         acquire();
 
         try {
-            PathMap.Element parent = lockMap.map(oldPath.getAncestor(1), true);
+            PathMap.Element<AbstractLockInfo> parent =
+                lockMap.map(oldPath.getAncestor(1), true);
             if (parent != null) {
                 refresh(parent);
             }
@@ -1153,7 +1148,8 @@
         acquire();
 
         try {
-            PathMap.Element parent = lockMap.map(path.getAncestor(1), true);
+            PathMap.Element<AbstractLockInfo> parent =
+                lockMap.map(path.getAncestor(1), true);
             if (parent != null) {
                 refresh(parent);
             }
@@ -1286,11 +1282,11 @@
 
         try {
             Path path = getPath(sysSession, nodeId);
-            PathMap.Element element = lockMap.map(path, true);
+            PathMap.Element<AbstractLockInfo> element = lockMap.map(path, true);
             if (element == null) {
                 throw new LockException("Node not locked: " + path.toString());
             }
-            AbstractLockInfo info = (AbstractLockInfo) element.get();
+            AbstractLockInfo info = element.get();
             if (info == null) {
                 throw new LockException("Node not locked: " + path.toString());
             }
@@ -1310,8 +1306,8 @@
      * @param ps print stream to dump to
      */
     public void dump(final PrintStream ps) {
-        lockMap.traverse(new PathMap.ElementVisitor() {
-            public void elementVisited(PathMap.Element element) {
+        lockMap.traverse(new PathMap.ElementVisitor<AbstractLockInfo>() {
+            public void elementVisited(PathMap.Element<AbstractLockInfo> element) {
                 StringBuffer line = new StringBuffer();
                 for (int i = 0; i < element.getDepth(); i++) {
                     line.append("--");

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/retention/HoldImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/retention/HoldImpl.java?rev=803119&r1=803118&r2=803119&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/retention/HoldImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/retention/HoldImpl.java Tue Aug 11 13:46:15 2009
@@ -63,16 +63,16 @@
         return valueFactory.createValue(str);
     }
 
-    static Hold createFromValue(Value val, NodeId nodeId, NameResolver resolver) throws RepositoryException {
+    static HoldImpl createFromValue(Value val, NodeId nodeId, NameResolver resolver) throws RepositoryException {
         String str = val.getString();
         Name name = NAME_FACTORY.create(str.substring(2));
         boolean isDeep = str.startsWith(DEEP);
         return new HoldImpl(name, isDeep, nodeId, resolver);
     }
 
-    static Hold[] createFromProperty(PropertyImpl property, NodeId nodeId) throws RepositoryException {
+    static HoldImpl[] createFromProperty(PropertyImpl property, NodeId nodeId) throws RepositoryException {
         Value[] vs = property.getValues();
-        Hold[] holds = new Hold[vs.length];
+        HoldImpl[] holds = new HoldImpl[vs.length];
         for (int i = 0; i < vs.length; i++) {
             holds[i] = createFromValue(vs[i], nodeId, (SessionImpl) property.getSession());
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/retention/RetentionRegistryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/retention/RetentionRegistryImpl.java?rev=803119&r1=803118&r2=803119&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/retention/RetentionRegistryImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/retention/RetentionRegistryImpl.java Tue Aug 11 13:46:15 2009
@@ -63,8 +63,10 @@
      */
     private static final String FILE_NAME = "retention";
 
-    private final PathMap retentionMap  = new PathMap();
-    private final PathMap holdMap = new PathMap();
+    private final PathMap<RetentionPolicyImpl> retentionMap =
+        new PathMap<RetentionPolicyImpl>();
+
+    private final PathMap<List<HoldImpl>> holdMap = new PathMap<List<HoldImpl>>();
 
     private final SessionImpl session;
     private final FileSystemResource retentionFile;
@@ -150,23 +152,22 @@
      * present only once.
      */
     private void writeRetentionFile() {
-        final Set nodeIds = new HashSet();
+        final Set<NodeId> nodeIds = new HashSet<NodeId>();
 
         // first look for nodes containing holds
-        holdMap.traverse(new PathMap.ElementVisitor() {
-            public void elementVisited(PathMap.Element element) {
-                List holds = (List) element.get();
+        holdMap.traverse(new PathMap.ElementVisitor<List<HoldImpl>>() {
+            public void elementVisited(PathMap.Element<List<HoldImpl>> element) {
+                List<HoldImpl> holds = element.get();
                 if (!holds.isEmpty()) {
-                    nodeIds.add(((HoldImpl) holds.get(0)).getNodeId());
+                    nodeIds.add(holds.get(0).getNodeId());
                 }
             }
         }, false);
 
         // then collect ids of nodes having an retention policy
-        retentionMap.traverse(new PathMap.ElementVisitor() {
-            public void elementVisited(PathMap.Element element) {
-                RetentionPolicyImpl rp  = (RetentionPolicyImpl) element.get();
-                nodeIds.add(rp.getNodeId());
+        retentionMap.traverse(new PathMap.ElementVisitor<RetentionPolicyImpl>() {
+            public void elementVisited(PathMap.Element<RetentionPolicyImpl> element) {
+                nodeIds.add(element.get().getNodeId());
             }
         }, false);
 
@@ -174,7 +175,7 @@
             BufferedWriter writer = null;
             try {
                 writer = new BufferedWriter(new OutputStreamWriter(retentionFile.getOutputStream()));
-                for (Iterator it = nodeIds.iterator(); it.hasNext();) {
+                for (Iterator<NodeId> it = nodeIds.iterator(); it.hasNext();) {
                     writer.write(it.next().toString());
                     if (it.hasNext()) {
                         writer.newLine();
@@ -197,7 +198,7 @@
 
     private void addHolds(Path nodePath, PropertyImpl p) throws RepositoryException {
         synchronized (holdMap) {
-            Hold[] holds = HoldImpl.createFromProperty(p, ((PropertyId) p.getId()).getParentId());
+            HoldImpl[] holds = HoldImpl.createFromProperty(p, ((PropertyId) p.getId()).getParentId());
             holdMap.put(nodePath, Arrays.asList(holds));
             holdCnt++;
         }
@@ -205,7 +206,7 @@
 
     private void removeHolds(Path nodePath) {
         synchronized (holdMap) {
-            PathMap.Element el = holdMap.map(nodePath, true);
+            PathMap.Element<List<HoldImpl>> el = holdMap.map(nodePath, true);
             if (el != null) {
                 el.remove();
                 holdCnt--;
@@ -215,7 +216,8 @@
 
     private void addRetentionPolicy(Path nodePath, PropertyImpl p) throws RepositoryException {
         synchronized (retentionMap) {
-            RetentionPolicy rp = new RetentionPolicyImpl(p.getString(), ((PropertyId) p.getId()).getParentId(), session);
+            RetentionPolicyImpl rp = new RetentionPolicyImpl(
+                    p.getString(), ((PropertyId) p.getId()).getParentId(), session);
             retentionMap.put(nodePath, rp);
             retentionCnt++;
         }
@@ -223,7 +225,8 @@
 
     private void removeRetentionPolicy(Path nodePath) {
         synchronized (retentionMap) {
-            PathMap.Element el = retentionMap.map(nodePath, true);
+            PathMap.Element<RetentionPolicyImpl> el =
+                retentionMap.map(nodePath, true);
             if (el != null) {
                 el.remove();
                 retentionCnt--;
@@ -242,8 +245,8 @@
         if (holdCnt <= 0) {
             return false;
         }
-        PathMap.Element element = holdMap.map(nodePath, false);
-        List holds = (List) element.get();
+        PathMap.Element<List<HoldImpl>> element = holdMap.map(nodePath, false);
+        List<HoldImpl> holds = element.get();
         if (holds != null) {
             if (element.hasPath(nodePath)) {
                 // one or more holds on the specified path
@@ -257,9 +260,8 @@
                 // by a deep hold on any ancestor.
                 return true;
             } else {
-                for (Iterator it = holds.iterator(); it.hasNext();) {
-                    Hold h = (Hold) it.next();
-                    if (h.isDeep()) {
+                for (Hold hold : holds) {
+                    if (hold.isDeep()) {
                         return true;
                     }
                 }
@@ -280,14 +282,14 @@
             return false;
         }
         RetentionPolicy rp = null;
-        PathMap.Element element = retentionMap.map(nodePath, true);
+        PathMap.Element<RetentionPolicyImpl> element = retentionMap.map(nodePath, true);
         if (element != null) {
-            rp = (RetentionPolicy) element.get();
+            rp = element.get();
         }
         if (rp == null && checkParent) {
             element = retentionMap.map(nodePath.getAncestor(1), true);
             if (element != null) {
-                rp = (RetentionPolicy) element.get();
+                rp = element.get();
             }
         }
         return rp != null;

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathMap.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathMap.java?rev=803119&r1=803118&r2=803119&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathMap.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathMap.java Tue Aug 11 13:46:15 2009
@@ -21,6 +21,7 @@
 import org.apache.jackrabbit.spi.PathFactory;
 import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
 
+import java.util.List;
 import java.util.Map;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -31,14 +32,15 @@
  * Generic path map that associates information with the individual path elements
  * of a path.
  */
-public class PathMap {
+public class PathMap<T> {
 
     private static final PathFactory PATH_FACTORY = PathFactoryImpl.getInstance();
 
     /**
      * Root element
      */
-    private final Element root = new Element(PATH_FACTORY.getRootPath().getNameElement());
+    private final Element<T> root =
+        new Element<T>(PATH_FACTORY.getRootPath().getNameElement());
 
     /**
      * Map a path to a child. If <code>exact</code> is <code>false</code>,
@@ -48,12 +50,12 @@
      * @return child, maybe <code>null</code> if <code>exact</code> is
      *         <code>true</code>
      */
-    public Element map(Path path, boolean exact) {
+    public Element<T> map(Path path, boolean exact) {
         Path.Element[] elements = path.getElements();
-        Element current = root;
+        Element<T> current = root;
 
         for (int i = 1; i < elements.length; i++) {
-            Element next = current.getChild(elements[i]);
+            Element<T> next = current.getChild(elements[i]);
             if (next == null) {
                 if (exact) {
                     return null;
@@ -71,8 +73,8 @@
      * @param path path to child
      * @param obj object to store at destination
      */
-    public Element put(Path path, Object obj) {
-        Element element = put(path);
+    public Element<T> put(Path path, T obj) {
+        Element<T> element = put(path);
         element.obj = obj;
         return element;
     }
@@ -83,12 +85,12 @@
      * @param path path to child
      * @param element element to store at destination
      */
-    public void put(Path path, Element element) {
+    public void put(Path path, Element<T> element) {
         Path.Element[] elements = path.getElements();
-        Element current = root;
+        Element<T> current = root;
 
         for (int i = 1; i < elements.length - 1; i++) {
-            Element next = current.getChild(elements[i]);
+            Element<T> next = current.getChild(elements[i]);
             if (next == null) {
                 next = current.createChild(elements[i]);
             }
@@ -101,12 +103,12 @@
      * Create an empty child given by its path.
      * @param path path to child
      */
-    public Element put(Path path) {
+    public Element<T> put(Path path) {
         Path.Element[] elements = path.getElements();
-        Element current = root;
+        Element<T> current = root;
 
         for (int i = 1; i < elements.length; i++) {
-            Element next = current.getChild(elements[i]);
+            Element<T> next = current.getChild(elements[i]);
             if (next == null) {
                 next = current.createChild(elements[i]);
             }
@@ -123,7 +125,7 @@
      *                     or not; otherwise call back on non-empty children
      *                     only
      */
-    public void traverse(ElementVisitor visitor, boolean includeEmpty) {
+    public void traverse(ElementVisitor<T> visitor, boolean includeEmpty) {
         root.traverse(visitor, includeEmpty);
     }
 
@@ -131,17 +133,17 @@
      * Internal class holding the object associated with a certain
      * path element.
      */
-    public final static class Element {
+    public final static class Element<T> {
 
         /**
          * Parent element
          */
-        private Element parent;
+        private Element<T> parent;
 
         /**
          * Map of immediate children
          */
-        private Map children;
+        private Map<Name, List<Element<T>>> children;
 
         /**
          * Number of non-empty children
@@ -151,7 +153,7 @@
         /**
          * Object associated with this element
          */
-        private Object obj;
+        private T obj;
 
         /**
          * Path.Element suitable for path construction associated with this
@@ -185,8 +187,8 @@
          * @param nameIndex position where child is created
          * @return child
          */
-        private Element createChild(Path.Element nameIndex) {
-            Element element = new Element(nameIndex);
+        private Element<T> createChild(Path.Element nameIndex) {
+            Element<T> element = new Element<T>(nameIndex);
             put(nameIndex, element);
             return element;
         }
@@ -214,10 +216,10 @@
             // convert 1-based index value to 0-base value
             int index = getZeroBasedIndex(nameIndex);
             if (children != null) {
-                ArrayList list = (ArrayList) children.get(nameIndex.getName());
+                List<Element<T>> list = children.get(nameIndex.getName());
                 if (list != null && list.size() > index) {
                     for (int i = index; i < list.size(); i++) {
-                        Element element = (Element) list.get(i);
+                        Element<T> element = list.get(i);
                         if (element != null) {
                             element.index = element.getNormalizedIndex() + 1;
                             element.updatePathElement(element.getName(), element.index);
@@ -234,15 +236,15 @@
          * @return element matching <code>nameIndex</code> or <code>null</code> if
          *         none exists.
          */
-        private Element getChild(Path.Element nameIndex) {
+        private Element<T> getChild(Path.Element nameIndex) {
             // convert 1-based index value to 0-base value
             int index = getZeroBasedIndex(nameIndex);
-            Element element = null;
+            Element<T> element = null;
 
             if (children != null) {
-                ArrayList list = (ArrayList) children.get(nameIndex.getName());
+                List<Element<T>> list = children.get(nameIndex.getName());
                 if (list != null && list.size() > index) {
-                    element = (Element) list.get(index);
+                    element = list.get(index);
                 }
             }
             return element;
@@ -253,15 +255,15 @@
          * @param nameIndex position where child should be located
          * @param element element to add
          */
-        public void put(Path.Element nameIndex, Element element) {
+        public void put(Path.Element nameIndex, Element<T> element) {
             // convert 1-based index value to 0-base value
             int index = getZeroBasedIndex(nameIndex);
             if (children == null) {
-                children = new HashMap();
+                children = new HashMap<Name, List<Element<T>>>();
             }
-            ArrayList list = (ArrayList) children.get(nameIndex.getName());
+            List<Element<T>> list = children.get(nameIndex.getName());
             if (list == null) {
-                list = new ArrayList();
+                list = new ArrayList<Element<T>>();
                 children.put(nameIndex.getName(), list);
             }
             while (list.size() < index) {
@@ -289,7 +291,7 @@
          * @param nameIndex child's path element
          * @return removed child, may be <code>null</code>
          */
-        public Element remove(Path.Element nameIndex) {
+        public Element<T> remove(Path.Element nameIndex) {
             return remove(nameIndex, true, true);
         }
 
@@ -309,7 +311,7 @@
          *                      an element
          * @return removed child, may be <code>null</code>
          */
-        private Element remove(Path.Element nameIndex, boolean shift,
+        private Element<T> remove(Path.Element nameIndex, boolean shift,
                                boolean removeIfEmpty) {
 
             // convert 1-based index value to 0-base value
@@ -317,14 +319,14 @@
             if (children == null) {
                 return null;
             }
-            ArrayList list = (ArrayList) children.get(nameIndex.getName());
+            List<Element<T>> list = children.get(nameIndex.getName());
             if (list == null || list.size() <= index) {
                 return null;
             }
-            Element element = (Element) list.set(index, null);
+            Element<T> element = list.set(index, null);
             if (shift) {
                 for (int i = index + 1; i < list.size(); i++) {
-                    Element sibling = (Element) list.get(i);
+                    Element<T> sibling = list.get(i);
                     if (sibling != null) {
                         sibling.index--;
                         sibling.updatePathElement(sibling.getName(), sibling.index);
@@ -386,19 +388,14 @@
          *                 <code>Path.PathElement</code> and values
          *                 are of type <code>Element</code>
          */
-        public void setChildren(Map children) {
+        public void setChildren(Map<Path.Element, Element<T>> children) {
             // Remove all children without removing the element itself
             this.children = null;
             childrenCount = 0;
 
             // Now add back all items
-            Iterator entries = children.entrySet().iterator();
-            while (entries.hasNext()) {
-                Map.Entry entry = (Map.Entry) entries.next();
-
-                Path.Element nameIndex = (Path.Element) entry.getKey();
-                Element element = (Element) entry.getValue();
-                put(nameIndex, element);
+            for (Map.Entry<Path.Element, Element<T>> entry : children.entrySet()) {
+                put(entry.getKey(), entry.getValue());
             }
 
             // Special case: if map was empty, handle like removeAll()
@@ -411,7 +408,7 @@
          * Return the object associated with this element
          * @return object associated with this element
          */
-        public Object get() {
+        public T get() {
             return obj;
         }
 
@@ -419,7 +416,7 @@
          * Set the object associated with this element
          * @param obj object associated with this element
          */
-        public void set(Object obj) {
+        public void set(T obj) {
             this.obj = obj;
 
             if (obj == null && childrenCount == 0 && parent != null) {
@@ -542,16 +539,13 @@
          *        element regardless, whether the associated object is empty
          *        or not; otherwise call back on non-empty children only
          */
-        public void traverse(ElementVisitor visitor, boolean includeEmpty) {
+        public void traverse(ElementVisitor<T> visitor, boolean includeEmpty) {
             if (includeEmpty || obj != null) {
                 visitor.elementVisited(this);
             }
             if (children != null) {
-                Iterator iter = children.values().iterator();
-                while (iter.hasNext()) {
-                    ArrayList list = (ArrayList) iter.next();
-                    for (int i = 0; i < list.size(); i++) {
-                        Element element = (Element) list.get(i);
+                for (List<Element<T>>list : children.values()) {
+                    for (Element<T> element : list) {
                         if (element != null) {
                             element.traverse(visitor, includeEmpty);
                         }
@@ -578,8 +572,8 @@
          * child of this node.
          * @param other node to check
          */
-        public boolean isAncestorOf(Element other) {
-            Element parent = other.parent;
+        public boolean isAncestorOf(Element<T> other) {
+            Element<T> parent = other.parent;
             while (parent != null) {
                 if (parent == this) {
                     return true;
@@ -593,7 +587,7 @@
          * Return the parent of this element
          * @return parent or <code>null</code> if this is the root element
          */
-        public Element getParent() {
+        public Element<T> getParent() {
             return parent;
         }
 
@@ -609,15 +603,11 @@
          * Return an iterator over all of this element's children. Every
          * element returned by this iterator is of type {@link Element}.
          */
-        public Iterator getChildren() {
-            ArrayList result = new ArrayList();
-
+        public Iterator<Element<T>> getChildren() {
+            ArrayList<Element<T>> result = new ArrayList<Element<T>>();
             if (children != null) {
-                Iterator iter = children.values().iterator();
-                while (iter.hasNext()) {
-                    ArrayList list = (ArrayList) iter.next();
-                    for (int i = 0; i < list.size(); i++) {
-                        Element element = (Element) list.get(i);
+                for (List<Element<T>> list : children.values()) {
+                    for (Element<T> element : list) {
                         if (element != null) {
                             result.add(element);
                         }
@@ -637,12 +627,12 @@
          * @return descendant, maybe <code>null</code> if <code>exact</code> is
          *         <code>true</code>
          */
-        public Element getDescendant(Path relPath, boolean exact) {
+        public Element<T> getDescendant(Path relPath, boolean exact) {
             Path.Element[] elements = relPath.getElements();
-            Element current = this;
+            Element<T> current = this;
 
             for (int i = 0; i < elements.length; i++) {
-                Element next = current.getChild(elements[i]);
+                Element<T> next = current.getChild(elements[i]);
                 if (next == null) {
                     if (exact) {
                         return null;
@@ -658,12 +648,12 @@
     /**
      * Element visitor used in {@link PathMap#traverse}
      */
-    public interface ElementVisitor {
+    public interface ElementVisitor<T> {
 
         /**
          * Invoked for every element visited on a tree traversal
          * @param element element visited
          */
-        void elementVisited(Element element);
+        void elementVisited(Element<T> element);
     }
 }



Mime
View raw message