Skip to main content
summaryrefslogtreecommitdiffstats
blob: 14ebbc46aa682a85f2e3414ceede64bd78a07d2e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.compare.internal;

import java.util.*;

import org.eclipse.jface.operation.IRunnableWithProgress;

/**
 * A work queue maintains a list of tasks that need to be run.
 * If the same task is added multiple times, the last occurrence of
 * the task will be run(i.e. the task will be removed from it's
 * previous location and aded to the end of the queue.
 */
public class WorkQueue {
	
	private List runnables = new ArrayList();

	public boolean add(IRunnableWithProgress runnable) {
		if (runnables.contains(runnable))
			runnables.remove(runnable);
		return runnables.add(runnable);
	}

	public void clear() {
		runnables.clear();
	}

	public boolean contains(IRunnableWithProgress runnable) {
		return runnables.contains(runnable);
	}

	public boolean isEmpty() {
		return runnables.isEmpty();
	}

	public boolean remove(IRunnableWithProgress runnable) {
		return runnables.remove(runnable);
	}

	public int size() {
		return runnables.size();
	}
	public IRunnableWithProgress remove() {
		return (IRunnableWithProgress)runnables.remove(0);
	}


}

Back to the top