Author: j16sdiz
Date: 2009-04-03 06:44:22 +0000 (Fri, 03 Apr 2009)
New Revision: 26410

Modified:
   trunk/freenet/src/freenet/node/PacketTracker.java
   trunk/freenet/src/freenet/support/UpdatableSortedLinkedList.java
   trunk/freenet/src/freenet/support/UpdatableSortedLinkedListItemImpl.java
   
trunk/freenet/src/freenet/support/UpdatableSortedLinkedListWithForeignIndex.java
Log:
Even more (bug 2512)

Modified: trunk/freenet/src/freenet/node/PacketTracker.java
===================================================================
--- trunk/freenet/src/freenet/node/PacketTracker.java   2009-04-03 06:43:55 UTC 
(rev 26409)
+++ trunk/freenet/src/freenet/node/PacketTracker.java   2009-04-03 06:44:22 UTC 
(rev 26410)
@@ -250,7 +250,7 @@
                        return next;
                }
 
-               public final BaseQueuedResend setNext(Item i) {
+               public final BaseQueuedResend setNext(Item<?> i) {
                        BaseQueuedResend old = next;
                        next = (BaseQueuedResend)i;
                        return old;
@@ -260,7 +260,7 @@
                        return prev;
                }
 
-               public BaseQueuedResend setPrev(Item i) {
+               public BaseQueuedResend setPrev(Item<?> i) {
                        BaseQueuedResend old = prev;
                        prev = (BaseQueuedResend)i;
                        return old;
@@ -281,14 +281,14 @@
                public Object indexValue() {
                        return packetNumber;
                }
-               private DoublyLinkedList parent;
+               private DoublyLinkedList<? super BaseQueuedResend> parent;
 
-               public DoublyLinkedList getParent() {
+               public DoublyLinkedList<? super BaseQueuedResend> getParent() {
                        return parent;
                }
 
-               public DoublyLinkedList setParent(DoublyLinkedList l) {
-                       DoublyLinkedList old = parent;
+               public DoublyLinkedList<? super BaseQueuedResend> 
setParent(DoublyLinkedList<? super BaseQueuedResend> l) {
+                       DoublyLinkedList<? super BaseQueuedResend> old = parent;
                        parent = l;
                        return old;
                }

Modified: trunk/freenet/src/freenet/support/UpdatableSortedLinkedList.java
===================================================================
--- trunk/freenet/src/freenet/support/UpdatableSortedLinkedList.java    
2009-04-03 06:43:55 UTC (rev 26409)
+++ trunk/freenet/src/freenet/support/UpdatableSortedLinkedList.java    
2009-04-03 06:44:22 UTC (rev 26410)
@@ -2,7 +2,6 @@
 
 import java.util.Enumeration;
 import java.util.Iterator;
-import java.util.NoSuchElementException;
 
 /**
  * @author amphibian
@@ -11,7 +10,7 @@
  * and provides an update() function to move an item when its
  * value has changed. Allows duplicates.
  */
-public class UpdatableSortedLinkedList implements Iterable {
+public class UpdatableSortedLinkedList<T extends 
UpdatableSortedLinkedListItem<T>> implements Iterable<T> {
        boolean debug = false;
        protected boolean killed = false;
        private static volatile boolean logMINOR;
@@ -25,12 +24,12 @@
        }
        
     public UpdatableSortedLinkedList() {
-        list = new DoublyLinkedListImpl();
+        list = new DoublyLinkedListImpl<T>();
     }
     
-    private final DoublyLinkedList list;
+    private final DoublyLinkedList<T> list;
     
-    public synchronized void add(UpdatableSortedLinkedListItem i) throws 
UpdatableSortedLinkedListKilledException {
+    public synchronized void add(T i) throws 
UpdatableSortedLinkedListKilledException {
        if(killed) throw new UpdatableSortedLinkedListKilledException();
         if(logMINOR) Logger.minor(this, "Add("+i+") on "+this);
         if(list.isEmpty()) {
@@ -49,11 +48,10 @@
             return;
         }
         // Search the list for a good place to put it
-        Enumeration e = list.elements();
-        UpdatableSortedLinkedListItem prev = null;
+        Enumeration<T> e = list.elements();
+        T prev = null;
         while(e.hasMoreElements()) {
-            UpdatableSortedLinkedListItem cur = 
-                (UpdatableSortedLinkedListItem) e.nextElement();
+            T cur =  e.nextElement();
             if((prev != null) && (cur.compareTo(i) >= 0) && (prev.compareTo(i) 
<= 0)) {
                 list.insertNext(prev, i);
                 checkList();
@@ -89,18 +87,17 @@
        }
        }
 
-       public synchronized UpdatableSortedLinkedListItem 
remove(UpdatableSortedLinkedListItem i) throws 
UpdatableSortedLinkedListKilledException {
+       public synchronized T remove(T i) throws 
UpdatableSortedLinkedListKilledException {
        if(killed) throw new UpdatableSortedLinkedListKilledException();
        if(logMINOR) Logger.minor(this, "Remove("+i+") on "+this);
         checkList();
-        UpdatableSortedLinkedListItem item = 
-               (UpdatableSortedLinkedListItem) list.remove(i);
+        T item = list.remove(i);
         if(logMINOR) Logger.minor(this, "Returning "+item);
         checkList();
         return item;
     }
     
-       public synchronized void addOrUpdate(UpdatableSortedLinkedListItem 
item) throws UpdatableSortedLinkedListKilledException {
+       public synchronized void addOrUpdate(T item) throws 
UpdatableSortedLinkedListKilledException {
                if(item.getParent() == list)
                        update(item);
                else if(item.getParent() == null)
@@ -108,7 +105,7 @@
                else throw new IllegalStateException("Item "+item+" should be 
on our list: "+list+" or null, but is "+item.getParent());
        }
        
-    public synchronized void update(UpdatableSortedLinkedListItem i) throws 
UpdatableSortedLinkedListKilledException {
+    public synchronized void update(T i) throws 
UpdatableSortedLinkedListKilledException {
        if(killed) throw new UpdatableSortedLinkedListKilledException();
        if(logMINOR) Logger.minor(this, "Update("+i+") on "+this);
         checkList();
@@ -131,8 +128,8 @@
             return;
         }
         // Forwards or backwards?
-        UpdatableSortedLinkedListItem next = (UpdatableSortedLinkedListItem) 
list.next(i);
-        UpdatableSortedLinkedListItem prev = (UpdatableSortedLinkedListItem) 
list.prev(i);
+        T next = list.next(i);
+        T prev = list.prev(i);
         if((next == null) && (prev == null)) {
             return;
         }
@@ -148,7 +145,7 @@
             // i > next - move forwards
             while(true) {
                 prev = next;
-                next = (UpdatableSortedLinkedListItem) list.next(next);
+                next = list.next(next);
                 if(next == null) {
                     throw new NullPointerException("impossible - we checked");
                 }
@@ -163,7 +160,7 @@
             // i < next - move backwards
             while(true) {
                 next = prev;
-                prev = (UpdatableSortedLinkedListItem) list.prev(prev);
+                prev = list.prev(prev);
                 if(next == null) {
                     throw new NullPointerException("impossible - we checked");
                 }
@@ -224,7 +221,7 @@
     /**
      * @return Does the list contain that item?
      */
-    public synchronized boolean contains(UpdatableSortedLinkedListItem item) {
+    public synchronized boolean contains(T item) {
        return list.contains(item);
     }
     
@@ -238,8 +235,8 @@
     /**
      * @return The item on the list with the lowest value.
      */
-    public synchronized UpdatableSortedLinkedListItem getLowest() {
-        return (UpdatableSortedLinkedListItem) list.head();
+    public synchronized T getLowest() {
+        return list.head();
     }
     
     public synchronized void clear() {
@@ -251,23 +248,23 @@
        killed = true;
     }
 
-       public synchronized UpdatableSortedLinkedListItem removeLowest() throws 
UpdatableSortedLinkedListKilledException {
+       public synchronized T removeLowest() throws 
UpdatableSortedLinkedListKilledException {
                if(isEmpty()) return null;
-               UpdatableSortedLinkedListItem i = getLowest();
+               T i = getLowest();
                remove(i);
                return i;
        }
 
-       public synchronized void moveTo(UpdatableSortedLinkedList dest) throws 
UpdatableSortedLinkedListKilledException {
-               Enumeration e = list.elements();
+       public synchronized void moveTo(UpdatableSortedLinkedList<T> dest) 
throws UpdatableSortedLinkedListKilledException {
+               Enumeration<T> e = list.elements();
                while(e.hasMoreElements()) {
-                       UpdatableSortedLinkedListItem item = 
(UpdatableSortedLinkedListItem) e.nextElement();
+                       T item = e.nextElement();
                        remove(item);
                        dest.add(item);
                }
        }
 
-       public synchronized Iterator iterator() {
+       public synchronized Iterator<T> iterator() {
                return list.iterator();
        }
 }

Modified: 
trunk/freenet/src/freenet/support/UpdatableSortedLinkedListItemImpl.java
===================================================================
--- trunk/freenet/src/freenet/support/UpdatableSortedLinkedListItemImpl.java    
2009-04-03 06:43:55 UTC (rev 26409)
+++ trunk/freenet/src/freenet/support/UpdatableSortedLinkedListItemImpl.java    
2009-04-03 06:44:22 UTC (rev 26410)
@@ -36,14 +36,14 @@
         * removed completely?
         */
 
-       private DoublyLinkedList parentList;
+       private DoublyLinkedList<? super T> parentList;
 
-       public DoublyLinkedList getParent() {
+       public DoublyLinkedList<? super T> getParent() {
                return parentList;
        }
 
-       public DoublyLinkedList setParent(DoublyLinkedList l) {
-               DoublyLinkedList oldParent = parentList;
+       public DoublyLinkedList<? super T> setParent(DoublyLinkedList<? super 
T> l) {
+               DoublyLinkedList<? super T> oldParent = parentList;
                parentList = l;
                return oldParent;
        }

Modified: 
trunk/freenet/src/freenet/support/UpdatableSortedLinkedListWithForeignIndex.java
===================================================================
--- 
trunk/freenet/src/freenet/support/UpdatableSortedLinkedListWithForeignIndex.java
    2009-04-03 06:43:55 UTC (rev 26409)
+++ 
trunk/freenet/src/freenet/support/UpdatableSortedLinkedListWithForeignIndex.java
    2009-04-03 06:44:22 UTC (rev 26410)
@@ -9,22 +9,22 @@
  * Note that this class, unlike its parent, does not permit 
  * duplicates.
  */
-public class UpdatableSortedLinkedListWithForeignIndex extends 
UpdatableSortedLinkedList {
+public class UpdatableSortedLinkedListWithForeignIndex<T extends 
IndexableUpdatableSortedLinkedListItem<T>> extends UpdatableSortedLinkedList<T> 
{
 
-    final HashMap map;
+    final HashMap<Object, T> map;
 
     public UpdatableSortedLinkedListWithForeignIndex() {
         super();
-        map = new HashMap();
+        map = new HashMap<Object, T>();
     }
     
     @Override
-       public synchronized void add(UpdatableSortedLinkedListItem item) throws 
UpdatableSortedLinkedListKilledException {
+       public synchronized void add(T item) throws 
UpdatableSortedLinkedListKilledException {
         if(!(item instanceof IndexableUpdatableSortedLinkedListItem)) {
             throw new IllegalArgumentException();
         }
        if(killed) throw new UpdatableSortedLinkedListKilledException();
-        IndexableUpdatableSortedLinkedListItem i = 
(IndexableUpdatableSortedLinkedListItem)item;
+        T i = item;
         if(map.get(i.indexValue()) != null) {
             // Ignore duplicate
             Logger.error(this, "Ignoring duplicate: "+i+" was already present: 
"+map.get(i.indexValue()));
@@ -36,21 +36,21 @@
     }
     
     @Override
-       public synchronized UpdatableSortedLinkedListItem 
remove(UpdatableSortedLinkedListItem item) throws 
UpdatableSortedLinkedListKilledException {
+       public synchronized T remove(T item) throws 
UpdatableSortedLinkedListKilledException {
        if(killed) throw new UpdatableSortedLinkedListKilledException();
-        
map.remove(((IndexableUpdatableSortedLinkedListItem)item).indexValue());
+        
map.remove(((IndexableUpdatableSortedLinkedListItem<?>)item).indexValue());
         return super.remove(item);
     }
     
-       public synchronized IndexableUpdatableSortedLinkedListItem get(Object 
key) {
-               return (IndexableUpdatableSortedLinkedListItem)map.get(key);
+       public synchronized IndexableUpdatableSortedLinkedListItem<?> 
get(Object key) {
+               return (IndexableUpdatableSortedLinkedListItem<?>)map.get(key);
        }
 
     public synchronized boolean containsKey(Object key) {
         return map.containsKey(key);
     }
     
-    public synchronized boolean 
contains(IndexableUpdatableSortedLinkedListItem item) {
+    public synchronized boolean 
contains(IndexableUpdatableSortedLinkedListItem<?> item) {
        return containsKey(item.indexValue());
     }
 
@@ -58,10 +58,9 @@
      * Remove an element from the list by its key.
      * @throws UpdatableSortedLinkedListKilledException 
      */
-    public synchronized IndexableUpdatableSortedLinkedListItem 
removeByKey(Object key) throws UpdatableSortedLinkedListKilledException {
+    public synchronized IndexableUpdatableSortedLinkedListItem<?> 
removeByKey(Object key) throws UpdatableSortedLinkedListKilledException {
        if(killed) throw new UpdatableSortedLinkedListKilledException();
-        IndexableUpdatableSortedLinkedListItem item = 
-            (IndexableUpdatableSortedLinkedListItem) map.get(key);
+        T item = map.get(key);
         if(item != null) remove(item);
         checkList();
         return item;

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to