001: /*
002: * Copyright 2001-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.collections;
017:
018: import java.util.NoSuchElementException;
019:
020: /**
021: * A thread safe version of the PriorityQueue.
022: * Provides synchronized wrapper methods for all the methods
023: * defined in the PriorityQueue interface.
024: *
025: * @deprecated PriorityQueue is replaced by the Buffer interface, see buffer subpackage.
026: * Due to be removed in v4.0.
027: * @since Commons Collections 1.0
028: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
029: *
030: * @author Ram Chidambaram
031: */
032: public final class SynchronizedPriorityQueue implements PriorityQueue {
033:
034: /**
035: * The underlying priority queue.
036: */
037: protected final PriorityQueue m_priorityQueue;
038:
039: /**
040: * Constructs a new synchronized priority queue.
041: *
042: * @param priorityQueue the priority queue to synchronize
043: */
044: public SynchronizedPriorityQueue(final PriorityQueue priorityQueue) {
045: m_priorityQueue = priorityQueue;
046: }
047:
048: /**
049: * Clear all elements from queue.
050: */
051: public synchronized void clear() {
052: m_priorityQueue.clear();
053: }
054:
055: /**
056: * Test if queue is empty.
057: *
058: * @return true if queue is empty else false.
059: */
060: public synchronized boolean isEmpty() {
061: return m_priorityQueue.isEmpty();
062: }
063:
064: /**
065: * Insert an element into queue.
066: *
067: * @param element the element to be inserted
068: */
069: public synchronized void insert(final Object element) {
070: m_priorityQueue.insert(element);
071: }
072:
073: /**
074: * Return element on top of heap but don't remove it.
075: *
076: * @return the element at top of heap
077: * @throws NoSuchElementException if isEmpty() == true
078: */
079: public synchronized Object peek() throws NoSuchElementException {
080: return m_priorityQueue.peek();
081: }
082:
083: /**
084: * Return element on top of heap and remove it.
085: *
086: * @return the element at top of heap
087: * @throws NoSuchElementException if isEmpty() == true
088: */
089: public synchronized Object pop() throws NoSuchElementException {
090: return m_priorityQueue.pop();
091: }
092:
093: /**
094: * Returns a string representation of the underlying queue.
095: *
096: * @return a string representation of the underlying queue
097: */
098: public synchronized String toString() {
099: return m_priorityQueue.toString();
100: }
101:
102: }
|