KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > util > queue > ChunkedQueue


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Ondrej Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 package soot.util.queue;
21
22 /** A queue of Object's. One can add objects to the queue, and they are
23  * later read by a QueueReader. One can create arbitrary numbers of
24  * QueueReader's for a queue, and each one receives all the Object's that
25  * are added. Only objects that have not been read by all the QueueReader's
26  * are kept. A QueueReader only receives the Object's added to the queue
27  * <b>after</b> the QueueReader was created.
28  * @author Ondrej Lhotak
29  */

30 public final class ChunkedQueue
31 {
32     static Object JavaDoc NULL_CONST = new Object JavaDoc();
33     private static final int LENGTH = 60;
34     private Object JavaDoc[] q;
35     private int index;
36     public ChunkedQueue() {
37         q = new Object JavaDoc[LENGTH];
38         index = 0;
39     }
40     /** Add an object to the queue. */
41     public void add( Object JavaDoc o ) {
42         if( o == null ) o = NULL_CONST;
43         if( index == LENGTH - 1 ) {
44             Object JavaDoc[] temp = new Object JavaDoc[LENGTH];
45             q[index] = temp;
46             q = temp;
47             index = 0;
48         }
49         q[index++] = o;
50     }
51     /** Create reader which will read objects from the queue. */
52     public QueueReader reader() {
53         return new QueueReader( q, index );
54     }
55 }
56
57
58
Popular Tags