Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/flexstor/common/util/Queue.java


1   /*
2    * Queue.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:31 $ FLEXSTOR.net Inc.
5    *
6    * This work is licensed for use and distribution under license terms found at
7    * http://www.flexstor.org/license.html
8    *
9    */
10  
11  package com.flexstor.common.util;
12  
13  import java.util.Vector;
14  
15  /**
16   * Implements a simple queue.
17   * @author Dan Schroeder
18   * @version 3.0
19   */
20  public class Queue
21  {
22     private Vector queue = new Vector();
23     
24     public Queue ( )
25     {
26     }
27     
28     /**
29      * Adds an object to the end of the queue.
30      * @param o the object to place in the queue.
31      */   
32     public synchronized void push ( Object o )
33     {
34        queue.addElement ( o );
35     }
36     
37     /**
38      * Retrieves and removes an object from the start of the queue
39      * @return The first object in the queue, or null if the queue is empty.
40      * @throws ArrayIndexOutOfBoundsException If the queue is empty.
41      */
42     public synchronized Object pop ( )
43        throws ArrayIndexOutOfBoundsException
44     {
45        if ( queue.isEmpty() )
46           return null;
47        
48        Object o = queue.firstElement();
49        queue.removeElementAt ( 0 );
50        return o;
51     }
52     
53     /**
54      * Removes all items from the queue.
55      */   
56     public synchronized void clear ( )
57     {
58        queue.removeAllElements();
59     }
60     
61     /**
62      * Returns true if this queue is empty.
63      */
64     public synchronized boolean isEmpty ( )
65     {
66        return queue.isEmpty();
67     }
68  }