Author: nextgens
Date: 2008-08-15 22:19:38 +0000 (Fri, 15 Aug 2008)
New Revision: 21924

Modified:
   trunk/freenet/src/freenet/store/RAMFreenetStore.java
   trunk/freenet/src/freenet/support/DoublyLinkedList.java
   trunk/freenet/src/freenet/support/DoublyLinkedListImpl.java
   trunk/freenet/src/freenet/support/LRUHashtable.java
Log:
Untested patch to use generics

Modified: trunk/freenet/src/freenet/store/RAMFreenetStore.java
===================================================================
--- trunk/freenet/src/freenet/store/RAMFreenetStore.java        2008-08-15 
21:54:08 UTC (rev 21923)
+++ trunk/freenet/src/freenet/store/RAMFreenetStore.java        2008-08-15 
22:19:38 UTC (rev 21924)
@@ -17,7 +17,7 @@
                byte[] fullKey;
        }
        
-       private final LRUHashtable blocksByRoutingKey;
+       private final LRUHashtable<ByteArrayWrapper, Block> blocksByRoutingKey;
        
        private final StoreCallback callback;
        
@@ -29,7 +29,7 @@
        
        public RAMFreenetStore(StoreCallback callback, int maxKeys) {
                this.callback = callback;
-               this.blocksByRoutingKey = new LRUHashtable();
+               this.blocksByRoutingKey = new LRUHashtable<ByteArrayWrapper, 
Block>();
                this.maxKeys = maxKeys;
                callback.setStore(this);
        }
