[jboss-cvs] JBoss Messaging SVN: r4309 - in trunk: src/main/org/jboss/messaging/core/list/impl and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue May 27 13:39:02 EDT 2008


Author: timfox
Date: 2008-05-27 13:39:02 -0400 (Tue, 27 May 2008)
New Revision: 4309

Added:
   trunk/src/main/org/jboss/messaging/core/list/PriorityHeadInsertableQueue.java
   trunk/src/main/org/jboss/messaging/core/list/impl/PriorityHeadInsertableQueueImpl.java
   trunk/src/main/org/jboss/messaging/util/HeadInsertableConcurrentQueue.java
   trunk/src/main/org/jboss/messaging/util/HeadInsertableQueue.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/list/impl/PriorityHeadInsertableQueueTest.java
Log:
 A few files that may come in useful later


Added: trunk/src/main/org/jboss/messaging/core/list/PriorityHeadInsertableQueue.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/list/PriorityHeadInsertableQueue.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/list/PriorityHeadInsertableQueue.java	2008-05-27 17:39:02 UTC (rev 4309)
@@ -0,0 +1,56 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+
+package org.jboss.messaging.core.list;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * A type of linked queue which maintains items according to a priority
+ * and allows adding and removing of elements at both ends, and peeking
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com>Tim Fox</a>
+ * @version <tt>$Revision: 1174 $</tt>
+ *
+ * $Id: PrioritizedDeque.java 1174 2006-08-02 14:14:32Z timfox $
+ */
+public interface PriorityHeadInsertableQueue<T>
+{
+   void offerFirst(T t, int priority);
+   
+   void offerLast(T t, int priority);
+   
+   T poll();
+   
+   T peek();
+   
+   List<T> getAll();
+   
+   void clear();   
+   
+   int size();
+   
+   Iterator<T> iterator();
+   
+   boolean isEmpty();
+}

