Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 50204 invoked from network); 1 Jan 2004 18:57:41 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 1 Jan 2004 18:57:41 -0000 Received: (qmail 11928 invoked by uid 500); 1 Jan 2004 18:57:29 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 11867 invoked by uid 500); 1 Jan 2004 18:57:29 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 11854 invoked by uid 500); 1 Jan 2004 18:57:28 -0000 Received: (qmail 11849 invoked from network); 1 Jan 2004 18:57:28 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 1 Jan 2004 18:57:28 -0000 Received: (qmail 50191 invoked by uid 1529); 1 Jan 2004 18:57:37 -0000 Date: 1 Jan 2004 18:57:37 -0000 Message-ID: <20040101185737.50190.qmail@minotaur.apache.org> From: scolebourne@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections PriorityQueueUtils.java SynchronizedPriorityQueue.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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(); /** * PriorityQueueUtils 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 Ram Chidambaram + * @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