@@ -37,7 +37,7 @@
        public synchronized StorableBlock fetch(byte[] routingKey, byte[] 
fullKey,
                        boolean dontPromote) throws IOException {
                ByteArrayWrapper key = new ByteArrayWrapper(routingKey);
-               Block block = (Block) blocksByRoutingKey.get(key);
+               Block block = blocksByRoutingKey.get(key);
                if(block == null) {
                        misses++;
                        return null;
@@ -77,7 +77,7 @@
                        KeyCollisionException {
                writes++;
                ByteArrayWrapper key = new ByteArrayWrapper(routingkey);
-               Block oldBlock = (Block) blocksByRoutingKey.get(key);
+               Block oldBlock = blocksByRoutingKey.get(key);
                boolean storeFullKeys = callback.storeFullKeys();
                if(oldBlock != null) {
                        if(callback.collisionPossible()) {

Modified: trunk/freenet/src/freenet/support/DoublyLinkedList.java
===================================================================
--- trunk/freenet/src/freenet/support/DoublyLinkedList.java     2008-08-15 
21:54:08 UTC (rev 21923)
+++ trunk/freenet/src/freenet/support/DoublyLinkedList.java     2008-08-15 
22:19:38 UTC (rev 21924)
@@ -6,36 +6,36 @@
  * Framework for managing a doubly linked list.
  * @author tavin
  */
-public interface DoublyLinkedList {
-    public abstract Object clone();
+public interface DoublyLinkedList<T> {
+    public abstract DoublyLinkedList<T> clone();
 
     /**
      * List element
      */
-    public interface Item {
+    public interface Item<T> {
                /**
                 * Get next [EMAIL PROTECTED] Item}. May or may not return
                 * <code>null</code> if this is the last <code>Item</code>.
                 * 
                 * @see DoublyLinkedList#hasNext()
                 */
-        Item getNext();
+        DoublyLinkedList.Item<T> getNext();
         /** Set next [EMAIL PROTECTED] Item} */
-        Item setNext(Item i);
+        DoublyLinkedList.Item<T> setNext(DoublyLinkedList.Item<T> i);
         /**
         * Get previous [EMAIL PROTECTED] Item}. May or may not return 
<code>null</code>
         * if this is the first <code>Item</code>.
         * 
         * @see DoublyLinkedList#hasNext()
         */
-        Item getPrev();
+        Item<T> getPrev();
         /** Get previous [EMAIL PROTECTED] Item} */
-        Item setPrev(Item i);
+        Item<T> setPrev(DoublyLinkedList.Item<T> i);
         
         /** Return the contained list. <strong>For sanity checking 
only.</strong> */
-        DoublyLinkedList getParent();
+        DoublyLinkedList<T> getParent();
         /** Set the contained list. <strong>For sanity checking 
only.</strong>*/
-        DoublyLinkedList setParent(DoublyLinkedList l);
+        DoublyLinkedList<T> setParent(DoublyLinkedList<T> l);
     }
     
     /** Clear this list */
@@ -61,11 +61,11 @@
     /**
      * Puts the item before the first item.
      */
-    void unshift(Item i);
+    void unshift(DoublyLinkedList.Item<T> i);
     /**
      * Put all items in the specified list before the first item.
      */
-    void unshift(DoublyLinkedList l);
+    void unshift(DoublyLinkedList<T> l);
     /**
      * Removes and returns the first item.
      */
@@ -73,16 +73,16 @@
     /**
      * Remove <tt>n</tt> elements from head and return them as a 
<code>DoublyLinkedList</code>.
      */
-    DoublyLinkedList shift(int n);
+    DoublyLinkedList<T> shift(int n);
 
     /**
      * Puts the item after the last item.
      */
-    void push(Item i);
+    void push(DoublyLinkedList.Item<T> i);
     /**
      * Puts all items in the specified list after the last item.
      */
-    void push(DoublyLinkedList l);
+    void push(DoublyLinkedList<T> l);
     /**
      * Removes and returns the last item.
      */
@@ -93,34 +93,34 @@
     DoublyLinkedList pop(int n);
 
     /** @return <code>true</code> if <code>i</code> has next item. (ie. not 
the last item); <code>false</code> otherwise */ 
-    boolean hasNext(Item i);
+    boolean hasNext(DoublyLinkedList.Item<T> i);
     /** @return <code>true</code> if <code>i</code> has previous item. (ie. 
not the first item); <code>false</code> otherwise */
-    boolean hasPrev(Item i);
+    boolean hasPrev(DoublyLinkedList.Item<T> i);
 
     /** @return next item of <code>i</code>. If this is the last element, 
return <code>null</code> */
-    Item next(Item i);
+    Item next(DoublyLinkedList.Item<T> i);
     /** @return previous item of <code>i</code>. If this is the first element, 
return <code>null</code> */
-    Item prev(Item i);
+    Item prev(DoublyLinkedList.Item<T> i);
     /** Remove and return a element 
      * @return  this item, or <code>null</code> if the item was not in the list
      */
-    Item remove(Item i);
+    Item remove(DoublyLinkedList.Item<T> i);
     /**
      * Inserts item <code>j</code> before item <code>i</code>.
      */
-    void insertPrev(Item i, Item j);
+    void insertPrev(DoublyLinkedList.Item<T> i, DoublyLinkedList.Item<T> j);
     /**
      * Inserts the entire [EMAIL PROTECTED] DoublyLinkedList} <code>l</code> 
before item <code>i</code>.
      */
-    void insertPrev(Item i, DoublyLinkedList l);  
+    void insertPrev(DoublyLinkedList.Item<T> i, DoublyLinkedList<T> l);  
     /**
      * Inserts item <code>j</code> after item <code>i</code.
      */
-    void insertNext(Item i, Item j);    
+    void insertNext(DoublyLinkedList.Item<T> i, DoublyLinkedList.Item<T> j);   
 
     /**
      * Inserts the entire [EMAIL PROTECTED] DoublyLinkedList} <code>l</code> 
after item <code>i</code>.
      */
-    void insertNext(Item i, DoublyLinkedList l);
+    void insertNext(DoublyLinkedList.Item<T> i, DoublyLinkedList<T> l);
 }
 
 

Modified: trunk/freenet/src/freenet/support/DoublyLinkedListImpl.java
===================================================================
--- trunk/freenet/src/freenet/support/DoublyLinkedListImpl.java 2008-08-15 
21:54:08 UTC (rev 21923)
+++ trunk/freenet/src/freenet/support/DoublyLinkedListImpl.java 2008-08-15 
22:19:38 UTC (rev 21924)
@@ -10,27 +10,28 @@
  * TODO: there are still some unimplemented methods
  *       -- it remains to be seen if they are needed at all
  */
-public class DoublyLinkedListImpl implements DoublyLinkedList {
+public class DoublyLinkedListImpl<T> implements DoublyLinkedList<T>{
 
     protected int size;
-    protected Item _headptr, _tailptr;
+    protected DoublyLinkedListImpl.Item<T> _headptr, _tailptr;
 
-    public final Object clone() {
-        return new DoublyLinkedListImpl(this);
+       @Override
+    public final DoublyLinkedListImpl<T> clone() {
+        return new DoublyLinkedListImpl<T>(this);
     }
     
     /**
      * A new list with no items.
      */
     public DoublyLinkedListImpl() {
-        _headptr = new Item();
-        _tailptr = new Item();
+        _headptr = new Item<T>();
+        _tailptr = new Item<T>();
         _headptr.setParent(this);
         _tailptr.setParent(this);
         clear();
     }
 
-    protected DoublyLinkedListImpl(Item _h, Item _t, int size) {
+    protected DoublyLinkedListImpl(DoublyLinkedListImpl.Item<T> _h, 
DoublyLinkedListImpl.Item<T> _t, int size) {
         _headptr  = _h;
         _tailptr  = _t;
         _headptr.setParent(this);
@@ -44,11 +45,11 @@
      */
     protected DoublyLinkedListImpl(DoublyLinkedListImpl impl) {
         this();
-        Enumeration e = impl.forwardElements();
+        Enumeration<DoublyLinkedListImpl.Item<T>> e = impl.forwardElements();
         boolean checked = false;
         for(;e.hasMoreElements();) {
-            Item oi = (Item)e.nextElement();
-            Item i = (Item) oi.clone();
+            DoublyLinkedListImpl.Item<T> oi = e.nextElement();
+            DoublyLinkedList.Item<T> i = oi.clone();
             if(!checked) {
                 checked = true;
                 if(!i.getClass().getName().equals(oi.getClass().getName())) {
@@ -69,8 +70,8 @@
        // Help to detect removal after clear().
        // The check in remove() is enough, strictly,
        // as long as people don't add elements afterwards.
-       DoublyLinkedList.Item pos = _headptr.next;
-       DoublyLinkedList.Item opos = _headptr;
+       DoublyLinkedList.Item<T> pos = _headptr.next;
+       DoublyLinkedList.Item<T> opos = _headptr;
        while(true) {
                if(pos == _tailptr) break;
                if(pos == null) break;
@@ -103,21 +104,21 @@
      * [EMAIL PROTECTED]
      * @see #forwardElements()
      */
-    public final Enumeration elements() {
+    public final Enumeration<DoublyLinkedList.Item<T>> elements() {
         return forwardElements();
     }
 
     /**
      * [EMAIL PROTECTED]
      */
-    public final DoublyLinkedList.Item head() {
+    public final DoublyLinkedList.Item<T> head() {
         return size == 0 ? null : _headptr.next;
     }
 
     /**
      * [EMAIL PROTECTED]
      */
-    public final DoublyLinkedList.Item tail() {
+    public final DoublyLinkedList.Item<T> tail() {
         return size == 0 ? null : _tailptr.prev;
     }
 
@@ -126,7 +127,7 @@
     /**
      * [EMAIL PROTECTED]
      */
-    public final void unshift(DoublyLinkedList.Item i) {
+    public final void unshift(DoublyLinkedList.Item<T> i) {
         insertNext(_headptr, i);
     }
     
@@ -134,30 +135,30 @@
      * [EMAIL PROTECTED]
      *  FIXME: unimplemented
      */
-    public void unshift(DoublyLinkedList l) {
+    public void unshift(DoublyLinkedList<T> l) {
         throw new RuntimeException("function currently unimplemented because i 
am a lazy sod");
     }
     /**
      * [EMAIL PROTECTED]
      */
-    public final DoublyLinkedList.Item shift() {
+    public final DoublyLinkedList.Item<T> shift() {
         return size == 0 ? null : remove(_headptr.next);
     }
     /**
      * [EMAIL PROTECTED]
      */
-    public DoublyLinkedList shift(int n) {
+    public DoublyLinkedList<T> shift(int n) {
 
         if (n > size) n = size;
-        if (n < 1) return new DoublyLinkedListImpl();
+        if (n < 1) return new DoublyLinkedListImpl<T>();
 
-        DoublyLinkedList.Item i = _headptr;
+        DoublyLinkedList.Item<T> i = _headptr;
         for (int m=0; m<n; ++m)
             i = i.getNext();
 
-        DoublyLinkedList.Item j = i.getNext();
-        Item newheadptr = new Item();
-        Item newtailptr = new Item();
+        DoublyLinkedList.Item<T> j = i.getNext();
+        Item<T> newheadptr = new Item<T>();
+        Item<T> newtailptr = new Item<T>();
 
         j.setPrev(newheadptr);
         newheadptr.setNext(j);
@@ -165,7 +166,7 @@
         i.setNext(newtailptr);
         newtailptr.setPrev(i);
 
-        DoublyLinkedList newlist = new DoublyLinkedListImpl(_headptr, 
newtailptr, n);
+        DoublyLinkedList<T> newlist = new DoublyLinkedListImpl<T>(_headptr, 
newtailptr, n);
         _headptr = newheadptr;
         _headptr.setParent(this);
         size -= n;
@@ -178,37 +179,37 @@
     /**
      * [EMAIL PROTECTED]
      */
-    public final void push(DoublyLinkedList.Item i) {
+    public final void push(DoublyLinkedList.Item<T> i) {
         insertPrev(_tailptr, i);
     }
     /**
      * [EMAIL PROTECTED]
      * FIXME: unimplemented
      */
-    public void push(DoublyLinkedList l) {
+    public void push(DoublyLinkedList<T> l) {
         throw new RuntimeException("function currently unimplemented because i 
am a lazy sod");
     }
     /**
      * [EMAIL PROTECTED]
      */
-    public final DoublyLinkedList.Item pop() {
+    public final DoublyLinkedList.Item<T> pop() {
         return size == 0 ? null : remove(_tailptr.prev);
     }
     /**
      * [EMAIL PROTECTED]
      */
-    public DoublyLinkedList pop(int n) {
+    public DoublyLinkedList<T> pop(int n) {
 
         if (n > size) n = size;
-        if (n < 1) return new DoublyLinkedListImpl();
+        if (n < 1) return new DoublyLinkedListImpl<T>();
 
-        DoublyLinkedList.Item i = _tailptr;
+        DoublyLinkedList.Item<T> i = _tailptr;
         for (int m=0; m<n; ++m)
             i = i.getPrev();
 
-        DoublyLinkedList.Item j = i.getPrev();
-        Item newtailptr = new Item();
-        Item newheadptr = new Item();
+        DoublyLinkedList.Item<T> j = i.getPrev();
+        DoublyLinkedListImpl.Item<T> newtailptr = new Item<T>();
+        DoublyLinkedListImpl.Item<T> newheadptr = new Item<T>();
 
         j.setNext(newtailptr);
         newtailptr.setPrev(j);
@@ -217,7 +218,7 @@
         i.setPrev(newheadptr);
         newheadptr.setNext(i);
 
-        DoublyLinkedList newlist = new DoublyLinkedListImpl(newheadptr, 
_tailptr, n);
+        DoublyLinkedList<T> newlist = new DoublyLinkedListImpl<T>(newheadptr, 
_tailptr, n);
         _tailptr = newtailptr;
         size -= n;
         
@@ -229,29 +230,29 @@
     /**
      * [EMAIL PROTECTED]
      */
-    public final boolean hasNext(DoublyLinkedList.Item i) {
-        DoublyLinkedList.Item next = i.getNext();
+    public final boolean hasNext(DoublyLinkedList.Item<T> i) {
+        DoublyLinkedList.Item<T> next = i.getNext();
         return (next != null) && (next != _tailptr);
     }
     /**
      * [EMAIL PROTECTED]
      */
-    public final boolean hasPrev(DoublyLinkedList.Item i) {
-        DoublyLinkedList.Item prev = i.getPrev();
+    public final boolean hasPrev(DoublyLinkedList.Item<T> i) {
+        DoublyLinkedList.Item<T> prev = i.getPrev();
         return (prev != null) && (prev != _headptr);
     }
     /**
      * [EMAIL PROTECTED]
      */
-    public final DoublyLinkedList.Item next(DoublyLinkedList.Item i) {
-        DoublyLinkedList.Item next = i.getNext();
+    public final DoublyLinkedList.Item<T> next(DoublyLinkedList.Item<T> i) {
+        DoublyLinkedList.Item<T> next = i.getNext();
         return next == _tailptr ? null : next;
     }
     /**
      * [EMAIL PROTECTED]
      */
-    public final DoublyLinkedList.Item prev(DoublyLinkedList.Item i) {
-        DoublyLinkedList.Item prev = i.getPrev();
+    public final DoublyLinkedList.Item<T> prev(DoublyLinkedList.Item<T> i) {
+        DoublyLinkedList.Item<T> prev = i.getPrev();
         return prev == _headptr ? null : prev;
     }
 
@@ -261,7 +262,7 @@
     /**
      * [EMAIL PROTECTED]
      */
-    public DoublyLinkedList.Item remove(DoublyLinkedList.Item i) {
+    public DoublyLinkedList.Item<T> remove(DoublyLinkedList.Item<T> i) {
        if (i.getParent() == null) return null; // not in list
        if(isEmpty()) {
                Logger.error(this, "Illegal ERROR: Removing from an empty 
list!!");
@@ -269,7 +270,7 @@
        }
        if (i.getParent() != this)
                throw new PromiscuousItemException(i, i.getParent());
-        DoublyLinkedList.Item next = i.getNext(), prev = i.getPrev();
+        DoublyLinkedList.Item<T> next = i.getNext(), prev = i.getPrev();
         if ((next == null) && (prev == null)) return null;  // not in the list
         if ((next == null) || (prev == null))
                throw new NullPointerException("next="+next+", prev="+prev); // 
partially in the list?!
@@ -290,7 +291,7 @@
     /**
      * [EMAIL PROTECTED]
      */
-    public void insertPrev(DoublyLinkedList.Item i, DoublyLinkedList.Item j) {
+    public void insertPrev(DoublyLinkedList.Item<T> i, 
DoublyLinkedList.Item<T> j) {
        if (i.getParent() == null)
                throw new PromiscuousItemException(i, i.getParent()); // 
different trace to make easier debugging
        if (i.getParent() != this)
@@ -299,7 +300,7 @@
                throw new PromiscuousItemException(j, j.getParent());
         if ((j.getNext() != null) || (j.getPrev() != null))
             throw new PromiscuousItemException(j);
-        DoublyLinkedList.Item prev = i.getPrev();
+        DoublyLinkedList.Item<T> prev = i.getPrev();
         if (prev == null)
             throw new VirginItemException(i);
         prev.setNext(j);
@@ -314,14 +315,14 @@
      * [EMAIL PROTECTED]
      * FIXME: unimplemented
      */
-    public void insertPrev(DoublyLinkedList.Item i, DoublyLinkedList l) {
+    public void insertPrev(DoublyLinkedList.Item<T> i, DoublyLinkedList<T> l) {
         throw new RuntimeException("function currently unimplemented because i 
am a lazy sod");
     }
 
     /**
      * [EMAIL PROTECTED]
      */
-    public void insertNext(DoublyLinkedList.Item i, DoublyLinkedList.Item j) {
+    public void insertNext(DoublyLinkedList.Item<T> i, 
DoublyLinkedList.Item<T> j) {
        if (i.getParent() != this)
                throw new PromiscuousItemException(i, i.getParent());
        if (j.getParent() != null)
@@ -343,7 +344,7 @@
      * [EMAIL PROTECTED]
      * FIXME: unimplemented
      */
-    public void insertNext(DoublyLinkedList.Item i, DoublyLinkedList l) {
+    public void insertNext(DoublyLinkedList.Item<T> i, DoublyLinkedList<T> l) {
         throw new RuntimeException("function currently unimplemented because i 
am a lazy sod");
     }
 
@@ -353,54 +354,54 @@
     /**
      * @return  an Enumeration of list elements from head to tail
      */
-    private Enumeration forwardElements() {
+    private Enumeration<DoublyLinkedList.Item<T>> forwardElements() {
         return new ForwardWalker();
     }
 
     /**
      * @return  an Enumeration of list elements from tail to head
      */
-    protected Enumeration reverseElements() {
+    protected Enumeration<DoublyLinkedList.Item<T>> reverseElements() {
         return new ReverseWalker();
     }
 
-    private class ForwardWalker implements Enumeration {
-        protected DoublyLinkedList.Item next;
+    private class ForwardWalker<T extends DoublyLinkedListImpl.Item<T>> 
implements Enumeration<DoublyLinkedList.Item<T>> {
+        protected DoublyLinkedList.Item<T> next;
         protected ForwardWalker() {
             next = _headptr.getNext();
         }
-        protected ForwardWalker(DoublyLinkedList.Item startAt,
+        protected ForwardWalker(DoublyLinkedList.Item<T> startAt,
                                 boolean inclusive) {
             next = (inclusive ? startAt : startAt.getNext());
         }
         public final boolean hasMoreElements() {
             return next != _tailptr;
         }
-        public Object nextElement() {
+        public DoublyLinkedList.Item<T> nextElement() {
             if (next == _tailptr)
                 throw new NoSuchElementException();
-            DoublyLinkedList.Item result = next;
+            DoublyLinkedList.Item<T> result = next;
             next = next.getNext();
             return result;
         }
     }
 
-    private class ReverseWalker implements Enumeration {
-        protected DoublyLinkedList.Item next;
+    private class ReverseWalker<T extends DoublyLinkedList.Item<T>> implements 
Enumeration<DoublyLinkedList.Item<T>> {
+        protected DoublyLinkedList.Item<T> next;
         protected ReverseWalker() {
             next = _tailptr.getPrev();
         }
-        protected ReverseWalker(DoublyLinkedList.Item startAt,
+        protected ReverseWalker(DoublyLinkedList.Item<T> startAt,
                                 boolean inclusive) {
             next = (inclusive ? startAt : startAt.getPrev());
         }
         public final boolean hasMoreElements() {
             return next != _headptr;
         }
-        public Object nextElement() {
+        public DoublyLinkedList.Item<T> nextElement() {
             if (next == _headptr)
                 throw new NoSuchElementException();
-            DoublyLinkedList.Item result = next;
+            DoublyLinkedList.Item<T> result = next;
            if(next == null) throw new IllegalStateException("next==null");
             next = next.getPrev();
             return result;
@@ -410,35 +411,36 @@
 
     //=== list element ====================================================
 
-    public static class Item implements DoublyLinkedList.Item {
-        private DoublyLinkedList.Item prev;
-        private DoublyLinkedList.Item next;
+    public static class Item<T> implements DoublyLinkedList.Item<T> {
+        private DoublyLinkedList.Item<T> prev;
+        private DoublyLinkedList.Item<T> next;
         private DoublyLinkedList list;
-        public Object clone() {
+               @Override
+        public DoublyLinkedList.Item<T> clone() {
             if(getClass() != Item.class)
                 throw new RuntimeException("Must implement clone() for 
"+getClass());
-            return new Item();
+            return new Item<T>();
         }
         public final DoublyLinkedList.Item getNext() {
             return next;
         }
-        public final DoublyLinkedList.Item setNext(DoublyLinkedList.Item i) {
-            DoublyLinkedList.Item old = next;
+        public final DoublyLinkedList.Item setNext(DoublyLinkedList.Item<T> i) 
{
+            DoublyLinkedList.Item<T> old = next;
             next = i;
             return old;
         }
         public final DoublyLinkedList.Item getPrev() {
             return prev;
         }
-        public final DoublyLinkedList.Item setPrev(DoublyLinkedList.Item i) {
-            DoublyLinkedList.Item old = prev;
+        public final DoublyLinkedList.Item setPrev(DoublyLinkedList.Item<T> i) 
{
+            DoublyLinkedList.Item<T> old = prev;
             prev = i;
             return old;
         }
                public DoublyLinkedList getParent() {
                        return list;
                }
-               public DoublyLinkedList setParent(DoublyLinkedList l) {
+               public DoublyLinkedList setParent(DoublyLinkedList<T> l) {
                        DoublyLinkedList old = list;
                        list = l;
                        return old;

Modified: trunk/freenet/src/freenet/support/LRUHashtable.java
===================================================================
--- trunk/freenet/src/freenet/support/LRUHashtable.java 2008-08-15 21:54:08 UTC 
(rev 21923)
+++ trunk/freenet/src/freenet/support/LRUHashtable.java 2008-08-15 22:19:38 UTC 
(rev 21924)
@@ -3,7 +3,7 @@
 import java.util.Enumeration;
 import java.util.Hashtable;
 
-public class LRUHashtable {
+public class LRUHashtable<K, V> {
 
     /*
      * I've just converted this to using the DLList and Hashtable
@@ -12,8 +12,8 @@
      * push is by far the most done operation, this should be an
      * overall improvement.
      */
-    private final DoublyLinkedListImpl list = new DoublyLinkedListImpl();
-    private final Hashtable hash = new Hashtable();
+    private final DoublyLinkedListImpl<V> list = new DoublyLinkedListImpl<V>();
+    private final Hashtable<K, QItem<K, V>> hash = new Hashtable<K, QItem<K, 
V>>();
     
     /**
      *       push()ing an object that is already in
@@ -21,10 +21,10 @@
      *       recently used position, but doesn't add
      *       a duplicate entry in the queue.
      */
-    public final synchronized void push(Object key, Object value) {
-        QItem insert = (QItem)hash.get(key);
+    public final synchronized void push(K key, V value) {
+        QItem<K,V> insert = hash.get(key);
         if (insert == null) {
-            insert = new QItem(key, value);
+            insert = new QItem<K, V>(key, value);
             hash.put(key,insert);
         } else {
                insert.value = value;
@@ -41,7 +41,7 @@
      */
     public final synchronized Object popKey() {
         if ( list.size() > 0 ) {
-            return ((QItem)hash.remove(((QItem)list.pop()).obj)).obj;
+            return (   hash.remove(((QItem) list.pop()).obj)).obj;
         } else {
             return null;
         }
@@ -52,7 +52,7 @@
      */
     public final synchronized Object popValue() {
         if ( list.size() > 0 ) {
-            return ((QItem)hash.remove(((QItem)list.pop()).obj)).value;
+            return (   hash.remove(((QItem) list.pop()).obj)).value;
         } else {
             return null;
         }
@@ -60,7 +60,7 @@
     
        public final synchronized Object peekValue() {
         if ( list.size() > 0 ) {
-            return ((QItem)hash.get(((QItem)list.tail()).obj)).value;
+            return (   hash.get(((QItem) list.tail()).obj)).value;
         } else {
             return null;
         }
@@ -70,8 +70,8 @@
         return list.size();
     }
     
-    public final synchronized boolean removeKey(Object key) {
-       QItem i = (QItem)(hash.remove(key));
+    public final synchronized boolean removeKey(K key) {
+       QItem<K,V> i = (hash.remove(key));
        if(i != null) {
            list.remove(i);
            return true;
@@ -85,7 +85,7 @@
      * @param obj Object to match
      * @return true if this queue contains obj.
      */
-    public final synchronized boolean containsKey(Object key) {
+    public final synchronized boolean containsKey(K key) {
         return hash.containsKey(key);
     }
     
@@ -93,8 +93,8 @@
      * Note that this does not automatically promote the key. You have
      * to do that by hand with push(key, value).
      */
-    public final synchronized Object get(Object key) {
-       QItem q = (QItem) hash.get(key);
+    public final synchronized V get(K key) {
+       QItem<K,V> q = hash.get(key);
        if(q == null) return null;
        return q.value;
     }
@@ -131,15 +131,16 @@
         }
     }
 
-    private static class QItem extends DoublyLinkedListImpl.Item {
-        public Object obj;
-        public Object value;
+    public static class QItem<K, V> extends DoublyLinkedListImpl.Item<V> {
+        public K obj;
+        public V value;
 
-        public QItem(Object key, Object val) {
+        public QItem(K key, V val) {
             this.obj = key;
             this.value = val;
         }
         
+               @Override
         public String toString() {
                return super.toString()+": "+obj+ ' ' +value;
         }
@@ -155,8 +156,8 @@
         * @param entries
         * @return
         */
-       public synchronized void valuesToArray(Object[] entries) {
-               Enumeration values = values();
+       public synchronized void valuesToArray(V[] entries) {
+               Enumeration<V> values = values();
                int i=0;
                while(values.hasMoreElements())
                        entries[i++] = values.nextElement();

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

Reply via email to