Added: trunk/src/main/org/jboss/messaging/core/list/impl/PriorityHeadInsertableQueueImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/list/impl/PriorityHeadInsertableQueueImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/list/impl/PriorityHeadInsertableQueueImpl.java	2008-05-27 17:39:02 UTC (rev 4309)
@@ -0,0 +1,251 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.messaging.core.list.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.jboss.messaging.core.list.PriorityHeadInsertableQueue;
+import org.jboss.messaging.util.HeadInsertableQueue;
+import org.jboss.messaging.util.HeadInsertableConcurrentQueue;
+
+/**
+ *
+ * @author <a href="mailto:tim.fox at jboss.com>Tim Fox</a>
+ * @version <tt>$Revision: 1174 $</tt>
+ *
+ * $Id: BasicPrioritizedDeque.java 1174 2006-08-02 14:14:32Z timfox $
+ */
+public class PriorityHeadInsertableQueueImpl<T> implements PriorityHeadInsertableQueue<T>
+{      	
+   private final HeadInsertableQueue[] queues;
+   
+   private final int priorities;
+   
+   private AtomicInteger size = new AtomicInteger();
+   
+   public PriorityHeadInsertableQueueImpl(final int priorities)
+   {
+      this.priorities = priorities;
+       
+      queues = new HeadInsertableConcurrentQueue[priorities];
+      
+      for (int i = 0; i < priorities; i++)
+      {
+         queues[i] = new HeadInsertableConcurrentQueue<T>();
+      }
+   }
+   
+   public void offerFirst(final T t, final int priority)
+   {      
+      queues[priority].offerFirst(t);
+      
+      size.incrementAndGet();
+   }
+   
+   public void offerLast(final T t, final int priority)
+   { 
+      queues[priority].offerLast(t);
+      
+      size.incrementAndGet();
+   }
+
+   public T poll()
+   {         
+      //Initially we are just using a simple prioritization algorithm:
+      //Highest priority refs always get returned first.
+      //This could cause starvation of lower priority refs.
+      
+      //TODO - A better prioritization algorithm
+      
+      for (int i = priorities - 1; i >= 0; i--)
+      {
+         HeadInsertableQueue<T> ll = queues[i];
+         
+         if (ll.size() == 0)
+         {
+            continue;
+         }
+         
+         T t = ll.poll();
+         
+         if (t != null)
+         {
+            size.decrementAndGet();
+            
+            return t;
+         }                          
+      }
+      
+      return null;    
+   }
+   
+   public T peek()
+   {
+      for (int i = priorities - 1; i >= 0; i--)
+      {
+         HeadInsertableQueue<T> ll = queues[i];
+         
+         if (ll.size() == 0)
+         {
+            continue;
+         }
+         
+         T t = ll.peek();
+         
+         if (t != null)
+         {
+            return t;
+         }
+      }
+      
+      return null;     
+   }
+   
+   public List<T> getAll()
+   {
+      List<T> all = new ArrayList<T>();
+      
+      for (int i = priorities - 1; i >= 0; i--)
+      {
+         HeadInsertableQueue<T> list = queues[i];
+         
+         //TODO improve performance
+         for (T t: list)
+         {
+            all.add(t);
+         }
+      }
+      
+      return all;
+   }
+   
+   public void clear()
+   {
+   	for (HeadInsertableQueue<T> list: queues)
+      {
+         list.clear();
+      }
+   	
+   	size.set(0);
+   }
+   
+   public int size()
+   {
+      return size.get();
+   }
+   
+   public boolean isEmpty()
+   {
+      return size.get() == 0;
+   }
+
+   public Iterator<T> iterator()
+   {
+      return new PriorityHeadInsertableQueueImplIterator();
+   }
+      
+   private class PriorityHeadInsertableQueueImplIterator implements ListIterator<T>
+   { 
+      private int index;
+      
+      private Iterator<T> currentIter;
+      
+      PriorityHeadInsertableQueueImplIterator()
+      {
+         index = queues.length - 1;
+         
+         currentIter = queues[index].iterator();
+      }
+
+      public void add(final Object obj)
+      {
+         throw new UnsupportedOperationException();
+      }
+
+      public boolean hasNext()
+      {
+         if (currentIter.hasNext())
+         {
+            return true;
+         }
+         
+         while (index >= 0)
+         {                 
+            if (index == 0 || currentIter.hasNext())
+            {
+               break;
+            }                 
+            
+            index--;
+            
+            currentIter = queues[index].iterator();
+         }
+         return currentIter.hasNext();      
+      }
+      
+      public boolean hasPrevious()
+      {
+         throw new UnsupportedOperationException();
+      }
+
+      public T next()
+      {
+         if (!hasNext())
+         {
+            throw new NoSuchElementException();
+         }
+         return currentIter.next();
+      }
+
+      public int nextIndex()
+      {
+         throw new UnsupportedOperationException();
+      }
+
+      public T previous()
+      {
+         throw new UnsupportedOperationException();
+      }
+
+      public int previousIndex()
+      {
+         throw new UnsupportedOperationException();
+      }
+
+      public void remove()
+      {
+         currentIter.remove();      
+         
+         size.decrementAndGet();
+      }
+
+      public void set(final Object obj)
+      {
+         throw new UnsupportedOperationException();
+      }
+   }   
+}

Added: trunk/src/main/org/jboss/messaging/util/HeadInsertableConcurrentQueue.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/HeadInsertableConcurrentQueue.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/util/HeadInsertableConcurrentQueue.java	2008-05-27 17:39:02 UTC (rev 4309)
@@ -0,0 +1,65 @@
+package org.jboss.messaging.util;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * 
+ * A HeadInsertableConcurrentQueue
+ * 
+ * TODO - considering using ConcurrentLinkedDeque?
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class HeadInsertableConcurrentQueue<T> implements HeadInsertableQueue<T>
+{
+   private LinkedList headList = new LinkedList();
+
+   private ConcurrentLinkedQueue<T> queue = new ConcurrentLinkedQueue<T>();
+   
+   private AtomicInteger size = new AtomicInteger(0);
+      
+   public void clear()
+   {
+      queue.clear();
+   }
+
+   public Iterator<T> iterator()
+   {
+      return queue.iterator();
+   }
+
+   public void offerFirst(T object)
+   {
+      throw new UnsupportedOperationException();
+      
+      //size.incrementAndGet();
+   }
+
+   public void offerLast(T object)
+   {
+      queue.offer(object);
+      
+      size.incrementAndGet();
+   }
+
+   public T peek()
+   {
+      return queue.peek();
+   }
+
+   public T poll()
+   {
+      size.decrementAndGet();
+      
+      return queue.poll();
+   }
+   
+   public int size()
+   {
+      return size.get();
+   }
+}

