Initial import to Gerrit.
[profile/ivi/festival.git] / src / modules / java / cstr / festival / client / JobQueue.java
1
2  //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
3  //                                                                        \\
4  //                 Centre for Speech Technology Research                  \\
5  //                      University of Edinburgh, UK                       \\
6  //                        Copyright (c) 1996,1997                         \\
7  //                         All Rights Reserved.                           \\
8  //   Permission is hereby granted, free of charge, to use and distribute  \\
9  //   this software and its documentation without restriction, including   \\
10  //   without limitation the rights to use, copy, modify, merge, publish,  \\
11  //   distribute, sublicense, and/or sell copies of this work, and to      \\
12  //   permit persons to whom this work is furnished to do so, subject to   \\
13  //   the following conditions:                                            \\
14  //    1. The code must retain the above copyright notice, this list of    \\
15  //       conditions and the following disclaimer.                         \\
16  //    2. Any modifications must be clearly marked as such.                \\
17  //    3. Original authors' names are not deleted.                         \\
18  //    4. The authors' names are not used to endorse or promote products   \\
19  //       derived from this software without specific prior written        \\
20  //       permission.                                                      \\
21  //   THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK        \\
22  //   DISCLAIM ALL WARRANTIES With REGARD TO THIS SOFTWARE, INCLUDING      \\
23  //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT   \\
24  //   SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE     \\
25  //   FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    \\
26  //   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   \\
27  //   AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          \\
28  //   ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       \\
29  //   THIS SOFTWARE.                                                       \\
30  //                                                                        \\
31  //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
32  //                                                                        \\
33  //                  Author: Richard Caley (rjc@cstr.ed.ac.uk)             \\
34  //  --------------------------------------------------------------------  \\
35  //  A thread safe queue based on Vector. Could be faster.                 \\
36  //                                                                        \\
37  //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\
38
39
40 package cstr.festival.client ;
41
42 import java.lang.*;
43 import java.util.*;
44 import java.awt.*;
45
46 public class JobQueue 
47 {
48   Vector q;
49
50   public JobQueue(int space)
51     {
52       q = new Vector(space);
53     }
54
55   public JobQueue()
56     {
57       q = new Vector();
58     }
59
60   public synchronized void add(Object thing)
61     {
62       q.addElement(thing);
63     }
64
65   public synchronized void remove(Object thing)
66     {
67       q.removeElement(thing);
68     }
69
70   public synchronized boolean isEmpty()
71     {
72       return q.isEmpty();
73     }
74
75   public synchronized Object top()
76     {
77      Object o;
78
79       if (q.isEmpty())
80         o = null;
81       else
82         o = q.firstElement(); 
83       return o;
84     }
85
86   public synchronized Object get()
87     {
88       Object o;
89
90       if (q.isEmpty())
91         o = null;
92       else
93         {
94           o = q.firstElement();
95           q.removeElementAt(0);
96         }
97       return o;
98     }
99
100   public synchronized Enumeration elements()
101     {
102       return q.elements();
103     }
104 }