comparison org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/Queue.d @ 78:0a55d2d5a946

Added file for databinding
author Frank Benoit <benoit@tionex.de>
date Tue, 14 Apr 2009 11:35:29 +0200
parents
children 6be48cf9f95c
comparison
equal deleted inserted replaced
76:f05e6e8b2f2d 78:0a55d2d5a946
1 /*******************************************************************************
2 * Copyright (c) 2007, 2008 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 module org.eclipse.core.internal.databinding.Queue;
12
13 import java.lang.all;
14
15 /**
16 * Created to avoid a dependency on java.util.LinkedList, see bug 205224.
17 *
18 * @since 1.1
19 *
20 */
21 public class Queue {
22
23 static class Entry {
24 Object object;
25
26 this(Object o) {
27 this.object = o;
28 }
29
30 Entry next;
31 }
32
33 Entry first;
34 Entry last;
35
36 /**
37 * Adds the given object to the end of the queue.
38 *
39 * @param o
40 */
41 public void enqueue(Object o) {
42 Entry oldLast = last;
43 last = new Entry(o);
44 if (oldLast !is null) {
45 oldLast.next = last;
46 } else {
47 first = last;
48 }
49 }
50
51 /**
52 * Returns the first object in the queue. The queue must not be empty.
53 *
54 * @return the first object
55 */
56 public Object dequeue() {
57 Entry oldFirst = first;
58 if (oldFirst is null) {
59 throw new IllegalStateException();
60 }
61 first = oldFirst.next;
62 if (first is null) {
63 last = null;
64 }
65 oldFirst.next = null;
66 return oldFirst.object;
67 }
68
69 /**
70 * Returns <code>true</code> if the list is empty.
71 *
72 * @return <code>true</code> if the list is empty
73 */
74 public bool isEmpty() {
75 return first is null;
76 }
77 }