PageRenderTime 101ms CodeModel.GetById 95ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/XInsert/src/CommandQueue.java

#
Java | 72 lines | 32 code | 11 blank | 29 comment | 1 complexity | 04cf37abbf36d6b636a4a8de1345fdf0 MD5 | raw file
 1/*
 2 *
 3 * CommandQueue.java
 4 * Copyright (C) 2001 Dominic Stolerman
 5 * dstolerman@jedit.org
 6 *
 7 * This program is free software; you can redistribute it and/or
 8 * modify it under the terms of the GNU General Public License
 9 * as published by the Free Software Foundation; either version 2
10 * of the License, or any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21
22import java.util.Vector;
23import java.util.Enumeration;
24import org.gjt.sp.util.Log;
25
26
27public class CommandQueue {
28  public CommandQueue() {
29    queue = new Vector();
30  }
31  
32  /**
33   * Adds a command to th beginning of the queue;
34   */
35  public synchronized void addFirst(Command cmd) {
36    queue.insertElementAt(cmd, 0);
37    insertPos++;
38  }
39  
40  /**
41   * Adds commands to the end of the queue;
42   */
43  public synchronized void add(Command cmd) {
44    queue.insertElementAt(cmd, insertPos);
45    insertPos++;
46  }
47  
48  /**
49   * Adds commands to the queue to be run after those added using {@link #add(Command)} and {@link #addFirst(Command)}.
50   */
51  public synchronized void addLast(Command cmd) {
52    queue.addElement(cmd);
53  }
54  
55  public int size() {
56    return queue.size();
57  }
58  
59  public synchronized void executeNext(ScriptContext context) {
60    ((Command) queue.remove(0)).run(context);
61  }
62  
63  public void executeAll(ScriptContext context) {
64    while(queue.size() != 0) {
65      executeNext(context);
66    }
67  }
68  
69  private int insertPos = 0;
70  private Vector queue;
71}
72