KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > SynchronizedPriorityQueue


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.collections;
17
18 import java.util.NoSuchElementException JavaDoc;
19
20 /**
21  * A thread safe version of the PriorityQueue.
22  * Provides synchronized wrapper methods for all the methods
23  * defined in the PriorityQueue interface.
24  *
25  * @deprecated PriorityQueue is replaced by the Buffer interface, see buffer subpackage.
26  * Due to be removed in v4.0.
27  * @since Commons Collections 1.0
28  * @version $Revision: 1.13 $ $Date: 2004/02/18 01:15:42 $
29  *
30  * @author Ram Chidambaram
31  */

32 public final class SynchronizedPriorityQueue implements PriorityQueue {
33
34     /**
35      * The underlying priority queue.
36      */

37     protected final PriorityQueue m_priorityQueue;
38
39     /**
40      * Constructs a new synchronized priority queue.
41      *
42      * @param priorityQueue the priority queue to synchronize
43      */

44     public SynchronizedPriorityQueue(final PriorityQueue priorityQueue) {
45         m_priorityQueue = priorityQueue;
46     }
47
48     /**
49      * Clear all elements from queue.
50      */

51     public synchronized void clear() {
52         m_priorityQueue.clear();
53     }
54
55     /**
56      * Test if queue is empty.
57      *
58      * @return true if queue is empty else false.
59      */

60     public synchronized boolean isEmpty() {
61         return m_priorityQueue.isEmpty();
62     }
63
64     /**
65      * Insert an element into queue.
66      *
67      * @param element the element to be inserted
68      */

69     public synchronized void insert(final Object JavaDoc element) {
70         m_priorityQueue.insert(element);
71     }
72
73     /**
74      * Return element on top of heap but don't remove it.
75      *
76      * @return the element at top of heap
77      * @throws NoSuchElementException if isEmpty() == true
78      */

79     public synchronized Object JavaDoc peek() throws NoSuchElementException JavaDoc {
80         return m_priorityQueue.peek();
81     }
82
83     /**
84      * Return element on top of heap and remove it.
85      *
86      * @return the element at top of heap
87      * @throws NoSuchElementException if isEmpty() == true
88      */

89     public synchronized Object JavaDoc pop() throws NoSuchElementException JavaDoc {
90         return m_priorityQueue.pop();
91     }
92
93     /**
94      * Returns a string representation of the underlying queue.
95      *
96      * @return a string representation of the underlying queue
97      */

98     public synchronized String JavaDoc toString() {
99         return m_priorityQueue.toString();
100     }
101     
102 }
103
Popular Tags