KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > compare > internal > WorkQueue


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.compare.internal;
12
13 import java.util.*;
14
15 import org.eclipse.jface.operation.IRunnableWithProgress;
16
17 /**
18  * A work queue maintains a list of tasks that need to be run.
19  * If the same task is added multiple times, the last occurrence of
20  * the task will be run(i.e. the task will be removed from it's
21  * previous location and aded to the end of the queue.
22  */

23 public class WorkQueue {
24     
25     private List runnables = new ArrayList();
26
27     public boolean add(IRunnableWithProgress runnable) {
28         if (runnables.contains(runnable))
29             runnables.remove(runnable);
30         return runnables.add(runnable);
31     }
32
33     public void clear() {
34         runnables.clear();
35     }
36
37     public boolean contains(IRunnableWithProgress runnable) {
38         return runnables.contains(runnable);
39     }
40
41     public boolean isEmpty() {
42         return runnables.isEmpty();
43     }
44
45     public boolean remove(IRunnableWithProgress runnable) {
46         return runnables.remove(runnable);
47     }
48
49     public int size() {
50         return runnables.size();
51     }
52     public IRunnableWithProgress remove() {
53         return (IRunnableWithProgress)runnables.remove(0);
54     }
55
56
57 }
58
Popular Tags