commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections PriorityQueueUtils.java SynchronizedPriorityQueue.java
Date Thu, 01 Jan 2004 18:57:37 GMT
scolebourne    2004/01/01 10:57:37

  Modified:    collections/src/java/org/apache/commons/collections
                        PriorityQueueUtils.java
                        SynchronizedPriorityQueue.java
  Removed:     collections/src/java/org/apache/commons/collections/buffer
                        UnmodifiablePriorityQueue.java
                        SynchronizedPriorityQueue.java
  Log:
  Move PriorityQueue decorators to PriorityQueueUtils only
  (PriorityQueue interface has nothing to do with Buffer)
  
  Revision  Changes    Path
  1.5       +123 -8    jakarta-commons/collections/src/java/org/apache/commons/collections/PriorityQueueUtils.java
  
  Index: PriorityQueueUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/PriorityQueueUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PriorityQueueUtils.java	3 Dec 2003 14:39:42 -0000	1.4
  +++ PriorityQueueUtils.java	1 Jan 2004 18:57:37 -0000	1.5
  @@ -57,9 +57,7 @@
    */
   package org.apache.commons.collections;
   
  -import org.apache.commons.collections.buffer.BinaryHeap;
  -import org.apache.commons.collections.buffer.SynchronizedPriorityQueue;
  -import org.apache.commons.collections.buffer.UnmodifiablePriorityQueue;
  +import java.util.NoSuchElementException;
   
   /**
    * Provides static utility methods and decorators for {@link PriorityQueue}.
  @@ -74,7 +72,7 @@
       /**
        * An empty unmodifiable priority queue.
        */
  -    public static final PriorityQueue EMPTY_PRIORITY_QUEUE = UnmodifiablePriorityQueue.decorate(new
BinaryHeap());
  +    public static final PriorityQueue EMPTY_PRIORITY_QUEUE = new EmptyPriorityQueue();
   
       /**
        * <code>PriorityQueueUtils</code> should not normally be instantiated.
  @@ -91,7 +89,7 @@
        * @throws IllegalArgumentException  if the priority queue is null
        */
       public static PriorityQueue synchronizedPriorityQueue(PriorityQueue priorityQueue)
{
  -        return SynchronizedPriorityQueue.decorate(priorityQueue);
  +        return new SynchronizedPriorityQueue(priorityQueue);
       }
   
       /**
  @@ -102,7 +100,124 @@
        * @throws IllegalArgumentException  if the priority queue is null
        */
       public static PriorityQueue unmodifiablePriorityQueue(PriorityQueue priorityQueue)
{
  -        return UnmodifiablePriorityQueue.decorate(priorityQueue);
  +        return new UnmodifiablePriorityQueue(priorityQueue);
       }
   
  +    //-----------------------------------------------------------------------
  +    /**
  +     * Decorator for PriorityQueue that adds synchronization.
  +     */
  +    static class SynchronizedPriorityQueue implements PriorityQueue {
  +
  +        /** The priority queue to decorate */
  +        protected final PriorityQueue priorityQueue;
  +
  +        protected SynchronizedPriorityQueue(PriorityQueue priorityQueue) {
  +            if (priorityQueue == null) {
  +                throw new IllegalArgumentException("PriorityQueue must not be null");
  +            }
  +            this.priorityQueue = priorityQueue;
  +        }
  +
  +        public synchronized boolean isEmpty() {
  +            return priorityQueue.isEmpty();
  +        }
  +
  +        public synchronized Object peek() {
  +            return priorityQueue.peek();
  +        }
  +
  +        public synchronized Object pop() {
  +            return priorityQueue.pop();
  +        }
  +
  +        public synchronized void insert(Object obj) {
  +            priorityQueue.insert(obj);
  +        }
  +
  +        public synchronized void clear() {
  +            priorityQueue.clear();
  +        }
  +
  +        public synchronized String toString() {
  +            return priorityQueue.toString();
  +        }
  +    }
  +    
  +    //-----------------------------------------------------------------------
  +    /**
  +     * Decorator for PriorityQueue that prevents changes.
  +     */
  +    static class UnmodifiablePriorityQueue implements PriorityQueue, Unmodifiable {
  +
  +        /** The priority queue to decorate */
  +        protected final PriorityQueue priorityQueue;
  +
  +        protected UnmodifiablePriorityQueue(PriorityQueue priorityQueue) {
  +            if (priorityQueue == null) {
  +                throw new IllegalArgumentException("PriorityQueue must not be null");
  +            }
  +            this.priorityQueue = priorityQueue;
  +        }
  +
  +        public synchronized boolean isEmpty() {
  +            return priorityQueue.isEmpty();
  +        }
  +
  +        public synchronized Object peek() {
  +            return priorityQueue.peek();
  +        }
  +
  +        public synchronized Object pop() {
  +            throw new UnsupportedOperationException();
  +        }
  +
  +        public synchronized void insert(Object obj) {
  +            throw new UnsupportedOperationException();
  +        }
  +
  +        public synchronized void clear() {
  +            throw new UnsupportedOperationException();
  +        }
  +
  +        public synchronized String toString() {
  +            return priorityQueue.toString();
  +        }
  +    
  +    }
  +    
  +    //-----------------------------------------------------------------------
  +    /**
  +     * PriorityQueue that is empty.
  +     */
  +    static class EmptyPriorityQueue implements PriorityQueue, Unmodifiable {
  +
  +        protected EmptyPriorityQueue() {
  +        }
  +
  +        public synchronized boolean isEmpty() {
  +            return true;
  +        }
  +
  +        public synchronized Object peek() {
  +            throw new NoSuchElementException();
  +        }
  +
  +        public synchronized Object pop() {
  +            throw new UnsupportedOperationException();
  +        }
  +
  +        public synchronized void insert(Object obj) {
  +            throw new UnsupportedOperationException();
  +        }
  +
  +        public synchronized void clear() {
  +            throw new UnsupportedOperationException();
  +        }
  +
  +        public synchronized String toString() {
  +            return "[]";
  +        }
  +    
  +    }
   }
  
  
  
  1.10      +4 -4      jakarta-commons/collections/src/java/org/apache/commons/collections/SynchronizedPriorityQueue.java
  
  Index: SynchronizedPriorityQueue.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/SynchronizedPriorityQueue.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SynchronizedPriorityQueue.java	29 Nov 2003 17:26:21 -0000	1.9
  +++ SynchronizedPriorityQueue.java	1 Jan 2004 18:57:37 -0000	1.10
  @@ -64,11 +64,11 @@
    * Provides synchronized wrapper methods for all the methods 
    * defined in the PriorityQueue interface.
    *
  - * @deprecated Moved to buffer subpackage. Due to be removed in v4.0.
  + * @deprecated Use PriorityQueueUtils. Due to be removed in v4.0.
    * @since Commons Collections 1.0
    * @version $Revision$ $Date$
    * 
  - * @author  <a href="mailto:ram.chidambaram@telus.com">Ram Chidambaram</a>

  + * @author Ram Chidambaram
    */
   public final class SynchronizedPriorityQueue implements PriorityQueue {
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message