Added: trunk/src/main/org/jboss/messaging/util/HeadInsertableQueue.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/HeadInsertableQueue.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/util/HeadInsertableQueue.java	2008-05-27 17:39:02 UTC (rev 4309)
@@ -0,0 +1,29 @@
+package org.jboss.messaging.util;
+
+import java.util.Iterator;
+
+
+/**
+ * 
+ * Extends a Queue with a method to insert an element at the head of the queue 
+ * 
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ * @param <T>
+ */
+public interface HeadInsertableQueue<T> extends Iterable<T>
+{
+   void offerFirst(T object);
+   
+   void offerLast(T object);
+   
+   T poll();
+   
+   T peek();
+   
+   void clear();
+   
+   Iterator<T> iterator();      
+   
+   int size();
+}

Added: trunk/tests/src/org/jboss/messaging/tests/unit/core/list/impl/PriorityHeadInsertableQueueTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/list/impl/PriorityHeadInsertableQueueTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/list/impl/PriorityHeadInsertableQueueTest.java	2008-05-27 17:39:02 UTC (rev 4309)
@@ -0,0 +1,619 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.messaging.tests.unit.core.list.impl;
+
+import java.util.Iterator;
+
+import org.jboss.messaging.core.list.PriorityHeadInsertableQueue;
+import org.jboss.messaging.core.list.impl.PriorityHeadInsertableQueueImpl;
+import org.jboss.messaging.tests.util.UnitTestCase;
+
+/**
+ * @author <a href="tim.fox at jboss.com>Tim Fox</a>
+ *
+ * $Id: PriorityHeadInsertableQueueTest.java 4055 2008-04-15 09:24:10Z ataylor $
+ */
+public class PriorityHeadInsertableQueueTest extends UnitTestCase
+{
+   protected PriorityHeadInsertableQueue<Wibble> queue;
+   
+   protected Wibble a;
+   protected Wibble b;
+   protected Wibble c;
+   protected Wibble d;
+   protected Wibble e;   
+   protected Wibble f;
+   protected Wibble g;
+   protected Wibble h;
+   protected Wibble i;
+   protected Wibble j;
+   protected Wibble k;
+   protected Wibble l;
+   protected Wibble m;
+   protected Wibble n;
+   protected Wibble o;   
+   protected Wibble p;
+   protected Wibble q;
+   protected Wibble r;
+   protected Wibble s;
+   protected Wibble t;
+   protected Wibble u;
+   protected Wibble v;
+   protected Wibble w;
+   protected Wibble x;
+   protected Wibble y;   
+   protected Wibble z;
+   
+   public void setUp() throws Exception
+   {
+      super.setUp();
+      
+      queue = new PriorityHeadInsertableQueueImpl<Wibble>(10);
+      
+      a = new Wibble("a");
+      b = new Wibble("b");
+      c = new Wibble("c");
+      d = new Wibble("d");
+      e = new Wibble("e");
+      f = new Wibble("f");
+      g = new Wibble("g");
+      h = new Wibble("h");
+      i = new Wibble("i");
+      j = new Wibble("j");
+      k = new Wibble("k");
+      l = new Wibble("l");
+      m = new Wibble("m");
+      n = new Wibble("n");
+      o = new Wibble("o");
+      p = new Wibble("p");
+      q = new Wibble("q");
+      r = new Wibble("r");
+      s = new Wibble("s");
+      t = new Wibble("t");
+      u = new Wibble("u");
+      v = new Wibble("v");
+      w = new Wibble("w");
+      x = new Wibble("x");
+      y = new Wibble("y");
+      z = new Wibble("z");
+   }
+   
+   
+   public void tearDown() throws Exception
+   {
+      super.tearDown();
+   }
+         
+   public void testofferFirst() throws Exception
+   {
+      //for now will throw UnsupportedOperationException
+      
+      try
+      {
+         queue.offerFirst(a, 0);
+         
+         fail("Should throw exception");
+      }
+      catch (UnsupportedOperationException e)
+      {
+         //Ok
+      }
+      
+//      queue.offerFirst(a, 0);
+//      queue.offerFirst(b, 0);
+//      queue.offerFirst(c, 0);
+//      queue.offerFirst(d, 0);
+//      queue.offerFirst(e, 0);
+//
+//
+//      assertEquals(e, queue.poll());
+//      assertEquals(d, queue.poll());
+//      assertEquals(c, queue.poll());
+//      assertEquals(b, queue.poll());
+//      assertEquals(a, queue.poll());
+//      assertNull(queue.poll());
+   }
+   
+   public void testofferLast() throws Exception
+   {
+      queue.offerLast(a, 0);
+      queue.offerLast(b, 0);
+      queue.offerLast(c, 0);
+      queue.offerLast(d, 0);
+      queue.offerLast(e, 0);
+      
+      assertEquals(a, queue.poll());
+      assertEquals(b, queue.poll());
+      assertEquals(c, queue.poll());
+      assertEquals(d, queue.poll());
+      assertEquals(e, queue.poll());
+      assertNull(queue.poll());
+
+   }
+   
+   
+   public void testpoll() throws Exception
+   {
+      queue.offerLast(a, 0);
+      queue.offerLast(b, 1);
+      queue.offerLast(c, 2);
+      queue.offerLast(d, 3);
+      queue.offerLast(e, 4);
+      queue.offerLast(f, 5);
+      queue.offerLast(g, 6);
+      queue.offerLast(h, 7);
+      queue.offerLast(i, 8);
+      queue.offerLast(j, 9);
+      
+      assertEquals(j, queue.poll());
+      assertEquals(i, queue.poll());
+      assertEquals(h, queue.poll());
+      assertEquals(g, queue.poll());
+      assertEquals(f, queue.poll());
+      assertEquals(e, queue.poll());
+      assertEquals(d, queue.poll());
+      assertEquals(c, queue.poll());
+      assertEquals(b, queue.poll());
+      assertEquals(a, queue.poll());
+    
+      assertNull(queue.poll());
+      
+      queue.offerLast(a, 9);
+      queue.offerLast(b, 8);
+      queue.offerLast(c, 7);
+      queue.offerLast(d, 6);
+      queue.offerLast(e, 5);
+      queue.offerLast(f, 4);
+      queue.offerLast(g, 3);
+      queue.offerLast(h, 2);
+      queue.offerLast(i, 1);
+      queue.offerLast(j, 0);
+      
+      assertEquals(a, queue.poll());
+      assertEquals(b, queue.poll());
+      assertEquals(c, queue.poll());
+      assertEquals(d, queue.poll());
+      assertEquals(e, queue.poll());
+      assertEquals(f, queue.poll());
+      assertEquals(g, queue.poll());
+      assertEquals(h, queue.poll());
+      assertEquals(i, queue.poll());
+      assertEquals(j, queue.poll());
+    
+      assertNull(queue.poll());
+      
+      queue.offerLast(a, 9);
+      queue.offerLast(b, 0);
+      queue.offerLast(c, 8);
+      queue.offerLast(d, 1);
+      queue.offerLast(e, 7);
+      queue.offerLast(f, 2);
+      queue.offerLast(g, 6);
+      queue.offerLast(h, 3);
+      queue.offerLast(i, 5);
+      queue.offerLast(j, 4);
+      
+      assertEquals(a, queue.poll());
+      assertEquals(c, queue.poll());
+      assertEquals(e, queue.poll());
+      assertEquals(g, queue.poll());
+      assertEquals(i, queue.poll());
+      assertEquals(j, queue.poll());
+      assertEquals(h, queue.poll());
+      assertEquals(f, queue.poll());
+      assertEquals(d, queue.poll());
+      assertEquals(b, queue.poll());
+      
+      assertNull(queue.poll());
+      
+      queue.offerLast(a, 0);
+      queue.offerLast(b, 3);
+      queue.offerLast(c, 3);
+      queue.offerLast(d, 3);
+      queue.offerLast(e, 6);
+      queue.offerLast(f, 6);
+      queue.offerLast(g, 6);
+      queue.offerLast(h, 9);
+      queue.offerLast(i, 9);
+      queue.offerLast(j, 9);
+      
+      assertEquals(h, queue.poll());
+      assertEquals(i, queue.poll());
+      assertEquals(j, queue.poll());
+      assertEquals(e, queue.poll());
+      assertEquals(f, queue.poll());
+      assertEquals(g, queue.poll());
+      assertEquals(b, queue.poll());
+      assertEquals(c, queue.poll());
+      assertEquals(d, queue.poll());
+      assertEquals(a, queue.poll());
+      
+      assertNull(queue.poll());
+      
+      queue.offerLast(a, 5);
+      queue.offerLast(b, 5);
+      queue.offerLast(c, 5);
+      queue.offerLast(d, 5);
+      queue.offerLast(e, 5);
+      queue.offerLast(f, 5);
+      queue.offerLast(g, 5);
+      queue.offerLast(h, 5);
+      queue.offerLast(i, 5);
+      queue.offerLast(j, 5);
+      
+      assertEquals(a, queue.poll());
+      assertEquals(b, queue.poll());
+      assertEquals(c, queue.poll());
+      assertEquals(d, queue.poll());
+      assertEquals(e, queue.poll());
+      assertEquals(f, queue.poll());
+      assertEquals(g, queue.poll());
+      assertEquals(h, queue.poll());
+      assertEquals(i, queue.poll());
+      assertEquals(j, queue.poll());
+      
+      assertNull(queue.poll());
+      
+      queue.offerLast(j, 5);
+      queue.offerLast(i, 5);
+      queue.offerLast(h, 5);
+      queue.offerLast(g, 5);
+      queue.offerLast(f, 5);
+      queue.offerLast(e, 5);
+      queue.offerLast(d, 5);
+      queue.offerLast(c, 5);
+      queue.offerLast(b, 5);
+      queue.offerLast(a, 5);
+      
+      assertEquals(j, queue.poll());
+      assertEquals(i, queue.poll());
+      assertEquals(h, queue.poll());
+      assertEquals(g, queue.poll());
+      assertEquals(f, queue.poll());
+      assertEquals(e, queue.poll());
+      assertEquals(d, queue.poll());
+      assertEquals(c, queue.poll());
+      assertEquals(b, queue.poll());
+      assertEquals(a, queue.poll());
+      
+      assertNull(queue.poll());
+      
+   }
+   
+   public void testGetAll() throws Exception
+   {
+      queue.offerLast(a, 0);
+      queue.offerLast(b, 3);
+      queue.offerLast(c, 3);
+      queue.offerLast(d, 3);
+      queue.offerLast(e, 6);
+      queue.offerLast(f, 6);
+      queue.offerLast(g, 6);
+      queue.offerLast(h, 9);
+      queue.offerLast(i, 9);
+      queue.offerLast(j, 9);
+      
+      
+      Iterator iter = queue.getAll().iterator();
+      int count = 0;
+      while (iter.hasNext())
+      {
+         Object o = iter.next();
+         if (count == 0)
+         {
+            assertEquals(h, o);
+         }
+         if (count == 1)
+         {
+            assertEquals(i, o);
+         }
+         if (count == 2)
+         {
+            assertEquals(j, o);
+         }
+         if (count == 3)
+         {
+            assertEquals(e, o);
+         }
+         if (count == 4)
+         {
+            assertEquals(f, o);
+         }
+         if (count == 5)
+         {
+            assertEquals(g, o);
+         }
+         if (count == 6)
+         {
+            assertEquals(b, o);
+         }
+         if (count == 7)
+         {
+            assertEquals(c, o);
+         }
+         if (count == 8)
+         {
+            assertEquals(d, o);
+         }
+         if (count == 9)
+         {
+            assertEquals(a, o);
+         }
+         count++;
+      }
+      assertEquals(10, count);
+   }
+   
+   public void testIterator()
+   {
+      queue.offerLast(a, 9);
+      queue.offerLast(b, 9);
+      queue.offerLast(c, 8);
+      queue.offerLast(d, 8);
+      queue.offerLast(e, 7);
+      queue.offerLast(f, 7);
+      queue.offerLast(g, 7);
+      queue.offerLast(h, 6);
+      queue.offerLast(i, 6);
+      queue.offerLast(j, 6);
+      queue.offerLast(k, 5);
+      queue.offerLast(l, 5);
+      queue.offerLast(m, 4);
+      queue.offerLast(n, 4);
+      queue.offerLast(o, 4);
+      queue.offerLast(p, 3);
+      queue.offerLast(q, 3);
+      queue.offerLast(r, 3);
+      queue.offerLast(s, 2);
+      queue.offerLast(t, 2);
+      queue.offerLast(u, 2);
+      queue.offerLast(v, 1);
+      queue.offerLast(w, 1);
+      queue.offerLast(x, 1);
+      queue.offerLast(y, 0);
+      queue.offerLast(z, 0);
+      
+      Iterator<Wibble> iter = queue.iterator();
+      
+      int c = 0;
+      while (iter.hasNext())
+      {
+         iter.next();
+         c++;
+      }      
+      assertEquals(c, 26);
+      assertEquals(26, queue.size());
+      
+      iter = queue.iterator();
+      assertTrue(iter.hasNext());
+      Wibble w = (Wibble)iter.next();
+      assertEquals("a", w.s);      
+      w = (Wibble)iter.next();
+      assertEquals("b", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("c", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("d", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("e", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("f", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("g", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("h", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("i", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("j", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("k", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("l", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("m", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("n", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("o", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("p", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("q", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("r", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("s", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("t", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("u", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("v", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("w", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("x", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("y", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("z", w.s);
+      assertFalse(iter.hasNext());
+      
+      iter = queue.iterator();
+      assertTrue(iter.hasNext());
+      w = (Wibble)iter.next();
+      assertEquals("a", w.s);   
+      
+      iter.remove();
+      
+      assertEquals(25, queue.size());
+      
+      w = (Wibble)iter.next();
+      assertEquals("b", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("c", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("d", w.s);
+      
+      iter.remove();
+      
+      assertEquals(24, queue.size());
+      
+      w = (Wibble)iter.next();
+      assertEquals("e", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("f", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("g", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("h", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("i", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("j", w.s);
+      
+      iter.remove();
+      
+      assertEquals(23, queue.size());
+      
+      w = (Wibble)iter.next();
+      assertEquals("k", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("l", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("m", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("n", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("o", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("p", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("q", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("r", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("s", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("t", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("u", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("v", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("w", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("x", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("y", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("z", w.s);
+      iter.remove();
+      assertFalse(iter.hasNext());
+      
+      iter = queue.iterator();
+      assertTrue(iter.hasNext());
+      w = (Wibble)iter.next();
+      assertEquals("b", w.s);   
+      w = (Wibble)iter.next();
+      assertEquals("c", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("e", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("f", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("g", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("h", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("i", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("k", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("l", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("m", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("n", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("o", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("p", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("q", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("r", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("s", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("t", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("u", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("v", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("w", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("x", w.s);
+      w = (Wibble)iter.next();
+      assertEquals("y", w.s);     
+      assertFalse(iter.hasNext());
+      
+   }
+      
+     
+   public void testClear()
+   {
+      queue.offerLast(a, 0);
+      queue.offerLast(b, 3);
+      queue.offerLast(c, 3);
+      queue.offerLast(d, 3);
+      queue.offerLast(e, 6);
+      queue.offerLast(f, 6);
+      queue.offerLast(g, 6);
+      queue.offerLast(h, 9);
+      queue.offerLast(i, 9);
+      queue.offerLast(j, 9);
+      
+      queue.clear();
+      
+      assertNull(queue.poll());
+      
+      assertTrue(queue.getAll().isEmpty());
+   }
+   
+   class Wibble
+   {
+      String s;
+      Wibble(String s)
+      {
+         this.s = s;
+      }
+      public String toString()
+      {
+         return s;
+      }
+   }
+   
+}
+




More information about the jboss-cvs-commits mailing list