PageRenderTime 165ms CodeModel.GetById 20ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. import java.util.Vector;
  22. import java.util.Enumeration;
  23. import org.gjt.sp.util.Log;
  24. public class CommandQueue {
  25. public CommandQueue() {
  26. queue = new Vector();
  27. }
  28. /**
  29. * Adds a command to th beginning of the queue;
  30. */
  31. public synchronized void addFirst(Command cmd) {
  32. queue.insertElementAt(cmd, 0);
  33. insertPos++;
  34. }
  35. /**
  36. * Adds commands to the end of the queue;
  37. */
  38. public synchronized void add(Command cmd) {
  39. queue.insertElementAt(cmd, insertPos);
  40. insertPos++;
  41. }
  42. /**
  43. * Adds commands to the queue to be run after those added using {@link #add(Command)} and {@link #addFirst(Command)}.
  44. */
  45. public synchronized void addLast(Command cmd) {
  46. queue.addElement(cmd);
  47. }
  48. public int size() {
  49. return queue.size();
  50. }
  51. public synchronized void executeNext(ScriptContext context) {
  52. ((Command) queue.remove(0)).run(context);
  53. }
  54. public void executeAll(ScriptContext context) {
  55. while(queue.size() != 0) {
  56. executeNext(context);
  57. }
  58. }
  59. private int insertPos = 0;
  60. private Vector queue;
  61. }